Clion how to deploy a project?

I have the following CMakeLists.txt :

cmake_minimum_required(VERSION 3.3) project(Thesis) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(SOURCE_FILES main.cpp Graph.h Graph.cpp) add_executable(Thesis ${SOURCE_FILES}) 

I use Run-> Build (as release) in the user folder ClionProjects\Thesis\exe\Release , and I get one executable file Thesis.exe . If I open it, I get the following consecutive errors:

1

What am I missing for sure?

+5
source share
2 answers

My solution was to link libraries statically. This was not necessary for the inconvenient .dll standing next to your .exe.

Adding a separate line to CMakeLists.txt

 set(CMAKE_EXE_LINKER_FLAGS -static) 

The problem is fixed. Here are 2 more options that also work if you need it for some reason.

 #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS} -static-libgcc -static-libstdc++ -static") #set(CMAKE_EXE_LINKER_FLAGS=-static-libgcc -static-libstdc++ -static) 

My .exe went from 100 KB to 1 MB

Edit: a few more interesting options

Added -s and -O3 to my original CMakeLists.txt my question.

 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -s -O3") 

-s reduced size from 1 MB to 650 KB. - s

-O3 should set optimization level 3, which is max - O3

You can see all the options from gcc.gnu.org . Too much. Use the "Find" option of your browser (Ctrl + f).

+4
source

You are missing 2 required DLLs.

The easiest way to enable this is to tell the compiler to link statically to each library using the -static option in GCC.

Another way is to copy these DLLs to the folder in which your executable file exists.

The third way is to find these DLLs and register them .

0
source

Source: https://habr.com/ru/post/1244035/


All Articles