无法将 LIBEVENT 链接为 C++
为什么这不起作用,文件 test.c
:
#include <event.h>
int main(void)
{
event_init();
return 0;
}
然后: gcc -o test.o -c test.c
运行正常,但
链接: g++ -o test -levent test.o
产生
test.o: In function `main':
test.c:(.text+0x5): undefined reference to `event_init'
collect2: ld returned 1 exit status
因此它不能作为 C++
链接。怎么解决这个问题呢?我需要将其链接为 C++
并编译为 C
。
Why this does not work, file test.c
:
#include <event.h>
int main(void)
{
event_init();
return 0;
}
Then:gcc -o test.o -c test.c
runs OK, but
Link:g++ -o test -levent test.o
produces
test.o: In function `main':
test.c:(.text+0x5): undefined reference to `event_init'
collect2: ld returned 1 exit status
So it cannot be linked as C++
. How to solve this? I need to link it as C++
and compile as C
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题已经被问过很多次了。在 Linux 上,您应该在编译命令中将库放在对象和源文件之后。因此,请尝试
避免调用您的测试程序
test
这是现有的实用程序或 shell 内置程序。作为新手,请记住始终在编译时询问
-Wall
和调试-g
的所有警告,并学习使用gdb
This question has been asked many times. On Linux, you should put libraries after object and source files in the compilation command. So try
Avoid calling your test program
test
which is an existing utility or shell builtin.As a newbie, remember to always compile with all warnings asked
-Wall
and for debugging-g
and learn to usegdb