ld:对“lua_”的未定义引用。我不知道为什么 ld 不能引用 lua,即使它在那里

ld: undefined reference to `lua_`. I don't know why ld cannot reference lua even though its there

我正在尝试从这个 git-repo for a university project and I'm stuck because ld does not seem to be able to link lua properly. I followed the install instructions 安装代码并使用以下代码编译代码:

catkin_make -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=/usr/bin/python3 -DCMAKE_CXX_STANDARD=14 

失败并显示几条消息,例如:

/usr/bin/ld: /home/felixk/catkin_ws/devel/lib/libflatland_lib.so: undefined reference to `lua_toboolean(lua_State*, int)'
/usr/bin/ld: /home/felixk/catkin_ws/devel/lib/libflatland_lib.so: undefined reference to `lua_tonumberx(lua_State*, int, int*)'
...
/usr/bin/ld: /home/felixk/catkin_ws/devel/lib/libflatland_lib.so: undefined reference to `lua_pushstring(lua_State*, char const*)'
/usr/bin/ld: /home/felixk/catkin_ws/devel/lib/libflatland_lib.so: undefined reference to `lua_isstring(lua_State*, int)'
collect2: error: ld returned 1 exit status

代码已经过测试并可在 Ubuntu 18.04 上运行,但我正试图让它在 Manjaro 上运行。手册指出 liblua5.2-dev 是必需的,我从 AUR 安装了 lua52,它似乎提供了正确的库。

ldd的输出是:

ldd /home/felixk/catkin_ws/devel/lib/libflatland_lib.so | grep lua
        liblua5.2.so.5.2 => /usr/lib/liblua5.2.so.5.2 (0x00007f23fd51c000)

然后我检查了 /usr/lib/liblua5.2.so.5.2 是否存在并且确实存在。我尝试使用 readelf 检查 liblua5.2.so.5.2 是否包含 undefined references:

readelf -s /usr/lib/liblua5.2.so.5.2                     

