Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: On Yaks and the Shaving Thereof - finding exported symbols of a C library

by VinsWorldcom (Parson)
on Mar 29, 2011 at 17:55 UTC ( #896237=note: print w/replies, xml ) Need Help??

in reply to On Yaks and the Shaving Thereof - finding exported symbols of a C library

UPDATE: I hate answering my own questions on here, but after playing with this all morning with no luck, a posted question and then lunch; I returned with a new direction and found this:

Luckily, I had a copy of gendef.exe from a MinGW-64 (4.4.5) that I have installed as gendef.exe doesn't seem to be in c:\strawberry\c\bin. dlltool is included with Strawberry, so:

NOTE: pexports.exe is included with Strawberry and the output is the same as gendef.exe, so one could just use pexports.exe instead of gendef.exe.

NOTE: There is a wpcap.dll installed in C:\Windows\system32 and C:\Windows\SysWOW64. I used the latter.

VinsWorldcom@C:\Users\VinsWorldcom\tmp> cp c:\Windows\SysWOW64\wpcap.d +ll . VinsWorldcom@C:\Users\VinsWorldcom\tmp> \Min\MinGW-64\bin\gendef.exe w +pcap.dll * [wpcap.dll] Found PE image VinsWorldcom@C:\Users\VinsWorldcom\tmp> which dlltool C:\strawberry\c\bin\dlltool.exe VinsWorldcom@C:\Users\VinsWorldcom\tmp> dlltool --as-flags=--64 -m i38 +6:x86-64 -k --output-lib libwpcap.a --input-def wpcap.def VinsWorldcom@C:\Users\VinsWorldcom\tmp> ls -al libwpcap.a Directory of C:\Users\VinsWorldcom\tmp 03/29/2011 02:27 PM 65,656 libwpcap.a 1 File(s) 65,656 bytes VinsWorldcom@C:\Users\VinsWorldcom\tmp> ls -al WpdPack\Lib\libwpcap.a Directory of C:\Users\VinsWorldcom\tmp\WpdPack\Lib 06/25/2010 10:02 AM 54,276 libwpcap.a 1 File(s) 54,276 bytes VinsWorldcom@C:\Users\VinsWorldcom\tmp> ls -al WpdPack\Lib\x64\libwpca +p.a File Not Found Directory of C:\Users\VinsWorldcom\tmp\WpdPack\Lib\x64 VinsWorldcom@C:\Users\VinsWorldcom\tmp> cp libwpcap.a WpdPack\Lib\x64

I used gendef.exe and dlltool.exe to create a new libwpcap.a static library from the 64-bit wpcap.dll. Why isn't there one included in the WpdPack/Lib/x64 directory already - who knows? In any case, once the new static library was copied into place, I re-ran 'perl Makefile.PL' with the following adjustment:

perl Makefile.PL INC=-IC:/Users/VinsWorldcom/tmp/WpdPack/Include "LIBS +=-LC:/Users/VinsWorldcom/tmp/WpdPack/Lib/x64 -lwpcap"

The subsequent 'dmake' worked this time, 'dmake test' had a few failures (similar to my WinXP experience). After a 'dmake install' a quick test script works fine:

VinsWorldcom@C:\Users\VinsWorldcom\tmp> more use Net::Pcap qw(:functions); @devs = pcap_findalldevs(\%devinfo, \$err); for my $dev (@devs) { print "$dev : $devinfo{$dev}\n" } VinsWorldcom@C:\Users\VinsWorldcom\tmp> perl \Device\NPF_{7C974F8C-6E64-44D9-B5F5-BE1242FA897D} : Intel(R) PRO/1000 + MT Network Connection VinsWorldcom@C:\Users\VinsWorldcom\tmp>

If this node goes completely unnoticed, it will at least serve as a personal archive for the next time I'm doing this on Win7.


So the patches worked for me with WinXP (x86, SP3) / Strawberry (5.12.2). However, I'm also trying this on Windows 7 (64-bit) / Strawberry (5.12.2 MSWin32-x64-multi-thread) and it's not going as well.

VinsWorldcom@C:\strawberry\cpan\build\Net-Pcap-0.16-BzfeHy# perl Makef +ile.PL INC=-IC:/Users/VinsWorldcom/tmp/WpdPack/Include "LIBS=-LC:/Use +rs/VinsWorldcom/tmp/WpdPack/Lib -lwpcap" socket.h patched... ok looking for -lwpcap... yes checking for pcap_lib_version() in -lwpcap... yes Using 'C:\Windows\system32\wpcap.dll' as potential symbol candidate at + Makefile.PL line 556. detecting available functions... ok Using 'C:\Windows\system32\wpcap.dll' as potential symbol candidate at + Makefile.PL line 556. detecting available functions... ok Writing Makefile for Net::Pcap VinsWorldcom@C:\strawberry\cpan\build\Net-Pcap-0.16-BzfeHy# dmake Skip blib\lib\Net\ (unchanged) gcc -c -IC:/Users/VinsWorldcom/tmp/WpdPack/Include -s -O2 -DWIN32 -D +HAVE_DES_FCRYPT -DWIN64 -DCONSERVATIVE -DUSE_SITECUSTOMIZE -DPERL_IMP +LICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-bitfields + -DPERL_MSVCRT_READFIX -s -O2 -DVERSION=\"0.16\" -DXS_VERSION=\"0 +.16\" "-IC:\strawberry\perl\lib\CORE"-DWINSOCK2_H_REQUESTED -DWPCAP +-DHAVE_REMOTE -DHAVE_BLANK -DHAVE_PCAP_LIB_VERSION -DHAVE_PCAP_BREAKL +OOP -DHAVE_PCAP_COMPILE_NOPCAP -DHAVE_PCAP_CREATESRCSTR -DHAVE_PCAP_D +ATALINK_NAME_TO_VAL -DHAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION -DHAVE_PC +AP_DATALINK_VAL_TO_NAME -DHAVE_PCAP_DUMP_FILE -DHAVE_PCAP_DUMP_FLUSH +-DHAVE_PCAP_FINDALLDEVS -DHAVE_PCAP_GETEVENT -DHAVE_PCAP_GETNONBLOCK +-DHAVE_PCAP_LIB_VERSION-DHAVE_PCAP_NEXT_EX -DHAVE_PCAP_OPEN -DHAVE_PC +AP_OPEN_DEAD -DHAVE_PCAP_PARSESRCSTR -DHAVE_PCAP_SENDPACKET -DHAVE_PC +AP_SENDQUEUE_ALLOC -DHAVE_PCAP_SENDQUEUE_QUEUE -DHAVE_PCAP_SENDQUEUE_ +TRANSMIT -DHAVE_PCAP_SETBUFF -DHAVE_PCAP_SETMINTOCOPY -DHAVE_PCAP_SET +MODE -DHAVE_PCAP_SETNONBLOCK -DHAVE_PCAP_SET_DATALINK Pcap.c In file included from Pcap.xs:43: warning: #warning "the function pcap_list_datalinks() + is not available" warning: #warning "the function pcap_get_selectable_f +d() is not available" warning: #warning "the function pcap_setuserbuffer() +is not available" warning: #warning "the function pcap_sendqueue_destro +y() is not available" warning: #warning "the function pcap_setsampling() is + not available" Pcap.c: In function 'XS_Net__Pcap_strerror': Pcap.c:1584: warning: assignment discards qualifiers from pointer targ +et type Pcap.xs: In function 'XS_Net__Pcap_getevent': Pcap.xs:951: warning: cast from pointer to integer of different size Running Mkbootstrap for Net::Pcap () C:\strawberry\perl\bin\perl.exe -MExtUtils::Command -e "chmod" -- 644 dlltool --def Pcap.def --output-exp dll.exp g++ -o blib\arch\auto\Net\Pcap\Pcap.dll -Wl,--base-file -Wl,dll.base - +mdll -s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib" Pcap. +o -Wl,--image-base,0x7e070000 C:\strawberry\perl\lib\CORE\libperl512 +.a C:\Users\VinsWorldcom\tmp\WpdPack\Lib\libwpcap.a C:\strawberry\c\x +86_64-w64-mingw32\lib\libmoldname.a C:\strawberry\c\x86_64-w64-mingw3 +2\lib\libkernel32.a C:\strawberry\c\x86_64-w64-mingw32\lib\libuser32. +a C:\strawberry\c\x86_64-w64-mingw32\lib\libgdi32.a C:\strawberry\c\x +86_64-w64-mingw32\lib\libwinspool.a C:\strawberry\c\x86_64-w64-mingw3 +2\lib\libcomdlg32.a C:\strawberry\c\x86_64-w64-mingw32\lib\libadvapi3 +2.a C:\strawberry\c\x86_64-w64-mingw32\lib\libshell32.a C:\strawberry +\c\x86_64-w64-mingw32\lib\libole32.a C:\strawberry\c\x86_64-w64-mingw +32\lib\liboleaut32.a C:\strawberry\c\x86_64-w64-mingw32\lib\libnetapi +32.a C:\strawberry\c\x86_64-w64-mingw32\lib\libuuid.a C:\strawberry\c +\x86_64-w64-mingw32\lib\libws2_32.a C:\strawberry\c\x86_64-w64-mingw3 +2\lib\libmpr.a C:\strawberry\c\x86_64-w64-mingw32\lib\libwinmm.a C:\s +trawberry\c\x86_64-w64-mingw32\lib\libversion.a C:\strawberry\c\x86_6 +4-w64-mingw32\lib\libodbc32.a C:\strawberry\c\x86_64-w64-mingw32\lib\ +libodbccp32.a C:\strawberry\c\x86_64-w64-mingw32\lib\libcomctl32.a dl +l.exp Pcap.o:Pcap.c:(.text+0x126b): undefined reference to `pcap_sendqueue_t +ransmit' Pcap.o:Pcap.c:(.text+0x16a7): undefined reference to `pcap_sendqueue_q +ueue' Pcap.o:Pcap.c:(.text+0x1924): undefined reference to `pcap_sendqueue_a +lloc' Pcap.o:Pcap.c:(.text+0x1b31): undefined reference to `pcap_sendpacket' Pcap.o:Pcap.c:(.text+0x1d20): undefined reference to `pcap_getevent' Pcap.o:Pcap.c:(.text+0x1f6a): undefined reference to `pcap_setmintocop +y' Pcap.o:Pcap.c:(.text+0x21ea): undefined reference to `pcap_setmode' Pcap.o:Pcap.c:(.text+0x246a): undefined reference to `pcap_setbuff' Pcap.o:Pcap.c:(.text+0x27aa): undefined reference to `pcap_open' Pcap.o:Pcap.c:(.text+0x2eb9): undefined reference to `pcap_parsesrcstr +' Pcap.o:Pcap.c:(.text+0x3605): undefined reference to `pcap_createsrcst +r' Pcap.o:Pcap.c:(.text+0x38c8): undefined reference to `pcap_geterr' Pcap.o:Pcap.c:(.text+0x3b14): undefined reference to `pcap_geterr' Pcap.o:Pcap.c:(.text+0x3b24): undefined reference to `pcap_stats' Pcap.o:Pcap.c:(.text+0x3e28): undefined reference to `pcap_fileno' Pcap.o:Pcap.c:(.text+0x4020): undefined reference to `pcap_file' Pcap.o:Pcap.c:(.text+0x4254): undefined reference to `pcap_lib_version +' Pcap.o:Pcap.c:(.text+0x4420): undefined reference to `pcap_strerror' Pcap.o:Pcap.c:(.text+0x461c): undefined reference to `pcap_perror' Pcap.o:Pcap.c:(.text+0x47c8): undefined reference to `pcap_minor_versi +on' Pcap.o:Pcap.c:(.text+0x49d8): undefined reference to `pcap_major_versi +on' Pcap.o:Pcap.c:(.text+0x4be8): undefined reference to `pcap_is_swapped' Pcap.o:Pcap.c:(.text+0x4df8): undefined reference to `pcap_snapshot' Pcap.o:Pcap.c:(.text+0x5000): undefined reference to `pcap_datalink_va +l_to_description' Pcap.o:Pcap.c:(.text+0x51c0): undefined reference to `pcap_datalink_va +l_to_name' Pcap.o:Pcap.c:(.text+0x5385): undefined reference to `pcap_datalink_na +me_to_val' Pcap.o:Pcap.c:(.text+0x55ba): undefined reference to `pcap_set_datalin +k' Pcap.o:Pcap.c:(.text+0x57c8): undefined reference to `pcap_datalink' Pcap.o:Pcap.c:(.text+0x59d8): undefined reference to `pcap_dump_flush' Pcap.o:Pcap.c:(.text+0x5bd0): undefined reference to `pcap_dump_file' Pcap.o:Pcap.c:(.text+0x5e63): undefined reference to `pcap_dump_close' Pcap.o:Pcap.c:(.text+0x5fd3): undefined reference to `pcap_close' Pcap.o:Pcap.c:(.text+0x6143): undefined reference to `pcap_breakloop' Pcap.o:Pcap.c:(.text+0x62b3): undefined reference to `pcap_freecode' Pcap.o:Pcap.c:(.text+0x64cf): undefined reference to `pcap_setfilter' Pcap.o:Pcap.c:(.text+0x6861): undefined reference to `pcap_compile_nop +cap' Pcap.o:Pcap.c:(.text+0x6ccd): undefined reference to `pcap_geterr' Pcap.o:Pcap.c:(.text+0x6ce8): undefined reference to `pcap_compile' Pcap.o:Pcap.c:(.text+0x71d1): undefined reference to `pcap_dump' Pcap.o:Pcap.c:(.text+0x751c): undefined reference to `pcap_next_ex' Pcap.o:Pcap.c:(.text+0x79c2): undefined reference to `pcap_next' Pcap.o:Pcap.c:(.text+0x7e59): undefined reference to `pcap_loop' Pcap.o:Pcap.c:(.text+0x81ec): undefined reference to `pcap_geterr' Pcap.o:Pcap.c:(.text+0x8224): undefined reference to `pcap_dispatch' Pcap.o:Pcap.c:(.text+0x8539): undefined reference to `pcap_getnonblock +' Pcap.o:Pcap.c:(.text+0x88b8): undefined reference to `pcap_setnonblock +' Pcap.o:Pcap.c:(.text+0x8bc8): undefined reference to `pcap_dump_open' Pcap.o:Pcap.c:(.text+0x8db7): undefined reference to `pcap_open_offlin +e' Pcap.o:Pcap.c:(.text+0x9017): undefined reference to `pcap_open_dead' Pcap.o:Pcap.c:(.text+0x92c5): undefined reference to `pcap_open_live' Pcap.o:Pcap.c:(.text+0x95eb): undefined reference to `pcap_findalldevs +' Pcap.o:Pcap.c:(.text+0x97b2): undefined reference to `pcap_lookupdev' Pcap.o:Pcap.c:(.text+0x988d): undefined reference to `pcap_freealldevs +' Pcap.o:Pcap.c:(.text+0x9b10): undefined reference to `pcap_lookupnet' Pcap.o:Pcap.c:(.text+0x9eae): undefined reference to `pcap_lookupdev' collect2: ld returned 1 exit status dmake: Error code 129, while making 'blib\arch\auto\Net\Pcap\Pcap.dll +' VinsWorldcom@C:\strawberry\cpan\build\Net-Pcap-0.16-BzfeHy#

The "undefined reference to `pcap_...'" usually show up because the functions have no library to link against - at least that's what I've seen before. However, I clearly tell it to link against wpcap (-lwpcap), where to find libwpcap.a (C:/Users/VinsWorldcom/tmp/WpdPack/Lib) and those directives show up in the 'dmake' output.

Could this be a 32-bit/64-bit issue - as this method worked fine on a WinXP (32-bit) system but is failing on Win7 (64-bit)?

I also noticed in the WpdPack/Lib subdirs, there is an x64 subdirectory, but there is only MSVC++ .lib files, no .a files.

VinsWorldcom@C:\Users\VinsWorldcom\tmp\WpdPack> ls -alR Lib Directory of C:\Users\VinsWorldcom\tmp\WpdPack\Lib 03/29/2011 01:43 PM <DIR> . 03/29/2011 01:43 PM <DIR> .. 06/25/2010 10:01 AM 20,814 libpacket.a 06/25/2010 10:02 AM 54,276 libwpcap.a 06/25/2010 09:47 AM 8,450 Packet.lib 06/25/2010 09:47 AM 19,320 wpcap.lib 03/29/2011 01:43 PM <DIR> x64 4 File(s) 102,860 bytes Directory of C:\Users\VinsWorldcom\tmp\WpdPack\Lib\x64 03/29/2011 01:43 PM <DIR> . 03/29/2011 01:43 PM <DIR> .. 06/25/2010 09:49 AM 8,290 Packet.lib 06/25/2010 09:49 AM 18,892 wpcap.lib 2 File(s) 27,182 bytes Total Files Listed: 6 File(s) 130,042 bytes

Replies are listed 'Best First'.
Re^2: On Yaks and the Shaving Thereof - finding exported symbols of a C library
by Corion (Pope) on Nov 09, 2016 at 21:11 UTC
Re^2: On Yaks and the Shaving Thereof - finding exported symbols of a C library
by sethlwilson (Initiate) on Jun 29, 2011 at 18:17 UTC

    Thanks so much for posting this! I'd been stuck for days trying to figure out why Net:Pcap wouldn't build for me even with the patch. Your solution worked perfectly!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://896237]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2018-10-22 16:51 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (121 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!