I’m building a Windows C++ app based on OpenSSL and would like to be able to easily move between PCs including ones where there is no OpenSSL installed.
So I downloaded OpenSSL with the msys2 environment and tried to link it to my program. Here is the basic CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(BasicSsl LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(OPENSSL_ROOT_DIR "D:/msys64/mingw64")
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
message(WARNING "libs: ${OPENSSL_LIBRARIES}")
add_executable(BasicSsl main.cpp)
target_include_directories(BasicSsl PRIVATE ${OPENSSL_INCLUDE_DIR})
target_link_libraries(BasicSsl PRIVATE OpenSSL::Crypto OpenSSL::SSL)
Here’s the main.cpp
#include <openssl/rand.h>
#define RANDID_SIZE 17
int main()
{
uint8_t randid[RANDID_SIZE];
if (RAND_bytes(randid, RANDID_SIZE) != 1)
{
fprintf(stderr, "openssl rand errorn");
return {};
}
return 0;
}
The problem is I keep getting tons of linker errors like
D:/msys64/mingw64/lib/libcrypto.a(libcrypto-lib-bio_sock.obj):(.text+0x2d3): undefined reference to `__imp_WSAGetLastError'
I think I’m missing something very obvious but can’t figure out what exactly