Cross compilation (arm64) with OpenSSL not working properly
ruicanas opened this issue · 4 comments
Describe the bug
I'm trying to cross-compile paho for arm64 with OpenSSL and I can do it successfully. However, when compiling it on my project, it retrieves some linking errors stating that the architecture has undefined symbols.
To Reproduce
For the toolchain file, I'm using leetal/ios-cmake which is working fine without the SSL flag activated.
I'm also using some OpenSSL binaries for iOS provided by krzyzanowskim/OpenSSL.
- In the library's directory, use this command:
cmake -S. -B_builds_ios -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.toolchain.cmake -DPLATFORM=OS64\
-DENABLE_BITCODE=NO \
-DPAHO_WITH_SSL=TRUE \
"-DOPENSSL_ROOT_DIR=<my-openssl-dir>" \
"-DDEPLOYMENT_TARGET=14.0" \
"-DMACOSX_BUNDLE_GUI_IDENTIFIER=<bundle-id>" \
"-DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=<dev-team>" \
"-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY=<id>" \
"-DCMAKE_XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER=<profile>" \
"-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE=Manual" \
-DPAHO_BUILD_SHARED=FALSE \
-DPAHO_BUILD_STATIC=TRUE
- Run the command
cmake --build _builds_ios --config Release
- Run the command
cmake --install _builds_ios --config Release
- Use the generated static binaries in a project. (In my specific case, I'm using it in a Kotlin Multiplatform Project)
Expected behavior
Everything compiles and links successfully.
Log files
log_file.txt
Environment:
- OS: iOS arm64 & x86_64
Additional context
I also made alipo -info libpaho-mqtt3cs.a
and it always retrieves the arch that I've asked for. I've also tried for x86_64 arch but the issue remains.
Like I've mentioned before, I was also able to make it work without the OpenSSL dependency. However, it's mandatory to have it for what I want to do and I really would like to have this working with OpenSSL.
Sorry for any technical mistakes and, please, correct me if I'm doing something reaaaaally wrong.
Thank you in advance!
I don't know if I can be much help here as I rarely if ever cross-compile.
You'll need to make sure the architecture of the binaries you build matches the architecture of the OpenSSL binaries you've obtained, which is the first thing I'd check. I don't know if the warnings:
ld: warning: object file (/var/folders/gp/fg0t8nq13w574w417rgtb50r0000gp/T/included2305542194918275474/libpaho-mqtt3cs.a(MQTTClient.o)) was built for newer iOS version (14.0) than being linked (9.0)
have any effect on this.
I assured that I was doing that several times and I'm really doing that correctly (check it with lipo -info
) making the issue odd.
I've even tried other OpenSSL binaries (x2on/OpenSSL-for-iPhone but with this one, I wasn't even able to compile it due to a missing headers which I find even more odd:
EDIT 1:
Give it another try and the issue remains. The libpaho-mqtt3c.a
is generated and is compiled correctly but thelibpaho-mqtt3cs.a
issue prevails.
Those calls are just to get information, you can comment them out if you want.
Looking at the OpenSSL docs they have apparently been replaced by OpenSSL_version() in OpenSSL 1.1.1. However I've built with OpenSSL versions 1 and 3 without complaint so I'm not sure what's going on. The OpenSSL_version APIs aren't available in 1.0.2, it seems, so I'd want to be careful about changing this.
I've commented out those lines, but the same thing still happens. Although I am able to generate the binaries successfully, I am unable to compile the ...cs.a
files in my project by the reasons I mentioned before, even though I can compile the ...c.a
files.