Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create standalone exe in clion? [closed]

Tags:

c++

clion

When I try to run .exe from cmake-build-debug I have an error:

"libgcc_s_dw2-1.dll not found".

How to build standalone .exe without any dlls. I use CLion 2017.2.4, MinGW 5.0, cmake 3.9.4

like image 753
super sahar Avatar asked Apr 11 '18 12:04

super sahar


People also ask

Where are CLion files stored?

By default, CLion stores user-specific files for each IDE instance (configuration, caches, plugins, logs, and so on) in the user's home directory.

How do I create a CPP file in CLion?

Create a new C/C++ source fileIn the Project tool window, select the directory in which you want to add new files. Right-click it and select New | C/C++ Source File from the context menu. In the dialog that opens: Specify the name of a file.


1 Answers

I did it. To do this you need to add to the file CMakeLists.txt this line:

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")

After this CMakeLists.txt shoud look like this:

cmake_minimum_required(VERSION 3.9)
project(MyProject)

set(CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")

set(SOURCE_FILES main.cpp)
add_executable(MyProject${SOURCE_FILES})

Reload changes in CMakeLists.txt

Run -> Clean

Run -> Build

Now .exe file is standalone

like image 129
super sahar Avatar answered Sep 23 '22 21:09

super sahar