lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

I am hoping someone can explain the issue I have encountered. When building the following lua example I get this linker error:

/sw/lib/odcctools/bin/ld: Undefined symbols:
_luaL_loadbuffer
_luaL_newstate
_lua_gettop
_lua_pcall
_lua_settop
_lua_tolstring
collect2: ld returned 1 exit status

The command line looks like this:
/sw/bin/g++-4 -L/usr/local/lib -llua luatest.cpp

However, when I change this to also link the stdc++ library, it builds fine:
/sw/bin/g++-4 -L/usr/local/lib -lstdc++ -llua luatest.cpp


This is on Mac OS X 10.3.9. I get the same behavior with g++ versions 3.3 and 4.0.2.

More than anything else I am just trying to educate myself a bit. Can anyone explain, or point me to some reading material, about why the stdc++ library needs to be linked as well? The Building Lua wiki page (http://lua-users.org/wiki/BuildingLua) mentions a few other caveats about using Lua with Mac OS X, but I don't see anything that resembles the issue I have encountered.

Thanks much.

P.S.: Here's the code I am compiling as well:

#include <string>
#include <lua.hpp>
//#include <lua.h>
//#include <lualib.h>
//#include <lauxlib.h>

int main(int argc, char** argv)
{
lua_State *L = luaL_newstate();   
char buff[] = "return 1,'a'";
int error;
printf( "%d\n", lua_gettop(L) );
error = luaL_loadbuffer(L, buff, strlen(buff), "my test") || lua_pcall(L, 0, LUA_MULTRET, 0);
if (error) {
fprintf(stderr, "%s", lua_tostring(L, -1));
lua_pop(L, 1); /* pop error message from the stack */
}
printf( "%d\n", lua_gettop(L) );
printf( "%s\n", lua_tostring(L,-2) );
printf( "%s\n", lua_tostring(L,-1) );
}