Symbol table '.dynsym' contains 245 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __[...]@GLIBC_2.3 (2)
     2: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
     3: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND free@GLIBC_2.2.5 (3)
     4: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND abort@GLIBC_2.2.5 (3)
     5: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
     6: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND ldexp@GLIBC_2.2.5 (4)
     7: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
     8: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterT[...]
     9: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    10: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    11: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __[...]@GLIBC_2.7 (5)
    12: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    13: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND fread@GLIBC_2.2.5 (3)
    14: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  UND stdin@GLIBC_2.2.5 (3)
    15: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    16: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    17: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND atan@GLIBC_2.2.5 (4)
    18: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND pow@GLIBC_2.29 (6)
    19: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND clock@GLIBC_2.2.5 (3)
    20: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    21: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    22: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __[...]@GLIBC_2.4 (7)
    23: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    24: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    25: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    26: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    27: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND modf@GLIBC_2.2.5 (4)
    28: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    29: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    30: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    31: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND close@GLIBC_2.2.5 (3)
    32: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND log@GLIBC_2.29 (6)
    33: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND fmod@GLIBC_2.2.5 (4)
    34: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    35: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND cos@GLIBC_2.2.5 (4)
    36: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    37: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    38: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND acos@GLIBC_2.2.5 (4)
    39: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND srand@GLIBC_2.2.5 (3)
    40: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    41: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND fgets@GLIBC_2.2.5 (3)
    42: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND frexp@GLIBC_2.2.5 (4)
    43: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    44: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    45: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND log10@GLIBC_2.2.5 (4)
    46: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.3.4 (8)
    47: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND feof@GLIBC_2.2.5 (3)
    48: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
    49: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    50: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    51: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND memcpy@GLIBC_2.14 (9)
    52: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    53: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND cosh@GLIBC_2.2.5 (4)
    54: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND time@GLIBC_2.2.5 (3)
    55: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (10)
    56: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND sinh@GLIBC_2.2.5 (4)
    57: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    58: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND tan@GLIBC_2.2.5 (4)
    59: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    60: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    61: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    62: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND atan2@GLIBC_2.2.5 (4)
    63: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    64: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    65: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    66: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (10)
    67: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    68: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    69: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.11 (11)
    71: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    72: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND popen@GLIBC_2.2.5 (3)
    73: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND fopen@GLIBC_2.2.5 (3)
    74: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    75: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND sin@GLIBC_2.2.5 (4)
    76: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND tanh@GLIBC_2.2.5 (4)
    77: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND asin@GLIBC_2.2.5 (4)
    78: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND exit@GLIBC_2.2.5 (3)
    79: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    80: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.3.4 (8)
    81: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMC[...]
    82: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND sqrt@GLIBC_2.2.5 (4)
    83: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    84: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (10)
    85: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    86: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND getc@GLIBC_2.2.5 (3)
    87: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    88: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND exp@GLIBC_2.29 (6)
    89: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND rand@GLIBC_2.2.5 (3)
    90: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (10)
    91: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __[...]@GLIBC_2.3 (2)
    92: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __[...]@GLIBC_2.3 (2)
    93: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  UND [...]@GLIBC_2.2.5 (3)
    94: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND [...]@GLIBC_2.3.4 (8)
    95: 0000000000007680   135 FUNC    GLOBAL DEFAULT    9 lua_arith
    96: 0000000000008640    32 FUNC    GLOBAL DEFAULT    9 lua_getctx
    97: 00000000000085d0    97 FUNC    GLOBAL DEFAULT    9 lua_setuservalue
    98: 0000000000008bd0    24 FUNC    GLOBAL DEFAULT    9 lua_getallocf
    99: 00000000000086f0   273 FUNC    GLOBAL DEFAULT    9 lua_pcallk
   100: 0000000000007a80    47 FUNC    GLOBAL DEFAULT    9 lua_touserdata
   101: 000000000000aff0  1192 FUNC    GLOBAL DEFAULT    9 lua_getinfo
   102: 000000000001b420   169 FUNC    GLOBAL DEFAULT    9 luaL_openlib
   103: 0000000000007460    60 FUNC    GLOBAL DEFAULT    9 lua_insert
   104: 0000000000007580    83 FUNC    GLOBAL DEFAULT    9 lua_isnumber
   105: 00000000000149d0   231 FUNC    GLOBAL DEFAULT    9 lua_newthread
   106: 0000000000024d90   117 FUNC    GLOBAL DEFAULT    9 luaL_openlibs
   107: 000000000001b360   183 FUNC    GLOBAL DEFAULT    9 luaL_setfuncs
   108: 000000000001ae50   275 FUNC    GLOBAL DEFAULT    9 luaL_tolstring
   109: 00000000000074a0    30 FUNC    GLOBAL DEFAULT    9 lua_replace
   110: 000000000001a840    38 FUNC    GLOBAL DEFAULT    9 luaL_buffinitsize
   111: 0000000000008df0    72 FUNC    GLOBAL DEFAULT    9 lua_upvalueid
   112: 0000000000007ef0   108 FUNC    GLOBAL DEFAULT    9 lua_getglobal
   113: 00000000000209c0    42 FUNC    GLOBAL DEFAULT    9 luaopen_os
   114: 000000000001a870   214 FUNC    GLOBAL DEFAULT    9 luaL_ref
   115: 000000000000ae00     5 FUNC    GLOBAL DEFAULT    9 lua_gethook
   116: 0000000000007370    24 FUNC    GLOBAL DEFAULT    9 lua_version
   117: 0000000000008260    39 FUNC    GLOBAL DEFAULT    9 lua_settable
   118: 0000000000019b40   159 FUNC    GLOBAL DEFAULT    9 luaL_where
   119: 000000000001a1f0    63 FUNC    GLOBAL DEFAULT    9 luaL_checktype
   120: 000000000001a230    58 FUNC    GLOBAL DEFAULT    9 luaL_checkany
   121: 0000000000019e90   132 FUNC    GLOBAL DEFAULT    9 luaL_fileresult
   122: 000000000001a5b0    57 FUNC    GLOBAL DEFAULT    9 luaL_optunsigned
   123: 0000000000008e40    92 FUNC    GLOBAL DEFAULT    9 lua_upvaluejoin
   124: 000000000001a050    33 FUNC    GLOBAL DEFAULT    9 luaL_setmetatable
   125: 000000000001a9b0   656 FUNC    GLOBAL DEFAULT    9 luaL_loadfilex
   126: 0000000000008c00    76 FUNC    GLOBAL DEFAULT    9 lua_newuserdata
   127: 0000000000007600    26 FUNC    GLOBAL DEFAULT    9 lua_isuserdata
   128: 000000000001a2c0   106 FUNC    GLOBAL DEFAULT    9 luaL_optlstring
   129: 000000000001a6f0    44 FUNC    GLOBAL DEFAULT    9 luaL_addstring
   130: 0000000000007390    34 FUNC    GLOBAL DEFAULT    9 lua_absindex
   131: 0000000000007c40    98 FUNC    GLOBAL DEFAULT    9 lua_pushstring
   132: 00000000000078a0   133 FUNC    GLOBAL DEFAULT    9 lua_tounsignedx
   133: 0000000000008660   135 FUNC    GLOBAL DEFAULT    9 lua_callk
   134: 0000000000007560    26 FUNC    GLOBAL DEFAULT    9 lua_iscfunction
   135: 000000000001ad60    85 FUNC    GLOBAL DEFAULT    9 luaL_callmeta
   136: 000000000001c470   127 FUNC    GLOBAL DEFAULT    9 luaopen_base
   137: 00000000000250e0   129 OBJECT  GLOBAL DEFAULT   11 lua_ident
   138: 0000000000008810   219 FUNC    GLOBAL DEFAULT    9 lua_load
   139: 000000000001acd0   139 FUNC    GLOBAL DEFAULT    9 luaL_getmetafield
   140: 0000000000007fe0    44 FUNC    GLOBAL DEFAULT    9 lua_rawget
   141: 00000000000074c0    37 FUNC    GLOBAL DEFAULT    9 lua_copy
   142: 0000000000008290    94 FUNC    GLOBAL DEFAULT    9 lua_setfield
   143: 00000000000072e0   102 FUNC    GLOBAL DEFAULT    9 lua_xmove
   144: 000000000001f430   216 FUNC    GLOBAL DEFAULT    9 luaopen_io
   145: 0000000000008d10   221 FUNC    GLOBAL DEFAULT    9 lua_setupvalue
   146: 0000000000019cd0   315 FUNC    GLOBAL DEFAULT    9 luaL_argerror
   147: 00000000000080c0   102 FUNC    GLOBAL DEFAULT    9 lua_createtable
   148: 0000000000007350    22 FUNC    GLOBAL DEFAULT    9 lua_atpanic
   149: 0000000000008010    50 FUNC    GLOBAL DEFAULT    9 lua_rawgeti
   150: 000000000000c7a0   155 FUNC    GLOBAL DEFAULT    9 lua_yieldk
   151: 0000000000008b10   145 FUNC    GLOBAL DEFAULT    9 lua_concat
   152: 000000000001a330   157 FUNC    GLOBAL DEFAULT    9 luaL_checkoption
   153: 0000000000008050   108 FUNC    GLOBAL DEFAULT    9 lua_rawgetp
   154: 0000000000008930   391 FUNC    GLOBAL DEFAULT    9 lua_gc
   155: 00000000000073e0    64 FUNC    GLOBAL DEFAULT    9 lua_settop
   156: 000000000001b040   127 FUNC    GLOBAL DEFAULT    9 luaL_getsubtable
   157: 0000000000007dd0   175 FUNC    GLOBAL DEFAULT    9 lua_pushcclosure
   158: 000000000001ac40    72 FUNC    GLOBAL DEFAULT    9 luaL_loadbufferx
   159: 0000000000008bf0    12 FUNC    GLOBAL DEFAULT    9 lua_setallocf
   160: 0000000000007b30    20 FUNC    GLOBAL DEFAULT    9 lua_pushnil
   161: 0000000000007a50    39 FUNC    GLOBAL DEFAULT    9 lua_tocfunction
   162: 000000000001a490   109 FUNC    GLOBAL DEFAULT    9 luaL_checkinteger
   163: 0000000000019f20   175 FUNC    GLOBAL DEFAULT    9 luaL_execresult
   164: 000000000000ae10     5 FUNC    GLOBAL DEFAULT    9 lua_gethookmask
   165: 00000000000082f0   126 FUNC    GLOBAL DEFAULT    9 lua_rawset
   166: 0000000000008920     5 FUNC    GLOBAL DEFAULT    9 lua_status
   167: 0000000000008ad0    50 FUNC    GLOBAL DEFAULT    9 lua_next
   168: 000000000001a180   105 FUNC    GLOBAL DEFAULT    9 luaL_checkstack
   169: 00000000000081e0   119 FUNC    GLOBAL DEFAULT    9 lua_setglobal
   170: 000000000001a440    67 FUNC    GLOBAL DEFAULT    9 luaL_optnumber
   171: 0000000000007420    55 FUNC    GLOBAL DEFAULT    9 lua_remove
   172: 000000000000af50   154 FUNC    GLOBAL DEFAULT    9 lua_setlocal
   173: 0000000000019fd0   122 FUNC    GLOBAL DEFAULT    9 luaL_newmetatable
   174: 0000000000014b10    16 FUNC    GLOBAL DEFAULT    9 lua_close
   175: 000000000000ae20     4 FUNC    GLOBAL DEFAULT    9 lua_gethookcount
   176: 00000000000077a0   119 FUNC    GLOBAL DEFAULT    9 lua_tonumberx
   177: 0000000000007cb0    64 FUNC    GLOBAL DEFAULT    9 lua_pushvfstring
   178: 0000000000007710   143 FUNC    GLOBAL DEFAULT    9 lua_compare
   179: 0000000000007e80    29 FUNC    GLOBAL DEFAULT    9 lua_pushboolean
   180: 0000000000007f60    38 FUNC    GLOBAL DEFAULT    9 lua_gettable
   181: 000000000001ffa0   118 FUNC    GLOBAL DEFAULT    9 luaopen_math
   182: 0000000000007ba0    53 FUNC    GLOBAL DEFAULT    9 lua_pushunsigned
   183: 000000000001b0c0   174 FUNC    GLOBAL DEFAULT    9 luaL_requiref
   184: 000000000000c650   328 FUNC    GLOBAL DEFAULT    9 lua_resume
   185: 0000000000008370   110 FUNC    GLOBAL DEFAULT    9 lua_rawseti
   186: 00000000000088f0    41 FUNC    GLOBAL DEFAULT    9 lua_dump
   187: 000000000001adc0   130 FUNC    GLOBAL DEFAULT    9 luaL_len
   188: 0000000000022f50   167 FUNC    GLOBAL DEFAULT    9 luaopen_string
   189: 0000000000007ec0    40 FUNC    GLOBAL DEFAULT    9 lua_pushthread
   190: 000000000001b170   224 FUNC    GLOBAL DEFAULT    9 luaL_gsub
   191: 0000000000008c50   181 FUNC    GLOBAL DEFAULT    9 lua_getupvalue
   192: 00000000000083e0   174 FUNC    GLOBAL DEFAULT    9 lua_rawsetp
   193: 0000000000007be0    88 FUNC    GLOBAL DEFAULT    9 lua_pushlstring
   194: 000000000001a720    71 FUNC    GLOBAL DEFAULT    9 luaL_pushresult
   195: 000000000000adc0    54 FUNC    GLOBAL DEFAULT    9 lua_sethook
   196: 00000000000075e0    27 FUNC    GLOBAL DEFAULT    9 lua_isstring
   197: 0000000000019820   800 FUNC    GLOBAL DEFAULT    9 luaL_traceback
   198: 000000000001a5f0   193 FUNC    GLOBAL DEFAULT    9 luaL_prepbuffsize
   199: 000000000001a120    85 FUNC    GLOBAL DEFAULT    9 luaL_checkudata
   200: 0000000000008ac0     9 FUNC    GLOBAL DEFAULT    9 lua_error
   201: 000000000001a950    83 FUNC    GLOBAL DEFAULT    9 luaL_unref
   202: 000000000001e150    42 FUNC    GLOBAL DEFAULT    9 luaopen_debug
   203: 000000000001b280   217 FUNC    GLOBAL DEFAULT    9 luaL_checkversion_
   204: 000000000001caa0    42 FUNC    GLOBAL DEFAULT    9 luaopen_bit32
   205: 0000000000007b50    25 FUNC    GLOBAL DEFAULT    9 lua_pushnumber
   206: 000000000001a780   146 FUNC    GLOBAL DEFAULT    9 luaL_addvalue
   207: 000000000001a500   107 FUNC    GLOBAL DEFAULT    9 luaL_checkunsigned
   208: 000000000001a6c0    46 FUNC    GLOBAL DEFAULT    9 luaL_addlstring
   209: 0000000000007ab0    21 FUNC    GLOBAL DEFAULT    9 lua_tothread
   210: 000000000001cf50    42 FUNC    GLOBAL DEFAULT    9 luaopen_coroutine
   211: 0000000000007620    87 FUNC    GLOBAL DEFAULT    9 lua_rawequal
   212: 00000000000074f0    33 FUNC    GLOBAL DEFAULT    9 lua_pushvalue
   213: 0000000000008130   105 FUNC    GLOBAL DEFAULT    9 lua_getmetatable
   214: 0000000000014720   683 FUNC    GLOBAL DEFAULT    9 lua_newstate
   215: 0000000000007b70    34 FUNC    GLOBAL DEFAULT    9 lua_pushinteger
   216: 0000000000023b40    79 FUNC    GLOBAL DEFAULT    9 luaopen_table
   217: 0000000000007f90    79 FUNC    GLOBAL DEFAULT    9 lua_getfield
   218: 000000000001a570    57 FUNC    GLOBAL DEFAULT    9 luaL_optinteger
   219: 0000000000019be0   234 FUNC    GLOBAL DEFAULT    9 luaL_error
   220: 0000000000007930    47 FUNC    GLOBAL DEFAULT    9 lua_toboolean
   221: 0000000000007ea0    23 FUNC    GLOBAL DEFAULT    9 lua_pushlightuserdata
   222: 00000000000079e0   111 FUNC    GLOBAL DEFAULT    9 lua_rawlen
   223: 0000000000007230   162 FUNC    GLOBAL DEFAULT    9 lua_checkstack
   224: 0000000000007cf0   218 FUNC    GLOBAL DEFAULT    9 lua_pushfstring
   225: 0000000000008490   317 FUNC    GLOBAL DEFAULT    9 lua_setmetatable
   226: 0000000000007ad0    96 FUNC    GLOBAL DEFAULT    9 lua_topointer
   227: 0000000000007540    18 FUNC    GLOBAL DEFAULT    9 lua_typename
   228: 0000000000007960   128 FUNC    GLOBAL DEFAULT    9 lua_tolstring
   229: 000000000001a820    28 FUNC    GLOBAL DEFAULT    9 luaL_buffinit
   230: 000000000001a770    10 FUNC    GLOBAL DEFAULT    9 luaL_pushresultsize
   231: 000000000001af70   207 FUNC    GLOBAL DEFAULT    9 luaL_pushmodule
   232: 000000000001b250    47 FUNC    GLOBAL DEFAULT    9 luaL_newstate
   233: 000000000001a080   148 FUNC    GLOBAL DEFAULT    9 luaL_testudata
   234: 0000000000007520    30 FUNC    GLOBAL DEFAULT    9 lua_type
   235: 000000000000ae80   199 FUNC    GLOBAL DEFAULT    9 lua_getlocal
   236: 000000000001a270    77 FUNC    GLOBAL DEFAULT    9 luaL_checklstring
   237: 0000000000008bb0    31 FUNC    GLOBAL DEFAULT    9 lua_len
   238: 000000000000ae30    79 FUNC    GLOBAL DEFAULT    9 lua_getstack
   239: 000000000001ac90    50 FUNC    GLOBAL DEFAULT    9 luaL_loadstring
   240: 00000000000081a0    64 FUNC    GLOBAL DEFAULT    9 lua_getuservalue
   241: 00000000000073c0    23 FUNC    GLOBAL DEFAULT    9 lua_gettop
   242: 0000000000007820   117 FUNC    GLOBAL DEFAULT    9 lua_tointegerx
   243: 0000000000024b50   568 FUNC    GLOBAL DEFAULT    9 luaopen_package
   244: 000000000001a3d0   111 FUNC    GLOBAL DEFAULT    9 luaL_checknumber

