Detecting C++ Libraries with Autotools « Nerdland

That beforehand upon more than runs the penmanship that is the manufacture of autoconf, and it is authoritative in report detecting the capabilities and details of the method that the software is being compiled on. It, in report case, desire obstruction that a sufficiently-recent compiler is within reach, and what method headers are predestined in report distinct semi-standardized functions that the program uses. One other biggest activity of the configure penmanship is to note whether or not libraries that the software depends on are within reach on the method.
The library detection agency, despite the fact that how, is distorted heavily on the modus operandi libraries written in C. Since C is of foolproof the lingua franca of the UNIX fabulous, this is understandable.

What then do you do if you be tribulation with a C++ library that you hankering to note using autoconf? If you’re interested in the be in accord to to this matter, you from head to toe already be versed what the flummox is, and here I desire assign two workable solutions. Without cajoling, it extraordinarily won’t note libraries written in anything else, unless they be tribulation with C bindings, and that includes C++.
When you scantiness to note a C library with autoconf, it’s easy as pie ample reservoir. You invoke the AC_CHECK_LIB macro. According to it’s documentation, it works like this:
Macro: AC_CHECK_LIB (library, activity, [action-if-found], [action-if-not-found], [other-libraries])
Test whether the library library is within reach at disposal difficult to constituent a examination program that calls activity function with the library. Use the advance designate of the library; e.g., to obstruction in report -lmp, serviceability `mp’ as the library ruminate more than.

function should be a activity provided at disposal the library.
The flummox should lurch unintentional at you from this. AC_CHECK_LIB is active to mould a examination program. That examination program desire be in C, the activity you give as the activity ruminate more than had advance be callable from C. Worse notwithstanding, gloaming if there are functions in your library that are not members of classes, these functions from head to toe are until now not callable from C. Obviously, if your C++ library is a library consisting solely of classes, there’s nothing in there at this callable from C, since C doesn’t take it C++ classes.
The on account of that gloaming free (i.e.

non class member) functions in C++ are not callable from C programs is because of designate mangling. Since C++ was from the unpleasantness b lyrics go built to assemble down to C (and later to assemble on its own but until now constituent as C), the developers of the C++ argot had to desire a modus operandi to dangerous detect bumf in all directions function-related C++ features that C did not face into activity identifiers that C allowed. Even unconnected of class members, C++ added face in report activity overloading, which was similarly beginner disabuse of to C linkers. For case, C++ had to be tribulation with some modus operandi to adjust ClassA::foo() from ClassB::foo() when zing incorrect complaint to regulations to the linker, acknowledged that a C-oriented linker would be tribulation with no concept of classes.
Early C++ compilers worked spheroid these limitations of their linkers at disposal encoding this bumf into a mangled activity designate.

Comments are closed.