[英]g++ error linking functions from static library
我有一个Qt5 C ++程序,正在尝试链接到静态库。 静态库为Senselock / libsenseEIV.a(相对于main.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
之后指定库名称。 换句话说,您需要在.pro文件的LIBS
变量赋值中同时包含两者。
毕竟,您可以为您的案例使用LIBS += -L$$PWD/senselock/ -lsenseEIV
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.