Insoluble name "name" specified in the expression

I have a function defined in a .c file (say funcs.c ):

 void *funName() { //implementation } 

and compiled into a library ( libname.so ).

And I compile another .c file ( main.c ) that uses this function, and I set the character names on the command line:

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

symbolsfile.txt

FunSym = funName,
Symbol2 = expression2;
...

but I get this communication error:

symbolfile.txt: 1: unsolvable character 'funName' specified in expression
symbolfile.txt: 2: unsolvable symbol 'expression2' specified in the expression
collect2.exe: error: ld returned 1 exit status

I tried adding a function declaration to funcs.c (I don't have a corresponding .h file), but that didn't change anything.

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

Update:

I tried adding extern void *funName(); at the top of main.c or in a separate header file, as suggested in the comments, but this did not solve the problem (same error). Do I need to add the --just-symbols flag when compiling main.c or when compiling / linking the library ( libname.so )?

+5
source share
1 answer

Move the --just-symbols flag from compiling main.c to the library link. So, compile the library as follows:

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

and main.c as follows:

 gcc main.c -o main -lname 
+1
source

All Articles