1

I've created a simple project to get myself accustomed to meson, but the build keeps failing.

This is what I did (to set up the environment, and to build):

set CC=clang
set CC_LD=lld
set CFLAGS="--target x86_64-pc-windows-msvc"
meson build
cd build
ninja

My meson.build is as follows:

project('EtaClient', 'c')
src = ['src/main.c', 'src/linkedlist.c']
executable('EtaClient', src)
target = 'x86_64-pc-windows-msvc'

While building, I get the following errors (the obj files are built successfully, but they're not linked and thus the exe isn't built):

LINK : warning LNK4044: unrecognized option '/-subsystem'; ignored
LINK : fatal error LNK1181: cannot open input file 'console.obj'
clang: error: linker command failed with exit code 1181 (use -v to see invocation)

When I look in my build.ninja to see what's going on, I find:

build EtaClient.exe | EtaClient.pdb: c_LINKER EtaClient.exe.p/src_main.c.obj EtaClient.exe.p/src_linkedlist.c.obj
LINK_ARGS = "-Wl,/nologo" "-Wl,/release" "-Wl,/nologo" "-Wl,/DEBUG" "-Wl,/PDB:EtaClient.pdb" "-Wl,--subsystem,console" "-lkernel32" "-luser32" "-lgdi32" "-lwinspool" "-lshell32" "-lole32" "-loleaut32" "-luuid" "-lcomdlg32" "-ladvapi32"

I replace "-Wl,--subsystem,console" with "-Wl,/subsystem:console", and the build compiles successfully, but I have to manually make this edit each time I modify my meson.build.

Could someone tell me why this happens, and how to set up meson to generate the correct flag? Thanks in advance.

TheMadHau5
  • 97
  • 1
  • 13

1 Answers1

1

use clang-cl instead of clang and leave out the defintion of the linker when you are on windows

set CC=clang-cl
set CFLAGS="--target x86_64-pc-windows-msvc"
meson build
cd build
ninja

see https://github.com/mesonbuild/meson/issues/4232

  • I'll try it out, and if it works, I'll mark this answer as accepted :) – TheMadHau5 Nov 22 '20 at 04:17
  • Just tested it, now the flag is output correctly but the linker (it automatically selected `lld-link`) is unable to find the windows `.lib` files (`kernel32.lib`, `user32.lib`, `shell32.lib`, etc.), any ideas? – TheMadHau5 Nov 22 '20 at 04:24
  • @TheMadHau5, this is a limitation of clang under windows see https://stackoverflow.com/a/58905323/14683662 – TheBlackRiderGBird Nov 22 '20 at 19:25
  • Thing is, I already do have MSVC installed (with Visual Studio 2019). I also have MSYS2 installed so I'll take a look using that then. – TheMadHau5 Nov 22 '20 at 21:01
  • Note: clang works fine with the MSVC libs when running with the environment I gave in the question, but the build.ninja file generated by meson has one incorrect flag. Using the clang-cl environment suggested by you however, this is not the case, and the libraries can not be found. It's around 3 am here, so I'll be checking the MSYS solution in the morning. Thanks for helping me as much as you did :) – TheMadHau5 Nov 22 '20 at 21:17
  • Update: I tried the MinGW toolchain and it works! (`lld` doesn't but I'll stick with the default one in that case). Now it's actually 3 am, so I'm going to go to sleep. Again, thank you for your help. – TheMadHau5 Nov 22 '20 at 21:28