通过mingw491在windows上构建Lua时,它会给出一个未定义的引用错误。以下是输出:
C:\Users\Alizadeh\Desktop\lua-5.3.0>mingw32-make PLAT=mingw
cd src && mingw32-make mingw
mingw32-make[1]: Entering directory 'C:/Users/Alizadeh/Desktop/lua-5.3.0/src'
mingw32-make "LUA_A=lua53.dll" "LUA_T=lua.exe" \
"AR=gcc -std=gnu99 -shared -o" "RANLIB=strip --strip-unneeded" \
"SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe
mingw32-make[2]: Entering directory 'C:/Users/Alizadeh/Desktop/lua-5.3.0/src'
g++ -c -o lua.o lua.c
g++ -c -o lapi.o lapi.c
g++ -c -o lcode.o lcode.c
.
.
.
g++ -c -o loadlib.o loadlib.c
g++ -c -o linit.o linit.c
gcc -std=gnu99 -shared -o lua53.dll lapi.o lcode.o lctype.o ldebug.o ldo.o ldump
.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o
ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o lbitlib.o lcorolib.o
ldblib.o liolib.o lmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o
linit.o
ldo.o:ldo.c:(.text+0xe5): undefined reference to `__cxa_allocate_exception'
ldo.o:ldo.c:(.text+0x105): undefined reference to `__cxa_throw'
ldo.o:ldo.c:(.text+0x234): undefined reference to `__cxa_begin_catch'
ldo.o:ldo.c:(.text+0x24c): undefined reference to `__cxa_end_catch'
ldo.o:ldo.c:(.rdata$_ZTIP11lua_longjmp[__ZTIP11lua_longjmp]+0xffff3fb8): undefin
ed reference to `vtable for __cxxabiv1::__pointer_type_info'
C:/Qt/Qt5.4.0/Tools/mingw491_32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../.
./i686-w64-mingw32/bin/ld.exe: ldo.o: bad reloc address 0x0 in section `.rdata$_
ZTIP11lua_longjmp[__ZTIP11lua_longjmp]'
collect2.exe: error: ld returned 1 exit status
makefile:59: recipe for target 'lua53.dll' failed
mingw32-make[2]: *** [lua53.dll] Error 1
mingw32-make[2]: Leaving directory 'C:/Users/Alizadeh/Desktop/lua-5.3.0/src'
makefile:116: recipe for target 'mingw' failed
mingw32-make[1]: *** [mingw] Error 2
mingw32-make[1]: Leaving directory 'C:/Users/Alizadeh/Desktop/lua-5.3.0/src'
makefile:55: recipe for target 'mingw' failed
mingw32-make: *** [mingw] Error 2
我在windows7上使用mingw(491),我想将它与Qt链接。
答案 0 :(得分:2)
我找到了答案。我刚刚使用g ++而不是gcc,它修复了:)
答案 1 :(得分:0)
解决方案是在src/Makefile
中添加以下行:
CXX= gcc -std=gnu99
或者更常见的是将CXX
设置为设置的值CC
。
出现此问题是因为Lua make文件依赖于GNU make(source)的隐式规则和变量。这意味着make应该调用$(CC) -c $(CFLAGS) $(CPPFLAGS)
来构建.c文件中的.o文件。
然而mingw打电话$(CXX) -c $(CFLAGS) $(CPPFLAGS)
。这意味着Lua C代码被编译为C ++。这个问题在链接时显现出来,因为这里使用了gcc,它无法找到与C ++相关的依赖项。所以从这里你有2个解决方案: