gcc static library compilation

227 views Asked by At

i have made a static library using the ar command after an object creation using gcc -o file.o -c file.c.

Now i'm trying to use the gcc to link this library in the compilation with a command similar to this

gcc -I /PathInclude -L /PathStaticLib -lm \
  -std=c99 -o file file.o -lstatic_library_name

with static_library_name i mean that the file is named

libstatic_library_name.a

Since the files structure is quite complex (because basically in the compiling i also substitute some macro definition etc) i don't post all the code, do you have any thought on what is going on? if not what kind of info could i provide to you in order to help me?

PS. there aren't a lot o files, but the internal structure is a bit complicated to explain in few words, so... let me know what do you need.

I can give you the make file content if you need, is not complicated.

PS. The command is...

gcc -I../CModels -L../CModels/ -std=c99 -o ref_approx_bs3_log2_4_4_1ulp_arch1 
 ref_approx_bs3_log2_4_4_1ulp_arch1.o -lm -lmy_float

The error is

ref_approx_bs3_log2_4_4_1ulp_arch1.o: In function `cogen_fp_bs3_log2_4_4_1ulp_arch1':
ref_approx_log2.c:(.text+0x2229): undefined reference to `cast'
ref_approx_log2.c:(.text+0x22d0): undefined reference to `cast'
ref_approx_log2.c:(.text+0x22f7): undefined reference to `cast'
ref_approx_log2.c:(.text+0x232e): undefined reference to `sumFP'
ref_approx_log2.c:(.text+0x2350): undefined reference to `diffFP'
ref_approx_log2.c:(.text+0x2375): undefined reference to `mulFP'
ref_approx_log2.c:(.text+0x239c): undefined reference to `sumFP'
collect2: ld returned 1 exit status

Using

nm my_float.a

the output is

my_float.o:
0000000000000ca8 T _Z11castToFixedyPyyyy
0000000000000a0c T _Z12splitIntFracyPyS_yy
0000000000000324 T _Z28rightShift_and_round2NearestyyPyyy
000000000000005c T _Z3ldzy
0000000000000132 T _Z3mulyyy
000000000000048a T _Z4castyPyyyyy
0000000000000000 T _Z4maxuyy
000000000000002e T _Z4minuyy
00000000000014dc T _Z5mulFPyyPyyy
0000000000000cc2 T _Z5sumFPyyPyyy
000000000000147a T _Z6diffFPyyPyyy
0000000000000300 T _Z9ldzFormatyy
                 U __gxx_personality_v0

So i guess the library .a is ok...

2

There are 2 answers

3
Natasha Dutta On

As per the gcc manual, AFAIR, there should be no space in between -L or -I and the path. Change your command to

 .. -I/PathInclude -L/PathStaticLib ...
0
Robert Jacobs On

Error says that the references to cast, sumFP, diffFP , mulFP are not defined. Need to make sure that they are defined in the library.