6

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 am using Run->Build (as release) on a custom folder ClionProjects\Thesis\exe\Release and I get a single executable Thesis.exe. If I open that, I get the following consecutive errors:

1

What am I missing exactly ?

dimitris93
  • 4,155
  • 11
  • 50
  • 86

2 Answers2

5

My solution was to link the libraries statically. That was there is no need for an awkward .dll standing next to your .exe.

Adding a single line on the CMakeLists.txt

set(CMAKE_EXE_LINKER_FLAGS -static)

Fixed my problem. Here is other 2 options that also work, in case 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 100KB to 1MB

Edit: A couple more cool options

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

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

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

-O3 is supposed to set optimization level to 3 which is the max -O3

You can see all the options from the gcc.gnu.org site. There are too many. Use the "find" option of your browser (Ctrl + f).

dimitris93
  • 4,155
  • 11
  • 50
  • 86
0

You are missing 2 of the required DLLs.

The easiest way to resolve this is to tell the compiler to link with every library statically by using the -static option in GCC.

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

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

Community
  • 1
  • 1
nom
  • 256
  • 3
  • 16