G++ & Clang++ - namespace std _GLIBCXX_VISIBILITY(默认)
G++ & Clang++ - namespace std _GLIBCXX_VISIBILITY(default)
我正在尝试使用clang++
编译我的C++代码,但不断收到此错误与冲突的命名空间。我的主文件.cpp是一个简单的Hello World程序(用于调试)。
我有一种感觉,问题出在我在集群上编译的 GCC 或 clang 版本上。关于如何追踪这个问题的任何想法?还是故障排除步骤?
[aebrenne@hpc src]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/data/apps/gcc/4.8.1/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --with-gmp=/data/apps/gmp/5.1.2 --with-mpfr=/data/apps/mpfr/3.1.2 --with-mpc=/data/apps/mpc-1.0.1 --enable-threads=posix --with-as=/data/apps/binutils/2.23.2/bin/as --mandir=/data/apps/gcc/4.8.1/man --pdfdir=/data/apps/gcc/4.8.1/pdf --htmldir=/data/apps/gcc/4.8.1/html --enable-languages=c,c++,fortran,ada,go,java,lto,objc,obj-c++ --prefix=/data/apps/gcc/4.8.1
Thread model: posix
gcc version 4.8.1 (GCC)
[aebrenne@hpc src]$ clang++ --version
clang version 3.4 (trunk 193367)
Target: x86_64-unknown-linux-gnu
Thread model: posix
[aebrenne@hpc src]$
[aebrenne@hpc src]$ cat main.cpp
#include <iostream>
int main() {
std::cout << "Starting test..." << std::endl;
return 0;
}
[aebrenne@hpc src]$ clang++ -std=c++11 -Wall -g -I/data/apps/gcc/4.8.1/include/c++/4.8.1 main.cpp
In file included from main.cpp:1:
In file included from /data/apps/gcc/4.8.1/include/c++/4.8.1/iostream:39:
In file included from /data/apps/gcc/4.8.1/include/c++/4.8.1/ostream:38:
In file included from /data/apps/gcc/4.8.1/include/c++/4.8.1/ios:38:
In file included from /data/apps/gcc/4.8.1/include/c++/4.8.1/iosfwd:39:
In file included from /data/apps/gcc/4.8.1/include/c++/4.8.1/bits/stringfwd.h:40:
/data/apps/gcc/4.8.1/include/c++/4.8.1/bits/memoryfwd.h:50:15: error: expected '{'
namespace std _GLIBCXX_VISIBILITY(default)
^
/data/apps/gcc/4.8.1/include/c++/4.8.1/bits/memoryfwd.h:50:15: error: C++ requires a type specifier for all declarations
namespace std _GLIBCXX_VISIBILITY(default)
^~~~~~~~~~~~~~~~~~~
/data/apps/gcc/4.8.1/include/c++/4.8.1/bits/memoryfwd.h:50:35: error: expected expression
namespace std _GLIBCXX_VISIBILITY(default)
^
/data/apps/gcc/4.8.1/include/c++/4.8.1/bits/memoryfwd.h:50:43: error: expected ';' after top level declarator
namespace std _GLIBCXX_VISIBILITY(default)
^
因为这是搜索的第一个结果:
error: expected unqualified-id before 'namespace'
namespace std _GLIBCXX_VISIBILITY(default)
我承认,我之所以出现此错误,是因为在回溯中提到的头文件中缺少一个右大括号。
希望这对某人有所帮助。
我遇到了同样的问题。
问题是我只有以下内容作为CPATH
:
<gcc-install-path>/include/c++/<gcc-version>
在同一目录中grep
ing _GLIBCXX_VISIBILITY
后,宏似乎是在特定于主机的子目录中定义的。就我而言,这x86_64-unknown-linux-gnu
.将其添加到CPATH
解决了问题。我的新CPATH
是:
<gcc-install-path>/include/c++/<gcc-version>:<gcc-install-path>/include/c++/<gcc-version>/<machine-specific-headers>
对于我的示例机器,这转化为:
export CPATH=~/f/i/gcc-4.8.4/include/c++/4.8.4:~/f/i/gcc-4.8.4/include/c++/4.8.4/x86_64-unknown-linux-gnu
我希望这对某人有所帮助。
我正在使用 clang++ 4.2,它对我有用,奇怪
clang++ -std=c++11 -Wall -g main.cpp
如果你只是摆脱了 -I/data/apps/gcc/4.8.1/include/c++/4.8.1
怎么办默认情况下它不起作用吗?
对于 GCC 定义函数的属性主题、命名空间传递的参数类型、调用协议等。宏_GLIBCXX_VISIBILITY(默认)是属性(visibility_(默认))的重新定义,在Windows中未定义...在 Linux 中已开启!至于另一个OC,我不知道。必须将此宏重新定义为空,并在所有包含之前设置它们。等等,发生错误。但很奇怪...如果设置面向 STL 平台,则必须进行适当的重新定义!!您需要手动使用它。至于我,我喜欢属性。它们允许控制任何编译器和受让人正确行为都不可用的某些方面。例如,根据格式在函数 printf 中传递的变量类型和变量数。如果您传递了不同类型的或没有足够的数字参数错误,则错误将作为编译错误发生!!没有别的能给人这样的机会!!在 Linux 上使用属性。这是个好主意...
我遇到了同样的问题。
我混淆了 gcc 4.8 标头和系统标头(较低版本,gcc 4.4.6,_GLIBCXX_VISIBILITY未定义)。
用:
clang++ -std=c++11 -Wall -g -I/data/apps/gcc/4.8.1/include/c++/4.8.1 main.cpp -v -H
以查看所有"包含"详细信息。
就我而言:
. /include/c++/4.8.2/iostream
.. /usr/lib64/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/x86_64-redhat-linux/bits/c++config.h
... /include/bits/wordsize.h
... /usr/lib64/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/x86_64-redhat-linux/bits/os_defines.h
.... /include/features.h
..... /include/stdc-predef.h
..... /include/sys/cdefs.h
...... /include/bits/wordsize.h
..... /include/gnu/stubs.h
...... /include/gnu/stubs-64.h
... /usr/lib64/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/x86_64-redhat-linux/bits/cpu_defines.h
.. /include/c++/4.8.2/ostream
... /include/c++/4.8.2/ios
.... /include/c++/4.8.2/iosfwd
..... /include/c++/4.8.2/bits/stringfwd.h
...... /include/c++/4.8.2/bits/memoryfwd.h
In file included from test.cpp:1:
In file included from /include/c++/4.8.2/iostream:39:
In file included from /include/c++/4.8.2/ostream:38:
In file included from /include/c++/4.8.2/ios:38:
In file included from /include/c++/4.8.2/iosfwd:39:
In file included from /include/c++/4.8.2/bits/stringfwd.h:40:
/include/c++/4.8.2/bits/memoryfwd.h:50:15: error: expected '{'
namespace std _GLIBCXX_VISIBILITY(default)
修复了这个:
clang++ -std=c++11 -isystem /include/c++/4.8.2/ -isystem /include/c++/4.8.2/x86_64-baidu-linux-gnu/ test.cpp -v -H
为此,_GLIBCXX_VISIBILITY在/include/c++/4.8.2/x86_64-baidu-linux-gnu/bits/c++_config.h 中定义
- glibcxx STL 在实现 std::valarray::sum() 时是否不正确?
- 如何将要求降级到动态库的 glibcxx 3.4.20?
- 使用稍旧版本的 GLIBCXX
- AWS 上的 GLIBCXX 版本错误
- 特定CXXABI和GLIBCXX版本的交叉编译
- 将 Ubuntu 交叉编译到 Centos GLIBCXX 的错误
- GLIBCXX(libstdc++.so.6)与gcc版本之间的关系
- 如何在C++中伪造"visibility of class"(不是功能)?
- C++ [[gnu::visibility( "default" )]] vs __declspec(dllexport) on Windows 和 Linux
- Glibcxx 编译 FREAK OpenCV 演示文件时出错
- 运行在同一台计算机上编译的程序时,GLIBCXX版本错误
- libstdc++ GLIBCXX版本错误
- 指定O2标志时,gcc链接到错误的GLIBCXX版本