G ++& Clang ++ - namespace std _GLIBCXX_VISIBILITY(默认)

时间:2013-11-05 19:26:51

标签: c++ gcc namespaces clang++

我正在尝试使用clang++编译我的C ++代码,但是仍然会在冲突的命名空间中出现此错误。我的main.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)
                                          ^

5 个答案:

答案 0 :(得分:8)

因为这是搜索的第一个结果:

error: expected unqualified-id before 'namespace'
namespace std _GLIBCXX_VISIBILITY(default)

我承认我在回溯中提到的一个头文件中遗漏了一个闭括号,从而得到了这个错误。

希望这有助于某人。

答案 1 :(得分:1)

我遇到了同样的问题。

问题是我只有以下CPATH

<gcc-install-path>/include/c++/<gcc-version>

在同一目录中grep _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

我希望能帮助别人。

答案 2 :(得分:0)

我正在使用clang ++ 4.2,它对我有用,很奇怪

clang++ -std=c++11 -Wall -g main.cpp 

如果你摆脱-I / data / apps / gcc / 4.8.1 / include / c ++ / 4.8.1

怎么办?

默认不起作用吗?

答案 3 :(得分:0)

我遇到了同样的问题。

我混合了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中定义

答案 4 :(得分:-1)

为GCC定义函数属性的主题,名称空间传递参数类型,调用协议等等。宏_GLIBCXX_VISIBILITY(默认)是重新定义属性 visibility _ (默认))在Windows中未定义...在Linux中已启用!至于另一个我不知道的OC。您必须将此宏重新定义为空,并在所有包含之前设置它们。所以出现错误。但是很奇怪......如果你设置STL平台,必须进行适当的重新定义!你手动需要它。至于我,我喜欢属性。它们允许控制某些方面不可用的任何编译器和被授予者的正确行为。例如控制参数类型和函数printf中传递的vars数量根据format.And如果你传递不同类型或没有足够数量args错误发生编译错误!没有别的机会给你这样的机会!在Linux上使用属性。这个好主意......