我已将我的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
答案 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
必须在列表的最后!