LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   linking problems (https://www.linuxquestions.org/questions/programming-9/linking-problems-365814/)

wmoti 09-22-2005 02:03 AM

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.

addy86 09-22-2005 02:23 AM

You forgot to tell gcc to link with the library. What commands do you enter to compile and link?

wmoti 09-22-2005 03:41 AM

gcc -o test.exe $(OBJ) $(LIBS)
and LIBS = -L. lib1.a lib2.a .......

bigearsbilly 09-22-2005 04:09 AM

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

wmoti 09-22-2005 04:59 AM

ok I did what you have told me , but nothing ,
still get the error : undefined reference to 'func name'..

bigearsbilly 09-22-2005 05:35 AM

need more info.

wmoti 09-22-2005 06:12 AM

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

bigearsbilly 09-22-2005 06:52 AM

in Makefile


LDFLAGS = -L /lib/directory

LDLIBS = -lname1

post the error message

wmoti 09-22-2005 07:07 AM

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

wmoti 09-22-2005 07:14 AM

I also checked inside the lib :
nm -g libname.a
and these undefined referened functions are there.

bigearsbilly 09-22-2005 07:15 AM

post the make output.

wmoti 09-24-2005 11:30 PM

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.