• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Compiling [Linux] "undefined reference" after 100%

Sequax

Member
Joined
Oct 24, 2008
Messages
19
Reaction score
9
Hello!

Trying to compile Nostalrius 7.7

Can anyone give me some pointers? I've tried to search function and find other people with similar problems, but I can't seem to find any soltion for this. Any help would be appreciated!

Here's my stuff:

OS:
Bash:
Operating System: Debian GNU/Linux 10 (buster)
Kernel: Linux 4.19.0-5-amd64
Architecture: x86-64


Essential stuff:
Code:
libboost-iostreams-dev is already the newest version (1.67.0.1).
libboost-system-dev is already the newest version (1.67.0.1).
build-essential is already the newest version (12.6).
cmake is already the newest version (3.13.4-1).
git is already the newest version (1:2.20.1-2).
libgmp3-dev is already the newest version (2:6.1.2+dfsg-4).
libcrypto++-dev is already the newest version (5.6.4-8).
liblua5.2-dev is already the newest version (5.2.4-1.1+b2).
libmariadbclient-dev is already the newest version (1:10.3.15-1).
libpugixml-dev is already the newest version (1.9-3).


The error:
Code:
[100%] Linking CXX executable tfs
/usr/bin/ld: CMakeFiles/tfs.dir/src/combat.cpp.o: in function `ValueCallback::getMinMaxValues(Player*, CombatDamage&, bool) const':
combat.cpp:(.text+0x4bb9): undefined reference to `lua_pcallk'
/usr/bin/ld: CMakeFiles/tfs.dir/src/combat.cpp.o: in function `TargetCallback::onTargetCombat(Creature*, Creature*) const':
combat.cpp:(.text+0x4fdd): undefined reference to `lua_pcallk'
/usr/bin/ld: CMakeFiles/tfs.dir/src/configmanager.cpp.o: in function `ConfigManager::load()':
configmanager.cpp:(.text+0xa5): undefined reference to `lua_pcallk'
/usr/bin/ld: CMakeFiles/tfs.dir/src/configmanager.cpp.o: in function `ConfigManager::getGlobalString[abi:cxx11](lua_State*, char const*, char const*)':
configmanager.cpp:(.text+0x1034): undefined reference to `lua_getglobal'
/usr/bin/ld: configmanager.cpp:(.text+0x1093): undefined reference to `lua_rawlen'
/usr/bin/ld: CMakeFiles/tfs.dir/src/configmanager.cpp.o: in function `ConfigManager::getGlobalNumber(lua_State*, char const*, int)':
configmanager.cpp:(.text+0x118e): undefined reference to `lua_getglobal'
/usr/bin/ld: CMakeFiles/tfs.dir/src/configmanager.cpp.o: in function `ConfigManager::getGlobalBoolean(lua_State*, char const*, bool)':
configmanager.cpp:(.text+0x1209): undefined reference to `lua_getglobal'
/usr/bin/ld: configmanager.cpp:(.text+0x125c): undefined reference to `lua_rawlen'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::protectedCall(lua_State*, int, int)':
luascript.cpp:(.text+0xfa6): undefined reference to `lua_pcallk'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::getEvent(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
luascript.cpp:(.text+0x11ec): undefined reference to `lua_getglobal'
/usr/bin/ld: luascript.cpp:(.text+0x129f): undefined reference to `lua_setglobal'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::getMetaEvent(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
luascript.cpp:(.text+0x140c): undefined reference to `lua_getglobal'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::getStackTrace(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
luascript.cpp:(.text+0x17ef): undefined reference to `lua_getglobal'
/usr/bin/ld: luascript.cpp:(.text+0x18eb): undefined reference to `lua_callk'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::registerFunctions()':
luascript.cpp:(.text+0x41d8): undefined reference to `lua_setglobal'
/usr/bin/ld: luascript.cpp:(.text+0x4211): undefined reference to `lua_setglobal'
/usr/bin/ld: luascript.cpp:(.text+0x424a): undefined reference to `lua_setglobal'
/usr/bin/ld: luascript.cpp:(.text+0x4283): undefined reference to `lua_setglobal'
/usr/bin/ld: luascript.cpp:(.text+0x42bc): undefined reference to `lua_setglobal'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o:luascript.cpp:(.text+0x42f5): more undefined references to `lua_setglobal' follow
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::registerClass(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int ([I])(lua_State[/I]))':
luascript.cpp:(.text+0x48836): undefined reference to `lua_getglobal'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::registerTable(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
luascript.cpp:(.text+0x48bea): undefined reference to `lua_setglobal'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::registerMethod(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int ([I])(lua_State[/I]))':
luascript.cpp:(.text+0x48c28): undefined reference to `lua_getglobal'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::registerGlobalMethod(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int ([I])(lua_State[/I]))':
luascript.cpp:(.text+0x48d66): undefined reference to `lua_setglobal'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::registerVariable(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double)':
luascript.cpp:(.text+0x48da5): undefined reference to `lua_getglobal'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::registerGlobalVariable(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double)':
luascript.cpp:(.text+0x48e30): undefined reference to `lua_setglobal'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::registerGlobalBoolean(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)':
luascript.cpp:(.text+0x48e81): undefined reference to `lua_setglobal'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::luaIsInArray(lua_State*)':
luascript.cpp:(.text+0x4ca0a): undefined reference to `lua_compare'
/usr/bin/ld: CMakeFiles/tfs.dir/src/luascript.cpp.o: in function `LuaScriptInterface::luaAddEvent(lua_State*)':
luascript.cpp:(.text+0x4d158): undefined reference to `lua_getglobal'
/usr/bin/ld: luascript.cpp:(.text+0x4d185): undefined reference to `lua_getglobal'
/usr/bin/ld: luascript.cpp:(.text+0x4d1e6): undefined reference to `lua_callk'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/tfs.dir/build.make:1161: tfs] Error 1
make[1]: *** [CMakeFiles/Makefile2:105: CMakeFiles/tfs.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Warnings during the build (I've removed -Werror in CMakeLists.txt)

12%
Code:
[ 12%] Building CXX object CMakeFiles/tfs.dir/src/behaviourdatabase.cpp.o
/home/makarys/Nostalrius/src/behaviourdatabase.cpp: In member function ‘int32_t BehaviourDatabase::searchDigit(const string&)’:
/home/makarys/Nostalrius/src/behaviourdatabase.cpp:1150:14: warning: catching polymorphic type ‘class std::invalid_argument’ by value [-Wcatch-value=]
  catch (std::invalid_argument) {
             
/home/makarys/Nostalrius/src/behaviourdatabase.cpp:1153:14: warning: catching polymorphic type ‘class std::out_of_range’ by value [-Wcatch-value=]
  catch (std::out_of_range) {

15%
Code:
[ 15%] Building CXX object CMakeFiles/tfs.dir/src/combat.cpp.o
/home/makarys/Nostalrius/src/combat.cpp: In static member function ‘static bool Combat::closeAttack(Creature*, Creature*, fightMode_t, bool)’:
/home/makarys/Nostalrius/src/combat.cpp:887:38: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
    if (hit || -totalDamage > defense && (randTest == 5 * (randTest / 5))) {
              
/home/makarys/Nostalrius/src/combat.cpp: In static member function ‘static bool Combat::rangeAttack(Creature*, Creature*, fightMode_t)’:
/home/makarys/Nostalrius/src/combat.cpp:1040:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
   if (rand() % distance <= skillValue) {
      
/home/makarys/Nostalrius/src/combat.cpp: In static member function ‘static bool Combat::canUseWeapon(Player*, Item*)’:
/home/makarys/Nostalrius/src/combat.cpp:1246:72: warning: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int32_t’ {aka ‘int’} [-Wsign-compare]
  if (!player->hasFlag(PlayerFlag_HasInfiniteMana) && player->getMana() < weapon->getManaConsumption()) {

67%
Code:
[ 67%] Building CXX object CMakeFiles/tfs.dir/src/player.cpp.o
/home/makarys/Nostalrius/src/player.cpp: In member function ‘uint32_t Player::checkPlayerKilling()’:
/home/makarys/Nostalrius/src/player.cpp:2746:14: warning: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int32_t’ {aka ‘int’} [-Wsign-compare]
  if (lastDay >= g_config.getNumber(ConfigManager::KILLS_DAY_BANISHMENT) ||
     
/home/makarys/Nostalrius/src/player.cpp:2747:12: warning: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int32_t’ {aka ‘int’} [-Wsign-compare]
   lastWeek >= g_config.getNumber(ConfigManager::KILLS_WEEK_BANISHMENT) ||
  
/home/makarys/Nostalrius/src/player.cpp:2748:13: warning: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int32_t’ {aka ‘int’} [-Wsign-compare]
   lastMonth >= g_config.getNumber(ConfigManager::KILLS_MONTH_BANISHMENT)) {
  
/home/makarys/Nostalrius/src/player.cpp:2752:14: warning: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int32_t’ {aka ‘int’} [-Wsign-compare]
  if (lastDay >= g_config.getNumber(ConfigManager::KILLS_DAY_RED_SKULL) ||
     
/home/makarys/Nostalrius/src/player.cpp:2753:12: warning: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int32_t’ {aka ‘int’} [-Wsign-compare]
   lastWeek >= g_config.getNumber(ConfigManager::KILLS_WEEK_RED_SKULL) ||
  
/home/makarys/Nostalrius/src/player.cpp:2754:13: warning: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘int32_t’ {aka ‘int’} [-Wsign-compare]
   lastMonth >= g_config.getNumber(ConfigManager::KILLS_MONTH_RED_SKULL)) {

71%
Code:
[ 71%] Building CXX object CMakeFiles/tfs.dir/src/protocolgame.cpp.o
/home/makarys/Nostalrius/src/protocolgame.cpp: In member function ‘void ProtocolGame::AddCreature(NetworkMessage&, const Creature*, bool, uint32_t)’:
/home/makarys/Nostalrius/src/protocolgame.cpp:1789:47: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
  if (!creature->isInvisible() || !otherPlayer && player->canSeeInvisibility()) {


Inside build.make. Row #1161
Code:
1161    $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/tfs.dir/link.txt --verbose=$(VERBOSE)


Inside link.txt (these were not separate rows I edited it for clarity)
Code:
/usr/bin/c++    -rdynamic
CMakeFiles/tfs.dir/src/otpch.cpp.o
CMakeFiles/tfs.dir/src/actions.cpp.o
CMakeFiles/tfs.dir/src/ban.cpp.o
CMakeFiles/tfs.dir/src/baseevents.cpp.o
CMakeFiles/tfs.dir/src/bed.cpp.o
CMakeFiles/tfs.dir/src/behaviourdatabase.cpp.o
CMakeFiles/tfs.dir/src/chat.cpp.o
CMakeFiles/tfs.dir/src/combat.cpp.o
CMakeFiles/tfs.dir/src/commands.cpp.o
CMakeFiles/tfs.dir/src/condition.cpp.o
CMakeFiles/tfs.dir/src/configmanager.cpp.o
CMakeFiles/tfs.dir/src/connection.cpp.o
CMakeFiles/tfs.dir/src/container.cpp.o
CMakeFiles/tfs.dir/src/creature.cpp.o
CMakeFiles/tfs.dir/src/creatureevent.cpp.o
CMakeFiles/tfs.dir/src/cylinder.cpp.o
CMakeFiles/tfs.dir/src/database.cpp.o
CMakeFiles/tfs.dir/src/databasemanager.cpp.o
CMakeFiles/tfs.dir/src/databasetasks.cpp.o
CMakeFiles/tfs.dir/src/depotlocker.cpp.o
CMakeFiles/tfs.dir/src/fileloader.cpp.o
CMakeFiles/tfs.dir/src/game.cpp.o
CMakeFiles/tfs.dir/src/globalevent.cpp.o
CMakeFiles/tfs.dir/src/guild.cpp.o
CMakeFiles/tfs.dir/src/groups.cpp.o
CMakeFiles/tfs.dir/src/house.cpp.o
CMakeFiles/tfs.dir/src/housetile.cpp.o
CMakeFiles/tfs.dir/src/ioguild.cpp.o
CMakeFiles/tfs.dir/src/iologindata.cpp.o
CMakeFiles/tfs.dir/src/iomap.cpp.o
CMakeFiles/tfs.dir/src/iomapserialize.cpp.o
CMakeFiles/tfs.dir/src/item.cpp.o
CMakeFiles/tfs.dir/src/items.cpp.o
CMakeFiles/tfs.dir/src/luascript.cpp.o
CMakeFiles/tfs.dir/src/mailbox.cpp.o
CMakeFiles/tfs.dir/src/map.cpp.o
CMakeFiles/tfs.dir/src/monster.cpp.o
CMakeFiles/tfs.dir/src/monsters.cpp.o
CMakeFiles/tfs.dir/src/movement.cpp.o
CMakeFiles/tfs.dir/src/networkmessage.cpp.o
CMakeFiles/tfs.dir/src/npc.cpp.o
CMakeFiles/tfs.dir/src/otserv.cpp.o
CMakeFiles/tfs.dir/src/outputmessage.cpp.o
CMakeFiles/tfs.dir/src/party.cpp.o
CMakeFiles/tfs.dir/src/player.cpp.o
CMakeFiles/tfs.dir/src/position.cpp.o
CMakeFiles/tfs.dir/src/protocol.cpp.o
CMakeFiles/tfs.dir/src/protocolgame.cpp.o
CMakeFiles/tfs.dir/src/protocollogin.cpp.o
CMakeFiles/tfs.dir/src/protocolstatus.cpp.o
CMakeFiles/tfs.dir/src/raids.cpp.o
CMakeFiles/tfs.dir/src/rsa.cpp.o
CMakeFiles/tfs.dir/src/scheduler.cpp.o
CMakeFiles/tfs.dir/src/scriptmanager.cpp.o
CMakeFiles/tfs.dir/src/server.cpp.o
CMakeFiles/tfs.dir/src/spawn.cpp.o
CMakeFiles/tfs.dir/src/spells.cpp.o
CMakeFiles/tfs.dir/src/script.cpp.o
CMakeFiles/tfs.dir/src/talkaction.cpp.o
CMakeFiles/tfs.dir/src/tasks.cpp.o
CMakeFiles/tfs.dir/src/teleport.cpp.o
CMakeFiles/tfs.dir/src/thing.cpp.o
CMakeFiles/tfs.dir/src/tile.cpp.o
CMakeFiles/tfs.dir/src/tools.cpp.o
CMakeFiles/tfs.dir/src/vocation.cpp.o
CMakeFiles/tfs.dir/src/waitlist.cpp.o
CMakeFiles/tfs.dir/src/wildcardtree.cpp.o  -o tfs -lmysqlclient -lluajit-5.1 -lm -lboost_system -lboost_filesystem -lboost_filesystem -lpugixml -lgmp -lpthread
 
Solution
Hello,
undefined reference is a linker issue that means the library files weren't loaded correctly.
And in your case, it means that "lua5.1.so" isn't linked.

Please refer to this thread for more information:

Whenever you face an issue, please use the search function before posting a new thread, it would be a common issue!

Sincerely,
Slavi
Hello,
undefined reference is a linker issue that means the library files weren't loaded correctly.
And in your case, it means that "lua5.1.so" isn't linked.

Please refer to this thread for more information:

Whenever you face an issue, please use the search function before posting a new thread, it would be a common issue!

Sincerely,
Slavi
 
Last edited:
Solution
Thank you!

Your mention of lua5.1 really got me in the right direction.

Solution:

Got inspired by this thread

I noticed that LuaJIT was NOT found in the cmake process, so I went in the "FindLuaJIT.cmake" and noticed that the path was to /usr/include/luajit-2.0 while mine was in 2.1. So I just change from 2.0 to 2.1 in the cmake file. I also installed lua5.1 while I had lua5.2 installed, not sure if it made a difference.
 
Thank you!

Your mention of lua5.1 really got me in the right direction.

Solution:

Got inspired by this thread

I noticed that LuaJIT was NOT found in the cmake process, so I went in the "FindLuaJIT.cmake" and noticed that the path was to /usr/include/luajit-2.0 while mine was in 2.1. So I just change from 2.0 to 2.1 in the cmake file. I also installed lua5.1 while I had lua5.2 installed, not sure if it made a difference.
I have some problem and my luajit was in 2.1 as well, i change on FindLuaJIT.cmake to my version and its works
Thanks man.
 
Back
Top