0
votes

Update

after using -ldl and link liblua.a in Project 2(console) the compile is okay, but when it runs it crashed with error Segment fault (core dumped) as soon as it runs a Lua function.


Problem Background:

  • OS: Linux Ubuntu

  • IDE: CodeBlock

  • Launguage: C++

  • 2 project:

    • Project 1: static lib using Lua;

    • Project 2: console application, using the lib generated by Project 1

Problem description

Project 1 (static lib) is built successfully.

The problem is that when building project 2, it says that those Lua functions in the lib from project 1 are undefined, here is part of the error messages:

g++  -o bin/Release/BattleConsoleCB obj/Release/main.o  -s
../BattleConsole/libBattleCore.a
../BattleConsole/libBattleCore.a(DataLoader.o): 
In function `boolDataLoader::GetNumber<double>(char const*, double&) [clone .isra.5]':
DataLoader.cpp:(.text+0x13): undefined reference to `lua_settop'
DataLoader.cpp:(.text+0x1e): undefined reference to `lua_getglobal'
DataLoader.cpp:(.text+0x2b): undefined reference to `lua_isnumber'
DataLoader.cpp:(.text+0x3e): undefined reference to `lua_tonumberx'
DataLoader.cpp:(.text+0x51): undefined reference to `lua_settop'

Note that "DataLoader.cpp" is from project 1, which should have been built in the static lib "libBattleCore.a" which should have been embedded with Lua.

How to solve the problem? Thanks for your help.


Additional information:

  • Project 2 should include: "libBattleCore.h", "main.cpp", libBattleCore.a

  • Project 1 : CodeBlockbuilding options have included "Lua/install/include" in Compile search directory and "Lua/install/lib" in Link search directory

  • The same code is successfully built and run on Win with VS2012

  • If anything else is needed, please inform, I will add it.

  • I am a green hand on linux and g++. :-(

Thank you

1
probably you should need to specify -l parameter to g++ to tell that need to link agains lua library. Codeblocks should have this configuration.NetVipeC
Then what to do ? I've tried included the lua/include and lua/lib in project 2 but still the same error appears. And in light of this, how can I embed lua into a lib?shrekshao
Search in VS2012 in the "Project Properties\Configuration Management\Linker\Additional Libraries", there probably is .lib from lua, if there is, you need to config CodeBlock the same way, meaning specify explicitly to search for that .libNetVipeC
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) no lua...shrekshao
you should probably try with -llua5.1 or the version of lua that you are using. this added to the linker command line in codeblock.NetVipeC

1 Answers

0
votes

I can't comment without 50 rep. There is no support for anonymous replies. So posting here is all I can do.

It's been a few years, but with g++, I thought it was .o files that you listed on the command line and with libraries you used -L to specify the directory to search and then -lname to include the library. (Where name lacked the leading lib and trailing .a.) E.g. -L../BattleConsole -lBattleCore

Oh, and the ordering of -lfoo -lbar vs -lbar -lfoo is critical, determining which library can use code from the other.

It's not clear that a static library will necessary include code from other libraries. You may need to link (in the right order) against the libraries from project1.

Try "nm". As in nm --demangle libBattleCore.a | grep ... This will let you see what precisely is included in each library. man nm or http://linux.die.net/man/1/nm can help you figure out what the letters stand for. For example, U is Undefined (used by not provided). T is defined in the text (code) segment. W and V are weakly-defined. Etc.