linking problems
Hi ,
I created a lib.a from several c files. now I write a test. c case which suppose to call some functions from the lib.a. the compilation succedded but the linking not. I get : undefined reference to 'function name' ..... but I have a '.h' file which has the prototypes to these functions and it is included in the test.c file. please tell me what do I do wrong. |
You forgot to tell gcc to link with the library. What commands do you enter to compile and link?
|
gcc -o test.exe $(OBJ) $(LIBS)
and LIBS = -L. lib1.a lib2.a ....... |
lib.a is not a good name.
a lib must be named: libname e.g to link a library called libwmoti gcc prog.o -lwmoti the linker implictly looks for a library named libwmoti |
ok I did what you have told me , but nothing ,
still get the error : undefined reference to 'func name'.. |
need more info.
|
ok ,
I build some libs ( libname1.a.... )with 'ar.....' after that I wrote a test.cpp file to check these libs. and the compilation is ok but linking not. I get some errors of : undefined reference to '.....' in the makefile of test I have LIBS = -lname .... and also IFLAGS = -Iincludefiles.h |
in Makefile
LDFLAGS = -L /lib/directory LDLIBS = -lname1 post the error message |
alraedy done this ,
p.s. the libs , code and exe are in the same folder just to make it simple. the develop machine isnot connected to the net , so I'ii try to copy the msg : In function 'aaa()' file :file_from_libname1.cpp:54 :undefined reference to 'Funcionname from lib' regards, Moti |
I also checked inside the lib :
nm -g libname.a and these undefined referened functions are there. |
post the make output.
|
In Function 'JpgFile::JpgStartCompress(int, int ,int )':
JpgFile.cpp:94: undefined reference to 'jpeg_destroy_compress' . . . and many lines like this one |
All times are GMT -5. The time now is 04:44 PM. |