似乎所有 未定义的引用 都存在于 /usr/lib/liblua5.2.so.5.2 中,我不知道如何从这里继续。

Other answers on SO 建议将 lua 的 #includes 放入 extern "C" 中,如下所示:

extern "C"{
    #include <lua5.2/lualib.h>
    #include <lua5.2/lauxlib.h>
    #include <lua5.2/lua.h>
}

但我宁愿不更改给定的代码,甚至不知道如何找出哪些文件 lua 被 #included 。

最好我只想更改 make 命令 catkin_make -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=/usr/bin/python3 -DCMAKE_CXX_STANDARD=14 以帮助 ld 正确 link 但我不知道这是否可能。我不太熟悉 makecmake 或本例中的 catkin_make,无法确定是否可以在 [=] 中添加 linker 选项25=]命令。

Lua 可以编译为 C 和 C++ 语言。这是它的一个广告功能。出于这个原因,Lua 作者决定 将经典 extern "C" 包含在 headers.

你的 liblua5.2.so.5.2 库是用 C 语言编译的,符号没有被破坏。您在 C++ 模式下编译了您的应用程序,只包含 Lua headers 而没有 extern "C",因此您的 Lua 包含的符号被破坏了。

解决方案:用 extern "C":

包裹你的包含
extern "C"
{
#include "lua.h"
}

另一种解决方案是将 Lua 5.2 重新编译为 C++ 语言(使用 GCC 和 Clang 的 -x c++ 编译器选项,或 MSVC 的 /TP 编译器选项)。

感谢 prapin 的回答,我让它工作了:)

我在 lua manual.

之后从源安装了 lua 5.2

代替 prapins 建议使用 -x c++ 编译器选项,我在 lua-5.2.0/src 的 makefile 中更改了以下内容:

  • 已将 CC= gcc 更改为 CC= g++

  • -shared -fPIC 添加到 MYCFLAGS= 因为我需要 .so 文件。

我希望这可以帮助任何不想将包含包含在 extern "C"

中的人解决这个问题