我安装了两个版本的gcc/g++:gcc-4.5(从包管理器安装,二进制文件在/usr/bin下,头文件在/usr/include下)和gcc-4.4.3(自己编译的) , 放在/opt/gcc-4.4.3 下)。
当我将 gcc/g++ 4.4.3 设置为默认版本时(使用“update-alternatives”使/usr/bin/gcc 和/usr/bin/g++ 指向目录“/opt/”下的相应版本gcc-4.4.3/bin") 编译文件,总是报如下错误:
/usr/include/c++/4.5/bits/basic_string.h:1659: undefined reference to `std::basic_string, std::allocator::_S_construct_aux_2(unsigned long, char, std::allocator const&)'
似乎是编译器试图在/usr/include/c++/4.5下寻找c++的头文件,导致链接错误。当我将 gcc 的默认版本更改为 gcc-4.5 时,错误消失了。
那么我怎样才能让编译器在正确的目录“/opt/gcc-4.4.3/include”下搜索头文件呢?我尝试导出 CPLUS_INCLUDE_PATH,但似乎不起作用。
附言:gcc -v
Using build-in specs
Target: x86_64-suse-linux
Configured with: ./configure --prefix=/opt/gcc-4.4.3
Thread model: posix
gcc version 4.4.3 (GCC)
最佳答案
尝试再次编译 gcc 4.4.3,但使用 --with-gxx-include-dir=/opt/gcc-4.4.3/include
配置步骤中的选项。
关于c++ - gcc 在错误的目录下搜索头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14980196/