1 // gcc -Wall -o gcc-glibmm-abi-check abicheck.c -ldl
2 // help2man -N -n 'glib gcc4/5 C++11 ABI compatibility test' -o gcc-glibmm-abi-check.1 ./gcc-glibmm-abi-check
11 static void print_usage (void) {
12 printf ("gcc-glibmm-abi-check - gcc4/5 C++11 ABI compatibility test\n\n");
14 printf ("Usage: gcc-glibmm-abi-check [ OPTIONS ]\n\n");
16 "This tool checks for C++ specific symbols in libglimm which are different in\n"
17 "the gcc4 and gcc5/c++11 ABI in order to determine system-wide use of gcc5.\n"
18 // TODO document error codes,...
21 printf ("\nOptions:\n"
22 " -f, --fail fail if system cannot be determined.\n"
23 " -h, --help Display this help and exit.\n"
24 " -4, --gcc4 Test succeeds if gcc4 ABI is found.\n"
25 " -5, --gcc5 Test succeeds if gcc5 ABI is found.\n"
26 " -g <soname>, --glibmm <soname>\n"
27 " Specify alternative file for libglibmm-2.4.so\n"
28 " -v, --verbose Print information.\n"
29 " -V, --version Print version information and exit.\n"
33 static void print_version (void) {
34 printf ("gcc-glibmm-abi-check version %s\n\n", VERSION);
36 "Copyright (C) GPL 2015 Robin Gareus <robin@gareus.org>\n"
37 "This is free software; see the source for copying conditions. There is NO\n"
38 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
42 int main (int argc, char **argv) {
47 char const * glibmm = "libglibmm-2.4.so";
49 const struct option long_options[] = {
50 { "fail", no_argument, 0, 'f' },
51 { "help", no_argument, 0, 'h' },
52 { "gcc4", no_argument, 0, '4' },
53 { "gcc5", no_argument, 0, '5' },
54 { "glibmm", required_argument, 0, 'g' },
55 { "verbose", no_argument, 0, 'v' },
56 { "version", no_argument, 0, 'V' },
59 const char *optstring = "fh45g:vV";
62 while ((c = getopt_long (argc, argv, optstring, long_options, NULL)) != -1) {
88 fprintf (stderr, "invalid argument.\n");
98 dlerror (); // reset error
100 void *h = dlopen (glibmm, RTLD_LAZY);
103 fprintf (stderr, "Cannot open '%s': %s.\n", glibmm, dlerror ());
105 return error_fail ? 3 : 0;
108 // Glib::ustring::ustring(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
109 if (dlsym (h, "_ZN4Glib7ustringC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE")) {
113 // Glib::ustring::ustring(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
114 if (dlsym (h, "_ZN4Glib7ustringC1ERKSs")) {
119 // Glib::Module::Module(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Glib::ModuleFlags)
120 if (dlsym (h, "_ZN4Glib6ModuleC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_11ModuleFlagsE")) {
124 // Glib::Module::Module(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Glib::ModuleFlags)
125 if (dlsym (h, "_ZN4Glib6ModuleC1ERKSsNS_11ModuleFlagsE")) {
130 // Glib::ustring::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
131 if (dlsym (h, "_ZN4Glib7ustringaSERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE")) {
135 // Glib::ustring::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
136 if (dlsym (h, "_ZN4Glib7ustringaSERKSs")) {
142 if (7 != (gcc4 ^ gcc5)) {
144 fprintf (stderr, "Inconsistent result: gcc4=%x gcc5=%x\n", gcc4, gcc5);
147 else if (gcc4 == 7) {
149 printf ("System uses gcc4 c++ ABI\n");
152 return (expect & 1) ? 0 : 1;
155 else if (gcc5 == 7) {
157 printf ("System uses gcc5 c++11 ABI\n");
160 return (expect & 2) ? 0 : 1;
164 fprintf (stderr, "Incomplete result: gcc4=%x gcc5=%x\n", gcc4, gcc5);
167 return error_fail ? 2 : 0;