Skip to main content
GameDev.net gamedev.net
🔒 Locked

Build shared library problem

Started by Asuralm Feb 26, 2008 at 5:33 AM 4 replies 850+ views
Original Post
Asuralm
Asuralm
Hi all: I have a problem while building a shared library. I declared my function prototype in the header file and wrote the function definition in a cpp file. It compiles without a problem. But when I tried to link to the library, the compiler complains that it can't find the function definition:

undefined reference to ....

It works if I move the function definition to the header file. Is it the only way to make it work? Or is it possible to separate declaration and definition in different file? Are the routines in header compiled? Does it affect the performance? If writing in header file equals to write in cpp file, why do we bother to have another file really? Could someone answer my questions please? Thanks
Asura
TheGilb
TheGilb
Your library will compile into a .lib file. You need to link with this file to resolve those external symbol references.
Asuralm
Asuralm
I am actually using c++ in Linux, I didn't see any lib files but some .a files.
Asura
dave
dave
The principle is still the same. In order to use a library in an executable you need to link the library file in when building the executable.

This may help.
Asuralm
Asuralm
I still can't find it. Really don't know how to solve it. I am using Eclipse-CDT to write C++ program. I think all the libraries should be linked and included correctly, but it just doesn't work.

Anybody know how to link a static library in Eclipse???
Asura
Asuralm
Asuralm
The make file looks like this:

g++ -L"/local/d0p6/ming/Project/C++/mesh_structure/Release" -o"smf2ply"  ./smf2ply.o   -llibmesh_structure


the library file is right in the directory, but the compiler just complains

/usr/lib/gcc/i486-slackware-linux/4.1.2/../../../../i486-slackware-linux/bin/ld: cannot find -llibmesh_structure


Also I tried
g++ -L"/local/d0p6/ming/Project/C++/mesh_structure/Release" -o"smf2ply"  ./smf2ply.o   -llibmesh_structure.a

But this gave me the same error.
Asura

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.