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:
What am I missing exactly ?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With