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

**URL:** https://discourse.cmake.org/t/c-pe-asking-for-dll-even-with-static-linker-flag/10703
**Category:** Usage
**Tags:** os:windows
**Created:** [April 20, 2024, 6:39pm UTC](https://discourse.cmake.org/t/c-pe-asking-for-dll-even-with-static-linker-flag/10703 "2024-04-20T18:39:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Roberto](https://discourse.cmake.org/user_avatar/discourse.cmake.org/roberto/32/4435_2.png) [@Roberto](https://discourse.cmake.org/u/Roberto)
#### Post date: [April 20, 2024, 6:39pm UTC](https://discourse.cmake.org/t/c-pe-asking-for-dll-even-with-static-linker-flag/10703/1 "2024-04-20T18:39:42Z")

</div>

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 ☹.

“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**

```auto
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**

```auto
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?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 27, 2024, 3:43pm UTC](https://discourse.cmake.org/t/c-pe-asking-for-dll-even-with-static-linker-flag/10703/2 "2024-04-27T15:43:13Z")

</div>

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.
