[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: undefinied symbols on linking
- From: Stephen Irons <stephen.irons@...>
- Date: Wed, 13 Feb 2013 12:20:01 +1300
On 13/02/13 11:24, Philipp Kraus wrote:
I have compiled LUA from the sources under OSX 10.6 and wrap the LUA functions with a C++ class.
On some programs I can use my class without any problems and on some I will get linker errors:
"_lua_atpanic", referenced from:
"_luaL_openlibs", referenced from:
"_luaL_newstate", referenced from:
"_lua_remove", referenced from:
"_lua_close", referenced from:
"_lua_pcallk", referenced from:
"_lua_tolstring", referenced from:
"_luaL_loadstring", referenced from:
I have build the LUA lib with the cppdefine LUA_USE_MACOSX but I can not found a problem on my
code, because I compile the different codes in the same way. I have build only a *.a file (static lib)
Can anybody help me or send me a tip?
This is probably a linker problem, so you will not find the solution by
looking at the code.
Most likely, the libraries to link to the program are specified in the
Some linkers only look for unresolved symbols in subsequent libraries in
the list of libraries. So if you specify libraries in the wrong order
you can get unresolved symbols.
For example, imagine
* main program in main.c which calls function A
* Function A calls function B
* Function A is provided by liba.
* Function B is provided by libb.
If the libraries are presented in the order main.o liba libb, then the
link work correctly. It will load main.o and find that symbol 'A' is
unresolved. It will then look in liba; it finds find symbol 'A', but now
needs symbol 'B'. This is not in main.o or liba. The linker then looks
in libb and find symbol 'B', so the link completes correctly.
But linking in the order main.o libb liba will end up with unresolved
symbol 'B'. This is because the linker first links in main.o, and find
that symbol 'A' is unresolved. The linker then looks in libb. At this
stage, nothing needs its symbol 'B', so the linker discards everything
from this library. The linker then looks at liba; it finds symbol 'A',
loads it, and now needs symbol 'B'. But symbol 'B' is not provided by
main.o or liba, so it remains unresolved. There are no more libraries to
link, so the linker reports the error.
Check that your makefile or linker command line presents the libraries
to the linker in the right order. It can be difficult to find the right
order, especially if you have circular dependencies between libraries.