Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ g++;链接到外部库会创建未定义的引用_C++_Linux_Gcc - Fatal编程技术网

C++ g++;链接到外部库会创建未定义的引用

C++ g++;链接到外部库会创建未定义的引用,c++,linux,gcc,C++,Linux,Gcc,我正在尝试构建一个简单的程序来测试外部库的使用,但是在将它与g++链接时遇到了问题。请参见命令/结果: user@user-Nuvo-2510VTC:~/Desktop/WDT_DIO/linux/test$ g++ -o main main.o -lwdt_dio /usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `sem_unlink' /usr/lib/gcc/x86_

我正在尝试构建一个简单的程序来测试外部库的使用,但是在将它与g++链接时遇到了问题。请参见命令/结果:

user@user-Nuvo-2510VTC:~/Desktop/WDT_DIO/linux/test$ g++ -o main main.o -lwdt_dio
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `sem_unlink'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `pthread_mutexattr_settype'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `sem_close'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `pthread_spin_lock'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `pthread_spin_unlock'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `pthread_create'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `pthread_spin_init'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `pthread_mutexattr_init'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `pthread_spin_destroy'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `sem_post'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `sem_open'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `sem_getvalue'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `sem_wait'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libwdt_dio.so: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
它看起来好像没有链接到操作系统中的一些基本库

详情:

gcc --version --> 5.4.0 20160609
ldd --version --> 2.23
OS            --> Ubuntu 16.04 x64, 4.8.0-36-generic kernel

您似乎缺少指向
pthread
库的链接。将
-pthread
添加到编译命令:

g++ -o main main.o -pthread -lwdt_dio
检查手册页的
sem\u wait(3)
显示:

链接到-pthread


注意:sem_wait是随机选择的,它们都应该指定您似乎缺少指向
pthread
库的链接。将
-pthread
添加到编译命令:

g++ -o main main.o -pthread -lwdt_dio
检查手册页的
sem\u wait(3)
显示:

链接到-pthread


注意:sem_wait是随机选择的,所有这些错误都应该指定

如果仔细阅读错误,则表示未定义的错误来自
libwdt_dio.so
。它还表示您对哪个函数有未定义的引用

在本例中,它是pthread库。在WDT lib文档中,它可能应该作为依赖项提到


如果要通过命令行进行编译,可以将
-pthread
添加到g++命令中

如果仔细阅读错误,就会发现未定义的错误来自
libwdt\u dio.so
。它还表示您对哪个函数有未定义的引用

在本例中,它是pthread库。在WDT lib文档中,它可能应该作为依赖项提到


如果要通过命令行进行编译,可以将
-pthread
添加到g++命令中

无法接受您或Petar的评论,但您是正确的。你们怎么知道图书馆丢了什么?pthread很明显,但我没有立即意识到信号量函数是同一个函数的一部分library@NateGreco,我熟悉这些方法,但为了以防万一,我还添加了一个直截了当的解释……太好了,thaknsCan还不能接受你或Petar的评论,但你是正确的。你们怎么知道图书馆丢了什么?pthread很明显,但我没有立即意识到信号量函数是同一个函数的一部分library@NateGreco,我熟悉这些方法,但为了以防万一,我还添加了一个简单的解释…完美,Thakns可能是和的副本,也可能是和的副本