G++ 链接器忽略静态库
G++ linker ignores static library
包含标头,但不包含静态库(influxdb(。
我的任务.json 文件:
{
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file (mt)",
"command": "C:/msys64/mingw64/bin/g++.exe",
"args": [
"-v",
"-LC:/influxdb-cxx/lib",
"-g",
"${file}",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe",
"-std=c++17",
"-lws2_32",
"-lInfluxDB"
],
"options": {
"cwd": "C:/msys64/mingw64/bin"
},
"problemMatcher": [
"$gcc"
]
},
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:/msys64/mingw64/bin/g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe",
"-std=c++17"
],
"options": {
"cwd": "C:/msys64/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
],
"version": "2.0.0"
}
使用 -v 选项显示库路径和库名称被传递给链接器(-LC:/influxdb-cxx/lib 和 -lInfluxDB(:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/collect2.exe -plugin C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/liblto_plugin-0.dll -plugin-opt=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:UsersAdminAppDataLocalTempccxBryht.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -m i386pep -Bdynamic -o c:/path/to/executable.exe C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/crtbegin.o -LC:/influxdb-cxx/lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0 -LC:/msys64/mingw64/bin/../lib/gcc -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../.. C:UsersAdminAppDataLocalTempccjciO8C.o -lws2_32 -lInfluxDB -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/default-manifest.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/
在编译时,我在这个库中的所有函数上都收到"未定义的引用"错误。但是链接器并没有说找不到文件,所以它链接了库,我猜。此库文件包含所有函数。我已经使用 nm 检查了这一点。
我也尝试更改链接顺序,但没有帮助。
我的系统是Windows 7,编辑器是VS代码,编译器是msys2 mingw64 g++。
库路径包含在 LIB 环境变量中,标头路径包含在 INCLUDE 中,dll 路径包含在路径中。
添加对-lInfluxDB
应为命令行末尾的附加引用。我不知道如何在tasks.json中执行此操作。
我相信 GNU 链接器只向前解析依赖关系。 也就是说,如果库 A 依赖于 B,则-lA
必须在命令行顺序中出现在-lB
之前。 如果 A 和 B 相互依赖,您可以执行-lA -lB -lA
或阅读此内容。
相关文章:
- 基于boost的程序的静态链接——zlib问题
- 使用gcc从静态链接的文件中查找可选符号
- 使用转换器提升 Python 问题 - 静态链接
- C++实用程序::转换在静态链接库中不起作用
- 将源中的 GLEW 与 cmake 静态链接
- 在发布模式下启动使用库的静态链接编译的应用程序时出错
- libavdevice 和 x11 的静态链接库应该以什么顺序链接?
- 静态链接启用 PIC 的库时出现链接器 PIC 错误
- 静态链接库时,收到链接器错误:找不到 -lgcc_s
- 静态链接 glibc & boost_python36 for Python extension
- 我可以在C++中配置静态链接吗?
- 协议缓冲区的静态链接会导致与现有符号冲突
- C++标准是否定义了结构中成员函数的函数内定义是否必须具有静态链接?
- 静态链接 Visual Studio dll 到动态链接的 sfml 项目
- 我可以加载与库静态链接的 dll 吗?
- 静态链接MSVC库,动态链接Qt
- C++:找不到静态链接
- OpenSSL AES仅适用于某些计算机,即使具有静态链接也是如此
- CURL 静态链接未解析的外部符号
- 如何强制Windows.h在Visual Studio中静态链接而不是动态链接?