Perl: the Markov chain saw | |
PerlMonks |
On Yaks and the Shaving Thereof - finding exported symbols of a C libraryby Corion (Patriarch) |
on Mar 22, 2011 at 22:27 UTC ( [id://894897]=perlquestion: print w/replies, xml ) | Need Help?? |
Corion has asked for the wisdom of the Perl Monks concerning the following question: After finding some changes that Sniffer::HTTP needed, I tried to run its test suite. My Strawberry Perl installation was missing some modules, since I hadn't touched Sniffer::HTTP for some time. Especially, it needed Net::Pcap. So I went, and downloaded the WinPCap driver and developer pack from http://www.winpcap.org/devel.htm and installed them. Then I found that I had already reported about four months ago that Net::Pcap 0.16 with libpcap 1.0 does not compile on Windows. So, I decided to look deeper into the problem:
...dropped me in the unpacked distribution directory. And fair enough, running the Makefile.PL with the appropriate parameters showed me that it did not find any of the "interesting" functions of the library. In fact, I found that DynaLoader loads DLLs on Windows (as expected) but seems to load .a files and other object files on other operating systems . At least, that's what the usage in the Makefile.PL suggests to me:
So, "all" I had to do was to find a suitable replacement (or suitable munging) of that code to find whether an object file exports a certain symbol or not. I ended up with the following, fairly ugly code:
That code munges a found .a file and infers the name of the DLL that belongs to it, at least for gcc. Then it searches that DLL in $ENV{PATH} and uses DynaLoader to load and inspect that DLL. My question is whether anybody knows how to extract the symbols of a library. I'm sure that there must be a much better, Perlish way to find out whether an object file (or a C header) exports a certain symbol or not. I briefly toyed with the idea of parsing the output of nm $libfile, but that will break on MSVC, and also, I know nothing about the different incarnations of nm across operating systems. The only relevant module I found is ExtUtils::FindFunctions by Maddingue and it (unsurprisingly) suffers the same problems, as Maddingue also is the author of Net::Pcap. PS: The patch is submitted so that should make Net::Pcap compile again on Windows (and elsewhere?), and hopefully, a new release of Net::Pcap will include these.
Back to
Seekers of Perl Wisdom
|
|