简体   繁体   中英

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

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.

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

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

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

Doesn't it work by default?

for GCC define subject of attribute for function, namespaces passed arguments types, call protocol and so no. Macros _GLIBCXX_VISIBILITY(default) is redefinition of attribute ( visibility_ (default)) In Windows is not defined... in Linux is on! As to another OC I don't know. You must redefine this macros as empty and set them before all includes. So on error occurs. But it's strange... If you setup STL platform oriented the appropriate redefinition must be!!! You need it to manually. As to me I like attributes. They allow control some aspects not available any compiler and grantee correct behavior. For example control arguments type and number of vars passed in function printf according to format.And if you passed different type or not enough number args error occurs as a compile error!!! Nothing else gives such an opportunity!!! Use attributes on Linux. It's good an idea...

I hit the same issue.

I mix up gcc 4.8 headers and system headers(lower version,gcc 4.4.6, _GLIBCXX_VISIBILITY not defined).

use:

clang++ -std=c++11 -Wall -g -I/data/apps/gcc/4.8.1/include/c++/4.8.1  main.cpp -v -H

to see all the "include" details.

In my case:

. /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)

Fixed with this:

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

For that _GLIBCXX_VISIBILITY is defined in /include/c++/4.8.2/x86_64-baidu-linux-gnu/bits/c++_config.h

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM