G ++ & Clang ++ - namespace std _GLIBCXX_VISIBILITY (default)

I am trying to compile my C ++ code using clang++ , but keep getting this error with a conflicting namespace. My main.cpp file is a simple Hello World program (for debugging).

I feel like the problem is with my version of GCC or clang, which I compiled in my cluster. Any ideas on how to trace this issue? Or troubleshooting steps?

 [ 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) ^ 
+7
c ++ gcc namespaces clang ++
source share
4 answers

Since this is the first result for a row search:

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

I admit that I got this error without seeing the closing bracket in the header file included before it is mentioned in the backtrace.

Hope this helps someone.

+7
source share

I had the same problem.

The problem was this: CPATH :

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

After grep ing for _GLIBCXX_VISIBILITY in the same directory, it seems that the macro is defined in a subdirectory specific to the host machine. In my case, this is x86_64-unknown-linux-gnu . Adding this parameter to CPATH solved the problem. My new CPATH :

 <gcc-install-path>/include/c++/<gcc-version>:<gcc-install-path>/include/c++/<gcc-version>/<machine-specific-headers> 

For my example, a machine means:

 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 

I hope this helps someone.

+1
source share

I am using clang ++ 4.2 and it worked for me, weird

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

What if you just get rid of -I / data / apps / gcc / 4.8.1 / include / C ++ / 4.8.1

Does it work by default?

0
source share

for GCC, they define an attribute object for a function, namespaces pass argument types, a call protocol, and so on. Macros _GLIBCXX_VIBIBILITY (default) - attribute override (visibility_ (default)). Not defined on Windows ... enabled on Linux! As for the other OK, I do not know. You must redefine these macros as empty and set them before everything is turned on. So an error occurs. But this is strange ... If you have configured the STL platform, then there must be a corresponding redefinition !!! You need it manually. As for me, I like the attributes. They allow you to control some aspects inaccessible to any compiler and the correct recipient behavior. For example, arguments to control arguments and the number of vars passed to the printf function according to the format. And if you passed another type or not enough arguments, the error occurs as a compilation error !!! Nothing else gives such an opportunity !!! Use attributes on Linux. This is a good idea ...

-one
source share

All Articles