静态库中的 g++ 错误链接函数
g++ error linking functions from static library
我有一个Qt5 C++程序,我正在尝试链接到一个静态库。 静态库是senselock/libsenseEIV.a(相对于主文件.cpp(。 当我编译时,我看到下面的输出:
^
g++ -Wl,-rpath,/opt/Qt/5.7/gcc_64/lib -o test1 main.o -Lsenselock/libsenseEIV.a -L/opt/Qt/5.7/gcc_64/lib -lQt5Core -lpthread
main.o: In function `test1()':
/test1/main.cpp:31: undefined reference to `S4Enum'
/test1/main.cpp:58: undefined reference to `S4Enum'
/test1/main.cpp:71: undefined reference to `S4Open'
/test1/main.cpp:83: undefined reference to `S4Control'
/test1/main.cpp:102: undefined reference to `S4Close'
collect2: error: ld returned 1 exit status
make: *** [Makefile:216: test1] Error 1
11:55:27: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project test1 (kit: Desktop Qt 5.7.1 GCC 64bit)
When executing step "Make"
在我的 .pro 文件中,我有
LIBS += -Lsenselock/libsenseEIV.a
万一重要。 有人可以解释如何解决此错误吗? 未定义的引用错误都与位于该libsenseEIV.a库中的函数有关。
我不明白编译器是否找不到 .a 文件或存在其他错误。
更新:我尝试了这种语法
LIBS += -Lsenselock -lsenseEIV
但它会产生错误
/usr/bin/ld: 找不到 -lsenseEIV
我是否使用了错误的库名称? 如果是这样,我将如何找到这个名字? (假设这被编译到 .a 文件中(
命令行的这一部分是错误的:
-Lsenselock/libsenseEIV.a
应该是:
senselock/libsenseEIV.a
(-Lfoo/bar.a
告诉链接器在目录foo/bar.a/
中搜索库,这根本不是你想要的。
没有
-l
前缀?
您可以通过以下(大部分等效(方式指定与libsenseEIV.a
的链接:
senselock/libsenseEIV.a
-Lsenselock -lsenseEIV
-Lsenselock -l:libsenseEIV.a
您使用链接器标志错误,您应该在-L
之后指定库路径,在-l
之后指定库名称。换句话说,您需要在赋值中同时具有两者,以LIBS
.pro 文件中的变量。
毕竟事实证明,您可以将LIBS += -L$$PWD/senselock/ -lsenseEIV
用于您的案例
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 使用cmake错误链接boost日志
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- 静态库中的 g++ 错误链接函数
- 未定义的参考错误链接天然函数Android
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- QT Q_PROPERTY错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- C 错误链接器命令失败了出口代码1(使用-V查看调用)
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- 聚输出错误 - 链接列表
- Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用)
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接