Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clion how to deploy project?

Tags:

c++

c++11

clion

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 ?

like image 431
dimitris93 Avatar asked Feb 28 '16 05:02

dimitris93


1 Answers

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).

like image 71
dimitris93 Avatar answered Sep 29 '22 17:09

dimitris93