Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Position Independent Code (-fPIC) during compilation (UE 5.0.2)(Linux) #21

Open
TheMesoria opened this issue Jul 4, 2022 · 4 comments

Comments

@TheMesoria
Copy link

OS: Ubuntu 22.04 LTS
UE Version: 5.0.2 (Source code build)
Plugin Version: 1.1.0 (Downloaded from releases)

When I am attempting to build your solution into my project, I am unfortunately greeted by those errors:

Full error output
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquittopp/libraries/libmosquittopp_static.a(mosquittopp.cpp.o)
>>> referenced by mosquittopp.cpp
>>>               mosquittopp.cpp.o:(mosqpp::mosquittopp::mosquittopp(char const*, bool)) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquittopp/libraries/libmosquittopp_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol vtable for mosqpp::mosquittopp; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquittopp/libraries/libmosquittopp_static.a(mosquittopp.cpp.o)
>>> referenced by mosquittopp.cpp
>>>               mosquittopp.cpp.o:(mosqpp::mosquittopp::~mosquittopp()) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquittopp/libraries/libmosquittopp_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol mosqpp::mosquittopp::~mosquittopp(); recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquittopp/libraries/libmosquittopp_static.a(mosquittopp.cpp.o)
>>> referenced by mosquittopp.cpp
>>>               mosquittopp.cpp.o:(mosqpp::mosquittopp::~mosquittopp()) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquittopp/libraries/libmosquittopp_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol mosquitto_reinitialise; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(mosquitto.c.o)
>>> referenced by mosquitto.c
>>>               mosquitto.c.o:(mosquitto_new) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol mosquitto_destroy; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(mosquitto.c.o)
>>> referenced by mosquitto.c
>>>               mosquitto.c.o:(mosquitto_new) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol mosquitto__destroy; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(mosquitto.c.o)
>>> referenced by mosquitto.c
>>>               mosquitto.c.o:(mosquitto_reinitialise) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol mosquitto__destroy; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(mosquitto.c.o)
>>> referenced by mosquitto.c
>>>               mosquitto.c.o:(mosquitto_destroy) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol _ui_method; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(setup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol _ui_method; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(setup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol _ui_method; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(setup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol _ui_method; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(setup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol _ui_method; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(setup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol _ui_method; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(cleanup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol _ui_method; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(cleanup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol _ui_method; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(cleanup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol _ui_method; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__get_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol tls_ex_index_mosq; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__init_tls) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol tls_ex_index_mosq; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__init_tls) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol tls_ex_index_mosq; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(psk_client_callback) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol net__socket_nonblock; recompile with -fPIC
>>> defined in Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a(net_mosq.c.o)
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__try_connect_tcp) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

Is it a problem on my end? Does any other Linux user already know it? The same setup works for MS Windows just fine; Project without plugins boots on Linux; it's just this plugin that fails to compile.

While I am not very experienced with the Unreal Engine Build Tool ecosystem, I look forward to knowing what I did wrong (or not).

@tustanivsky
Copy link
Member

Hi @TheMesoria , it looks that the mosquitto library which is used by our plugin was compiled with some settings that make it incompatible with UE5 on Linux. You can try to re-compile it by making sure -fPIC option is there (PIC stands for Position Independent Code) and update the corresponding plugin binaries.

@tustanivsky
Copy link
Member

Also, you can try to add AdditionalCompilerArguments = "-fPIC"; to your project's Target.cs file and see if it helps

@TheMesoria
Copy link
Author

I already did add AdditionalCompilerArguments = "-fPIC"; to the project, as it was one of my first guesses. I will attempt to recompile mosquitopp and other '.a' with -fPIC and update in the next comment.

@TheMesoria
Copy link
Author

After some work (mostly reading CMakeLists.txt) If come up with this solution:

mkdir bin && cd bin
cmake ../ -DCMAKE_INSTALL_PREFIX=$(pwd)/install/mosquitto/bin/install -DWITH_STATIC_LIBRARIES=ON -DWITH_PIC=ON
make && make install

After those, I copied those libraries to replace the current ones, and it appears to work relatively well. Unfortunately, I run into issues with openSSL lib, which I think are mostly connected to the Unreal Engine Build Tool linker:

Full error output
[1/21] Link (lld) libUnrealEditor-MqttUtilities.so
0>ld.lld: Error  : undefined symbol: SSL_free
>>> referenced by mosquitto.c
>>>               mosquitto.c.o:(mosquitto__destroy) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__socket_close) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__socket_connect_step3) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: SSL_CTX_free
>>> referenced by mosquitto.c
>>>               mosquitto.c.o:(mosquitto__destroy) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: UI_OpenSSL
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(ui_open) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(ui_read) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(ui_write) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a
>>> referenced 1 more times

0>ld.lld: Error  : undefined symbol: UI_method_get_opener
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(ui_open) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: UI_method_get_reader
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(ui_read) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: UI_method_get_writer
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(ui_write) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: UI_method_get_closer
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(ui_close) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: UI_create_method
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(setup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: UI_method_set_opener
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(setup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: UI_method_set_reader
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(setup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: UI_method_set_writer
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(setup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: UI_method_set_closer
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(setup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: UI_destroy_method
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(cleanup_ui_method) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: CONF_modules_unload
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__cleanup) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: OPENSSL_init_crypto
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__init_tls) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: ENGINE_load_builtin_engines
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__init_tls) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: CRYPTO_get_ex_new_index
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__init_tls) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: SSL_in_init
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__socket_close) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: SSL_shutdown
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__socket_close) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: SSL_get_ex_data
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(psk_client_callback) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a
>>> referenced by tls_mosq.c
>>>               tls_mosq.c.o:(mosquitto__server_certificate_verify) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : too many errors emitted, stopping now (use -error-limit=0 to see all errors)
0>clang++: Error  : linker command failed with exit code 1 (use -v to see invocation)

I am slightly clueless about what could be a reason for such an output, as I have libssl in public and well-defined paths:

/usr/include/openssl/ssl.h
/usr/include/openssl/engine.h
etc.

libs are at

>>>>> ls /lib/x86_64-linux-gnu/ | grep ssl
libssl3.so
libssl.a
libssl.so
libssl.so.1.1
libssl.so.3
ossl-modules

So everything looks well and dandy to me. I attempted to add

		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				"OpenSSL"
				// ... add other public dependencies that you statically link with here ...
			}
			);

And It appeared to patch up the issue (?) and I was left with:

Full Error Output
0>ld.lld: Error  : undefined symbol: SSL_CTX_load_verify_file
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__tls_load_ca) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a

0>ld.lld: Error  : undefined symbol: SSL_CTX_load_verify_dir
>>> referenced by net_mosq.c
>>>               net_mosq.c.o:(net__tls_load_ca) in archive Plugins/MqttUtilities/Source/ThirdParty/Linux/libmosquitto/libraries/libmosquitto_static.a
0>clang++: Error  : linker command failed with exit code 1 (use -v to see invocation)

I am completely clueless about how to approach this issue, as it seems to be part of the OpenSSL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants