I am trying to compile my C++ code using clang++
but keep getting this error with the conflicting namespace. My main.cpp file is a simple Hello World program (for debugging).
I have a feeling the issue is with my version of GCC or clang that I compiled on my cluster. Any ideas as to how to trace this issue down? Or steps to troubleshoot?
[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)
^
As this is the first result for searches along the lines of:
error: expected unqualified-id before 'namespace'
namespace std _GLIBCXX_VISIBILITY(default)
I'll confess that I got this error by missing a closing-brace in a header file included before the one mentioned in the backtrace.
Hopefully this helps someone.
I had the same issue.
The problem was that I had only the following as 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 sub-directory, specific for the host machine. In my case, this is x86_64-unknown-linux-gnu
. Adding that to CPATH
solved the problem. My new CPATH
is:
<gcc-install-path>/include/c++/<gcc-version>:<gcc-install-path>/include/c++/<gcc-version>/<machine-specific-headers>
For my example machine this translates to:
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 that helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With