Alaa M. Alaa M. - 1 year ago 116
C Question

unresolvable symbol 'name' referenced in expression

I have a function defined in a

file (say funcs.c):

void *funName()

and compiled to a library (

And I'm compiling another
file (main.c) which uses this function, and I'm setting symbol names in command line:

gcc -Wl,--just-symbols=symbolsfile.txt main.c -o main -lname


FunSym = funName;

Symbol2 = expression2;


but I'm getting this linking error:

symbolsfile.txt:1: unresolvable symbol 'funName' referenced in expression

symbolsfile.txt:2: unresolvable symbol 'expression2' referenced in expression

collect2.exe: error: ld returned 1 exit status

I tried adding a function declaration in funcs.c (I don't have a corresponding
file), but it didn't change a thing.

If I change
FunSym = funName
FunSym = garbage
, the error changes to "undefined symbol...", so I guess the expression
is found.


I tried adding
extern void *funName();
at the top of main.c or in a separate header file as suggested in the comments, but it didn't resolve the problem (same error). Is the flag
needed to be added in compiling
or in compiling/linking the library (

Answer Source

Move the flag --just-symbols from compiling main.c to linking the library. So compile the library like this:

gcc -g -Wl,--just-symbols=symbolsfile.txt -shared -o *.o

and main.c like this:

gcc main.c -o main -lname
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download