Car*_*s00 6 c c++ gcc g++ libevent
为什么这不起作用,文件test.c:
#include <event.h>
int main(void)
{
event_init();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后:
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
Run Code Online (Sandbox Code Playgroud)
所以它无法链接为C++.怎么解决这个?我需要链接它C++并编译为C.
Bas*_*tch 12
这个问题已被多次询问.在Linux上,您应该将库放在编译命令中的对象和源文件之后.所以试试吧
g++ -Wall -g -c mytest.cc
g++ -Wall -g mytest.o -levent -o mytest
Run Code Online (Sandbox Code Playgroud)
避免调用您的测试程序test,该程序是现有的实用程序或内置的shell.
作为一个新手,请记住始终编译所有要求的警告-Wall和调试-g并学习使用gdb
| 归档时间: |
|
| 查看次数: |
3843 次 |
| 最近记录: |