我一直在尝试在我的 Windows 10 机器上设置 LLVM 工具链。我放弃了从源代码构建并安装了 MSYS2 mingw-w64-clang-x86_64-toolchain 包(clang 版本 13.0.0)。
我可以编译使用 C++ 标准库的简单代码。我使用 clang 编译,lld 链接,我应该使用 libc++。
为了测试链接一个额外的库,我使用 glfw:
#include <iostream>
#include <vector>
#include "glfw3.h"
int main(int argc, char **argv) {
glfwInit();
std::vector<int> testVector = {4, 5, 6, 7, 2};
testVector.push_back(23);
std::cout << testVector[1] << std::endl;
return 0;
}
如果我注释掉 glfwInit(); 这将编译并运行良好 行并使用此命令:
clang++ -Iinclude\ -Llib\ -lglfw3 -v .\main.cpp
所以看起来 lld 正在找到我放在 lib\ 目录中的 libglfw3.a 库文件。但是如果glfwInit(); 未注释,使用相同的命令我得到很多未解决的符号错误:
ld.lld: error: undefined symbol: __declspec(dllimport) CreateDIBSection
>>> referenced by libglfw3.a(win32_window.c.obj):(createIcon)
ld.lld: error: undefined symbol: __declspec(dllimport) CreateBitmap
>>> referenced by libglfw3.a(win32_window.c.obj):(createIcon)
ld.lld: error: undefined symbol: __declspec(dllimport) DeleteObject
>>> referenced by libglfw3.a(win32_window.c.obj):(createIcon)
>>> referenced by libglfw3.a(win32_window.c.obj):(createIcon)
>>> referenced by libglfw3.a(win32_window.c.obj):(updateFramebufferTransparency)
..等等。
我使用 CMake、Ninja 和 Clang 从 glfw 源代码构建了 glfw 库。
win32_window.c.obj 文件和这些错误引用的所有其他文件是 lib\ 目录中更深的几个目录,但我似乎无法让 clang/lld 找到它们。
我在这里缺少什么论点?
编辑:我跑了这个
clang++ -### -Iinclude\ -Llib\ -lglfw3 -v .\main.cpp
并得到了这两行:
"C:/msys64/clang64/bin/clang++.exe" "-cc1" "-triple" "x86_64-w64-windows-gnu" "-emit-obj" "-mrelax-all" "--mrelax-relocations" "-disable-free"
"-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none"
"-fmath-errno" "-fno-rounding-math" "-mconstructor-aliases" "-mms-bitfields" "-munwind-tables" "-target-cpu" "x86-64" "-tune-cpu" "generic"
"-debugger-tuning=gdb" "-v" "-fcoverage-compilation-dir=C:\\Users\\gcvan\\testProgram" "-resource-dir" "C:/msys64/clang64/lib/clang/13.0.0"
"-I" "include\\" "-internal-isystem" "C:/msys64/clang64/x86_64-w64-mingw32/include/c++/v1" "-internal-isystem" "C:/msys64/clang64/include/c++/v1"
"-internal-isystem" "C:/msys64/clang64/lib/clang/13.0.0/include" "-internal-isystem" "C:/msys64/clang64/x86_64-w64-mingw32/include"
"-internal-isystem" "C:/msys64/clang64/include" "-fdeprecated-macro" "-fdebug-compilation-dir=C:\\Users\\gcvan\\testProgram" "-ferror-limit"
"19" "-fmessage-length=120" "-fno-use-cxa-atexit" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-exception-model=seh"
"-fcolor-diagnostics" "-faddrsig" "-o" "C:/Users/gcvan/AppData/Local/Temp/main-c1d43f.o" "-x" "c++" ".\\main.cpp"
"C:/msys64/clang64/bin/ld.lld" "-m" "i386pep" "-Bdynamic" "-o" "a.exe" "C:/msys64/clang64/x86_64-w64-mingw32/lib/crt2.o"
"C:/msys64/clang64/x86_64-w64-mingw32/lib/crtbegin.o" "-Llib\\" "-LC:/msys64/clang64/x86_64-w64-mingw32/lib" "-LC:/msys64/clang64/lib"
"-LC:/msys64/clang64/x86_64-w64-mingw32/sys-root/mingw/lib" "-LC:/msys64/clang64/lib/clang/13.0.0/lib/windows" "-LC:\\cppLibraries" "-lglfw3"
"C:/Users/gcvan/AppData/Local/Temp/main-c1d43f.o" "-lc++" "-lmingw32" "C:/msys64/clang64/lib/clang/13.0.0/lib/windows/libclang_rt.builtins-x86_64.a"
"-lunwind" "-lmoldname" "-lmingwex" "-lmsvcrt" "-ladvapi32" "-lshell32" "-luser32" "-lkernel32" "-lmingw32"
"C:/msys64/clang64/lib/clang/13.0.0/lib/windows/libclang_rt.builtins-x86_64.a" "-lunwind" "-lmoldname" "-lmingwex" "-lmsvcrt" "-lkernel32"
"C:/msys64/clang64/x86_64-w64-mingw32/lib/crtend.o"