开发者

c++ code using libnet not compiling

开发者 https://www.devze.com 2023-04-08 17:59 出处:网络
I\'m trying to compile my libnet script and am getting this error: [root@whyme]# gcc -Wall `libnet-config --defines` mysocket.cc -o mysocket `libnet-config --libs` -lpcap -lnet

I'm trying to compile my libnet script and am getting this error:

[root@whyme]# gcc -Wall `libnet-config --defines` mysocket.cc -o mysocket `libnet-config --libs` -lpcap -lnet
/tmp/ccUPbuVg.o: In function `main':
mysocket.cc:(.text+0x1e): undefined reference to `net_init'
mysocket.cc:(.text+0x2a): undefined reference to `net_loadconfig'
mysocket.cc:(.text+0x35): undefined reference to `net_detectdrivers'
mysocket.cc:(.text+0x40): undefined reference to `net_initdrivers'
mysocket.cc:(.text+0x54): undefined reference to `ne开发者_StackOverflowt_openconn'
mysocket.cc:(.text+0x83): undefined reference to `net_listen'
mysocket.cc:(.text+0xbe): undefined reference to `net_poll_listen'
mysocket.cc:(.text+0xd2): undefined reference to `net_closeconn'
mysocket.cc:(.text+0xf1): undefined reference to `net_receive_rdm'
mysocket.cc:(.text+0x11b): undefined reference to `net_query_rdm'

I didn't paste my code because this looks like it's related to linking the objects.


I'm able to compile & execute this source file with your exact command (changing only the filenames): https://github.com/repolho/Libnet-1.1-tutorial-examples/blob/master/01_init.c

I therefore suspect the problem is in your source after all. Most libnet function names are of the form libnet_[funcname], but in your linker errors I see names of the form net_[funcname].

I also note that you've manually inserted -lnet. On my system, -lnet is the entire output of libnet-config --libs, so if you do need it specifying it manually is redundant. It's not harmful, but you can type fewer characters next time. :)


Could you check what is returned by "libnet-config --libs" ?

It might be returning something wrong, thus preventing the linker to find the libnet library. Make sure that the part saying "-L XXXX" points to the directory where libnet library is located.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号