Skip to content
Advertisement

Compilation with glibc 2.7 include path fails

I have compiled on my SLES 12.3 g++ 7.3 into the /FaF directory and glibc 2.27 is installed into the /FaF/glibc directory.

Compiling this very simple program with g++ -c testAbs.cpp -I /FaF/glibc/include fails horribly:

#include <cstdlib>
#include <cmath>
int main( int argc, char * argv [] )
{
    if ( argc != 2 )
    {
        return 1;
    }
    return std::abs(std::atoi(argv[1]));
}

See the long error list. Below I inserted the first 15 lines – in total there are more than 300 lines of error messages.

Compiling it with g++ -c testAbs.cpp works fine. In this case it is using the system glibc 2.22 include files.

I found out that it must somehow relate to the g++ 7.3 installation. Using the system g++ 4.8.5 works fine compiled like this /usr/bin/g++-4.8 -c testAbs.cpp -I /FaF/glibc/include

What is going so horrible wrong compiling it with g++ 7.3 using the path to the glibc 2.27 include directories?

What am I messing up?

In file included from /usr/include/math.h:48:0,
                 from /FaF/include/c++/7.3/cmath:45,
                 from testAbs.cpp:11:
/FaF/glibc/include/bits/mathdef.h:19:3: error: #error "Never use <bits/mathdef.h> directly; include <complex.h> instead"
 # error "Never use <bits/mathdef.h> directly; include <complex.h> instead"
   ^~~~~
In file included from /FaF/include/c++/7.3/cstdlib:75:0,
                 from testAbs.cpp:10:
/usr/include/stdlib.h:95:1: error: ‘__BEGIN_NAMESPACE_STD’ does not name a type; did you mean ‘__BEGIN_DECLS’?
 __BEGIN_NAMESPACE_STD
 ^~~~~~~~~~~~~~~~~~~~~
 __BEGIN_DECLS
/usr/include/stdlib.h:101:5: error: ‘div_t’ does not name a type; did you mean ‘size_t’?
   } div_t;
     ^~~~~

Advertisement

Answer

The example in the question was a minimized version of my include file. These are all include files which are needed in the project:

#include <algorithm>
#include <atomic>
#include <chrono>
#include <cmath>
#include <condition_variable>
#include <cstdlib>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <mutex>
#include <regex>
#include <set>
#include <string>
#include <thread>
#include <vector>
#include <execinfo.h>
#include <gnu/libc-version.h>
#include <libgen.h>
#include <locale.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/poll.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/sysinfo.h>
#include <unistd.h>
#include <mysql/my_global.h>
#include <mysql/mysql.h>

First, it could not be compiled in this order and I could not use the cmath include – due to the described error in the question.

I could fix it using these g++ switches:

-nostdinc
-I /FaF/curl/include
-I /usr/include/mysql
-I /FaF/lib64/gcc/x86_64-suse-linux/7.3.0/include-fixed
-I /FaF/include/c++/7.3
-I /FaF/include/c++/7.3/x86_64-suse-linux/
-I /FaF/lib64/gcc/x86_64-suse-linux/7.3.0/include
-I /FaF/glibc/include/
-I /usr/include

g++ -xc++ -E -v - helped me to figure out which include paths are needed.

THE ORDER DOES MATTER

-I /usr/include must be last in the list!

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement