I need to make a cross-compiled OpenSSL for a MIPS device. I've tried following the documentation. Set OPENSSL_USE_STATIC_LIBS
to true and set target_link_libraries
to the library files you need.
CMakeLists.txt:
compileAsC99()
if(NOT ${use_http})
message(FATAL_ERROR "program being generated without HTTP support")
endif()
set(program_c_files
...
)
set(program_h_files
...
)
include_directories(...)
add_executable(program ${program_c_files} ${program_h_files})
set(OPENSSL_USE_STATIC_LIBS TRUE)
#target_link_libraries(program OpenSSL::Crypto)
target_link_libraries(program /home/program/mips/lib/libssl.so.1.1)
target_link_libraries(program /home/program/mips/lib/libcrypto.so.1.1)
It compiles fine without warnings, but checking the resulting binary tells me that it's still shared library.
readelf -d program:
Dynamic section at offset 0x1bc contains 35 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libssl.so.1.1]
0x00000001 (NEEDED) Shared library: [libcrypto.so.1.1]
0x0000000f (RPATH) Library rpath: [/home/program/mips/lib]
I don't understand what I'm doing wrong.
EDIT: Already looked at Linking statically OpenSSL crypto library in CMake but it didn't tell me anything new.
EDIT 2: Updated the CMakeLists.txt file according to the reply: CMakeLists.txt:
compileAsC99()
if(NOT ${use_http})
message(FATAL_ERROR "program being generated without HTTP support")
endif()
set(program_c_files
...
)
set(program_h_files
...
)
include_directories(...)
add_executable(program ${program_c_files} ${program_h_files})
find_package(OpenSSL REQUIRED)
if(OPENSSL_FOUND)
set(OPENSSL_USE_STATIC_LIBS TRUE)
message("OPENSSL FOUND!")
endif()
target_link_libraries(program OpenSSL::Crypto)
Output:
-- IoT Client SDK Version = 1.2.11
-- Provisioning client OFF
-- target architecture: GENERIC
-- Cross compiling not using pkg-config
-- Found CURL: /home/program/mips/lib/libcurl.a (found version "7.63.0")
-- Found CURL: /home/program/mips/lib/libcurl.a
-- target architecture: GENERIC
-- target architecture: GENERIC
-- target architecture: GENERIC
-- target architecture: GENERIC
-- iothub architecture: GENERIC
OPENSSL FOUND!
-- Configuring done
-- Generating done
EDIT PROSPERITY:
If you, future people, run into the undefined reference to dlopen
, I added the following to my CMakeLists.txt
file
target_link_libraries(program ${CMAKE_DL_LIBS})
ssl
andcrypto
library files according to the build log, butreadelf
still reports that those are shared. Tried deleting the ´cmake` folder entirely and rebuilding everything without any change. Is there another flag somewhere that needs to be set somewhere perhaps? – Giess