[geekery] Success! I think, anyway.
Dec. 16th, 2004 12:06 amA while back, I mentioned Klein, the network topologiser I wrote. I haven't added any new functionality to it yet, but now it's all packaged up and ready to be used by other people, courtesy the GNU autotools, which I've been fighting with off and on for the last couple of weeks. Last night, I discovered why my configure script couldn't find one of the libraries the program depends on -- it turns out that the AC_CHECK_LIBS macro in autoconf can't handle looking for C++ library functions that are in namespaces, or which don't have C linkages (i.e., aren't in extern "C" { ... } blocks). Tonight, I figured out a hack around it, which I reproduce here for anyone who might need it:
If you'd like to give Klein a spin, you can download it here. You'll need to have libpqxx (edit: um, and the Boost graph library, right, I meant to include that in the source tree) installed in order to compile it, and you'll need to have or make a PostgreSQL database with two columns that you want to use as the sources and targets of edges if you want to use it.
I'd like to make sure that I did this right, so if you're willing to download and build it, I'd appreciate a heads-up on whether it worked!
First, grep through the header for your C++ library to find a function with an extern "C" declaration (alternately, use nm and look for a function whose name isn't mangled). Look for a function that takes no parameters, otherwise your configure script will choke on it later. If you can't find one, look through the includes that your C++ library uses and see if you can find a C library that your C++ library links to statically. (I'll be honest: your guess is as good as mine on how to do this. I got lucky.) Pick any parameterless function from that library. Whichever you pick (a parameterless C-linked function from the problem library, or a function from some C library your problem library depends on), use that as the argument to AC_CHECK_LIBS. You may also need to use -lstdc++ as the OTHER-LIBRARIES argument in order to resolve linker errors, which would make the entire macro look likeAC_CHECK_LIBS(foo, bar_not_in_foo, , , [-lstdc++])This dodges the problem by checking for a function that autoconf can deal with in a library that autoconf normally couldn't, whether that function really belongs to the library or not.
If you'd like to give Klein a spin, you can download it here. You'll need to have libpqxx (edit: um, and the Boost graph library, right, I meant to include that in the source tree) installed in order to compile it, and you'll need to have or make a PostgreSQL database with two columns that you want to use as the sources and targets of edges if you want to use it.
I'd like to make sure that I did this right, so if you're willing to download and build it, I'd appreciate a heads-up on whether it worked!