3

I am trying to build an example program which uses WinPcap-functions. I’m working under Windows 7 64 Bit edition with MinGW. I am able to compile the C-code to an object file, but I can’t link against wpcap.lib. My linker call looks like this:

gcc -L ../../lib/x64 send_packet.o -lwpcap -o WinPcapTest.exe

With this call I get the following errors:

undefined reference to pcap_open

undefined reference to pcap_sendpacket

undefined reference to pcap_geterr

Obviously I am not linking against wpcap.lib, but I don’t know why. The library is definitely found. If I change the lib include path for example, I get this error:

cannot find -lwpcap

Why does the linker find the lib but does not link against it? Thanks for your help.

user3035952
  • 301
  • 5
  • 12
  • Does this `gcc -L ../../lib/x64 send_packet.o -lwpcap -o WinPcapTest.exe` reflect the **real** command you issue to build the executable giving you the error mentioned in your question, especially in terms of the order of the arguments? – alk Nov 26 '13 at 10:59
  • Yes. I only shortend the library include path for better readability. The real command looks like this: `gcc -L ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Lib\x64 send_packet.o -lwpcap -o WinPcapTest.exe` – user3035952 Nov 26 '13 at 11:09
  • I also tried the combined compiler and linker call: `gcc -I ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Include ..\send_packet.c -L ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Lib\x64 -lwpcap -O0 -g3 -Wall -o WinPcapTest.exe` and got the same result. – user3035952 Nov 26 '13 at 11:18

1 Answers1

2

Try listing you libraries after binary definition. As far as I remember, with provided gcc command, ld would be symbol matching for pcap symbols between send_packet.o and libwpcap.lib but not with WinPcapTest.exe. I would suggest moving -lwpcap at the end:

gcc -I ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Include ..\send_packet.c -L ..\..\..\Downloads\WpdPack_4_1_2\WpdPack\Lib\x64 -O0 -g3 -Wall -o WinPcapTest.exe -lwpcap
jcm
  • 2,568
  • 14
  • 18