Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7957 Discussions

undefined references with -fvisibility=hidden

filipe_gr_sousa
Beginner
719 Views
I have the following code in foo.h

void __attribute__ ((visibility("default"))) foo();

and in foo.c

#include "foo.h"
#include stdio.h

void foo()
{
printf("foo()");
}

When I try to compile this with icc it fails:

icc -fvisibility=hidden -fpic -o foo.o -c foo.c
icc -fpic -shared -o libfoo foo.o
foo.o: In function `foo':
foo.c:(.text+0x18): undefined reference to `printf'
ld: libfoo: hidden symbol `printf' isn't defined
ld: final link failed: Nonrepresentable section on output

The same code with gcc compiles fine:

cc -fvisibility=hidden -fpic -o foo.o -c foo.c
cc -fpic -shared -o libfoo foo.o

Compiler versions:
gcc (GCC) 3.4.4 (Gentoo 3.4.4, ssp-3.4.4-1.0, pie-8.7.8)
Intel C Compiler for 32-bit applications, Version 9.0 Build 20050722Z Package ID:
0 Kudos
2 Replies
Maximillia_D_Intel
719 Views
Hi,
Can you submit a premier support issue? If gcc compiles the code and runs fine, this is potentially a gcc compatibility issue for icc.
Max
0 Kudos
John_O_Intel
Employee
719 Views

Hi,

This has been corrected in the Intel Compiler package 9.1.045 now available for download.

# fails with 9.1.044 or earlier:

$ /opt/spdtools/compiler/ia32/cc-9.1.044/bin/icpc -fvisibility=hidden -fpic -o foo.o -c foo.c
$ /opt/spdtools/compiler/ia32/cc-9.1.044/bin/icpc -fpic -shared -o libfoo foo.o
foo.o(.text+0x1b): In function `foo()':
: undefined reference to `printf'
ld: libfoo: hidden symbol `printf' isn't defined

# works with 9.1.045

$ /opt/spdtools/compiler/ia32/cc-9.1.045/bin/icpc -fvisibility=hidden -fpic -o foo.o -c foo.c
$ /opt/spdtools/compiler/ia32/cc-9.1.045/bin/icpc -fpic -shared -o libfoo foo.o

If you are intersted in -fvisibility, we have anicewhite paper on Linux symbol preemption & performance implications / speedup possibilitiesat http://www3.intel.com/cd/ids/developer/asmo-na/eng/dc/tools/compilers/198900.htm

best regards,

_|ohnO

0 Kudos
Reply