[C++] PE asking for .dll EVEN with static linker flag

Good evening!

My .exe has been built and worked well on my PC, but once I tried to run it on my Laptop, I got a bigger surprise than in Thailand :frowning:.

“libcurl.dll was not found”, - What?? I use target_link_libraries and added CURL_STATICLIB to compile definitions.

No problem, let’s install the libcurl.dll on the Laptop.

“libgcc_s_dw2-1.dll was not found” - WHAT?? I have set(CMAKE_EXE_LINKER_FLAGS “-static-libgcc -static-libstdc++ -static”).

CMakeLists.txt

cmake_minimum_required(VERSION 3.24.0)
project(recorder)

# Force build if you don't want to set IDE build settings
# set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")

# Set flags to build 32-bit binary & which exe to use for C / C++
set (CMAKE_C_FLAGS "-m32")
set (CMAKE_CXX_FLAGS "-m32")
#set(CMAKE_C_COMPILER gcc)
#set(CMAKE_CXX_COMPILER g++)

# Linker optimization for ALL targets
# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)

# Preprocessor definitions
add_compile_definitions(
    CURL_STATICLIB
    UNICODE
    _UNICODE
)

# Define project
file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
file(GLOB_RECURSE MY_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
add_executable(${PROJECT_NAME} "${MY_SOURCES}" "${MY_HEADERS}"
        include/test_runtime_encrypt.hpp)

# Additional include directories (ONLY for project)
target_include_directories(${PROJECT_NAME} PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}/include"
)

# Add dependencies
target_include_directories(${PROJECT_NAME} PRIVATE
    "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/curl/include"
    "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/NaturalMouseMotion"
    "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/xorstr"
    "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/nt_function"
)

# STATIC
target_link_libraries(${PROJECT_NAME} -static)
add_subdirectory(dependencies/ntfunction)
target_link_libraries(${PROJECT_NAME} nt_function)

find_package(CURL REQUIRED)
target_link_libraries(${PROJECT_NAME} iphlpapi)
target_link_libraries(${PROJECT_NAME} gdiplus)
target_link_libraries(${PROJECT_NAME} CURL::libcurl)

CMakeLists.txt for add_subdirectory /ntfunction

project(nt_function)
set(CMAKE_CXX_FLAGS "-fpermissive")
add_library(${PROJECT_NAME} STATIC nt_function.cpp nt_function.hpp)
target_include_directories(${PROJECT_NAME} INTERFACE .)

What causes my .exe to require additional .dll’s when built with static linkage?

It looks like you have a shared libcurl build. It will need to be built statically (or a static build found instead). Note that preprocessor definitions won’t change anything about the shared/static state of a library that CMake finds.