rdeioris / LuaMachine

Unreal Engine Plugin for Lua APIs implementation
MIT License
581 stars 120 forks source link

fails to link on linux #7

Closed nonchip closed 4 years ago

nonchip commented 4 years ago

apparently it tries to link the shared object for the plugin against a static lua library built without the PositionIndependentCode flag:

[6/8] Link (ld) libUE4Editor-LuaMachine.so
/home/kyra/src/UnrealEngine/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v15_clang-8.0.1-centos7/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-ld: /home/kyra/src/UnrealEngine/Engine/Plugins/LuaMachine/Source/ThirdParty/x64/liblua53_linux64.a(lstate.o): relocation R_X86_64_PC32 against symbol `lua_newstate' can not be used when making a shared object; recompile with -fPIC
/home/kyra/src/UnrealEngine/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v15_clang-8.0.1-centos7/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-ld: final link failed: bad value

see also https://stackoverflow.com/a/19768349/668125 for an explanation why this is happening, the binary static libs you provide were compiled without the -fPIC compiler flag, which would be required for the code to be relocatable in a shared lib.

a quick workaround was to just replace your Source/ThirdParty/x64/liblua53_linux64.a with the one from my distribution's lua (/usr/lib/liblua5.3.a), because that happened to be built with PIC, but i'd suggest you rebuild the one you're providing. or if you want i can send you my "known good" binary version?

rdeioris commented 4 years ago

Hi, you can rebuild the lua static library by following this guide: https://github.com/rdeioris/LuaMachine/blob/master/BuildingNotes.md

the linux one is pretty "useless" (just a "make linux") but adding CFLAGS='-fPIC' should do the trick

nonchip commented 4 years ago

assuming, because there's no makefile or customized lua sources in this repo, that's literally just "how to build lua from source", that won't be necessary, as i said the static lib provided by my system did the job, it's just the one you're providing that's built the wrong way.

rdeioris commented 4 years ago

Yes, i was meaning "lua official sources". PIC should not harm even in non-editor/non-shared so i can probably include a PIC version directly in the repository

nonchip commented 4 years ago

yeah the linker usually doesn't care if the code is PIC compatible when it doesn't need to be. there's even some old server OSses that require everything to be PIC, so while nobody will run UE on those, it shows it definitely doesnt hurt :D

rdeioris commented 4 years ago

The included lua static library for linux x64 has been rebuilt with -fPIC. Thanks for reporting