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")
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).
source share