J
J
John Doe2019-01-20 06:13:06
C++ / C#
John Doe, 2019-01-20 06:13:06

How to include all dependencies in the compiled file?

When running the executable file, I get errors that there are no necessary .dlls nearby, such as libgcc_s_dw2-1.dll , msys_curl-4.dll , libstdc++-6.dll . How can I build a clion project with all dependencies into one executable?
I am using clion, mingw-w64 (i686-8-1-0-posix-dwarf-rt_v6-rev0).
CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.7)
project(cpr-example)

if(NOT ${CMAKE_VERSION} LESS 3.2)
    set(CMAKE_CXX_STANDARD 11)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
else()
    message(STATUS "Checking compiler flags for C++11 support.")
    # Set C++11 support flags for various compilers
    include(CheckCXXCompilerFlag)
    check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
    check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
    if(COMPILER_SUPPORTS_CXX11)
        message(STATUS "C++11 is supported.")
        if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
        else()
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
        endif()
    elseif(COMPILER_SUPPORTS_CXX0X)
        message(STATUS "C++0x is supported.")
        if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++")
        else()
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
        endif()
    else()
        message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
    endif()
endif()

add_subdirectory(opt)

add_executable(test main.cpp)
target_link_libraries(test ${CPR_LIBRARIES})
include_directories(${CPR_INCLUDE_DIRS} ${JSON_INCLUDE_DIRS})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2019-01-20
@rabbit418

How can I build a project with all dependencies into a single executable?

By adding -staticto LDFLAGS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question