meguli
meguli

Reputation: 1526

Building Win32 C++ GUI programs using clang-cl

I am trying to use LLVM's clang-cl, giving its MSVC compatibility skills a go. I am in Visual Studio and I use CMake for this.

I used file below from LLVM project to configure my CMake settings, needed some modifications because my VSCode setup defaults to using cmd.exe and that handles paths differently.

https://github.com/llvm/llvm-project/blob/main/llvm/cmake/platforms/WinMsvc.cmake

Now I can compile any pure-C++ project that uses STL etc. That works fine.

Second, I wanted to try building a Win32 program, using windows.h. For this, I took the sample program given by Microsoft:

https://learn.microsoft.com/en-us/windows/win32/learnwin32/your-first-windows-program?source=recommendations

When I build, lld-link.exe gives me tons of undefined reference to ... errors. Here is the command eventually executed by my CMake:

C:\dev\LLVM\bin\lld-link.exe /nologo CMakeFiles\cpp-playground.dir\main.cpp.obj /out:cpp-playground.exe /implib:cpp-playground.lib /pdb:cpp-playground.pdb /version:0.0 /manifest:no -libpath:"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\atlmfc\lib\x64" -libpath:"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\lib\x64" -libpath:"C:\Program Files\Microsoft Visual Studio\2022\Community\Windows Kits\10\Lib\10.0.22000.0\ucrt\x64" -libpath:"C:\Program Files\Microsoft Visual Studio\2022\Community\Windows Kits\10\Lib\10.0.22000.0\um\x64" /machine:x64 /debug /INCREMENTAL /subsystem:windows

It looks to me like it is finding and passing all the required libpath just fine. Still I get errors like following:

[build] lld-link: error: undefined symbol: __declspec(dllimport) RegisterClassW
[build] >>> referenced by C:\dev\work\cpp-playground\main.cpp:19
[build] >>>               CMakeFiles\cpp-playground.dir\main.cpp.obj:(wWinMain)
[build] 
[build] lld-link: error: undefined symbol: __declspec(dllimport) CreateWindowExW
[build] >>> referenced by C:\dev\work\cpp-playground\main.cpp:23
[build] >>>               CMakeFiles\cpp-playground.dir\main.cpp.obj:(wWinMain)
[build] 
...

Basically, same error for all the Win32 functions from Windows.h mentioned in that sample program. My question is, why it is not linking these correctly?

Upvotes: 0

Views: 22

Answers (0)

Related Questions