ar2015
ar2015

Reputation: 6130

translate g++ code to clion environment

I am new in clion. on gcc i always use:

g++  bin/obj/main.o -o bin/main -lboost_filesystem -lboost_system -lcrypto

How to do it in clion?

It seems my CMakeList does not work:

cmake_minimum_required(VERSION 3.1)
project(motion_simulation)

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

set(SOURCE_FILES main.cpp)
add_executable(motion_simulation ${SOURCE_FILES})
link_libraries(lboost_filesystem)
link_libraries(lboost_system)
link_libraries(lcrypto)

Upvotes: 0

Views: 498

Answers (2)

Finn
Finn

Reputation: 1056

As you are using CMake 3.1 you can use some more advanced features of CMake.

With CMAKE_CXX_STANDARD you can select which C++ version you want to use and CMake will select the corresponding compiler flags (see docs).

link_libraries is one possibility, but it has to be called before add_executable or add_library. The alternative is target_link_libraries which links only to a single target, but can also manage transitive dependencies (docs).

CMake comes with find_package modules for OpenSSL and Boost to find dependencies and with the option REQUIRED, you can ensure that they are found on the system. Boost also supports COMPONENTS to select which libraries you need.

In case you ever work on a system, where OpenSSL and Boost are not installed in /usr/, you can already use target_include_directories to specify where the headers for your executable is found. Like target_link_libraries, target_include_directories can work with transitive dependencies, in this case PRIVATE.

 cmake_minimum_required(VERSION 3.1)
 project(motion_simulation)

 set(CMAKE_CXX_STANDARD 11)

 find_package(Boost REQUIRED COMPONENTS filesystem system)
 find_package(OpenSSL REQUIRED)

 set(SOURCE_FILES main.cpp)
 add_executable(motion_simulation ${SOURCE_FILES})
 target_include_directories(motion_simulation PRIVATE ${Boost_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR})
 target_link_libraries( motion_simulation PRIVATE ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES})

Upvotes: 1

user1283078
user1283078

Reputation: 2006

Try including the keyword "CMake" into your search next time. This question is actually not CLion specific because CLion actually uses CMake as buildsystem. CMake is very well documented, and you should be able to find a lot of answers regarding your problem.

You could first try to get rid of that "l":

link_libraries(boost_filesystem)

If that doesn't work you should take a look how the find_package() command works. http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries

And here is a detailed explanation how to find Boost libs and include directory. http://www.cmake.org/cmake/help/v3.0/module/FindBoost.html

Upvotes: 3

Related Questions