使用glibc 2.7进行编译包括路径失败

时间:2018-03-06 22:41:56

标签: c++ linux compilation glibc

我已将我的SLES 12.3 g++ 7.3编译到/FaF目录中 glibc 2.27安装在/FaF/glibc目录中。

g++ -c testAbs.cpp -I /FaF/glibc/include编译这个非常简单的程序失败了:

#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。下面我插入了前15行 - 总共有超过300行错误消息。

使用g++ -c testAbs.cpp进行编译可以正常工作。在这种情况下,它使用的是系统glibc 2.22 include files

我发现它必须以某种方式与g++ 7.3安装有关。使用系统g++ 4.8.5可以正常编译,如/usr/bin/g++-4.8 -c testAbs.cpp -I /FaF/glibc/include

使用g++ 7.3包含目录的路径glibc 2.27使用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; ^~~~~ 编译它有什么可怕的错误?

我搞砸了什么?

onChange

1 个答案:

答案 0 :(得分:2)

问题中的示例是我的包含文件的最小化版本。这些都是项目中需要的包含文件:

#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>

首先,它无法按此顺序编译,因为问题中描述的错误,我无法使用cmath包含。

我可以使用这些g++开关修复它:

-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 -帮助我弄清楚需要哪些包含路径。

订单重要

-I /usr/include必须在列表的最后!