1

My code runs correctly in the terminal when I compile it like

g++ -g -O2 -std=c++11 -I/usr/local/include -L/usr/local/lib main.cpp -lboost_system -lboost_filesystem -fopenmp -lpthread -o main -lz

But when I run it from CLion it gives a bunch of errors specifically linking

Undefined reference to gzread/gzclose/gzopen

which I believe is due to not specifying the compile options while compiling.

How do I set the compile options in CLion?

EDIT

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)
project(Partition)

set(CMAKE_CXX_STANDARD 14)

add_executable(Partition main.cpp kseq.h)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -O2 -std=c++11 -I/usr/local/include -L/usr/local/lib -lboost_system -lboost_filesystem -fopenmp -lpthread -lz")
Harsh
  • 13
  • 1
  • 6
  • 3
    `target_link_libraries` in CMakeLists.txt – halfelf Dec 21 '18 at 05:55
  • Yes but I don't know how exactly to write it. Do I write like this target_link_libraries (-g -O2 -std=c++11 etc)? – Harsh Dec 21 '18 at 11:36
  • https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html – arved Dec 21 '18 at 14:25
  • @arved I have already gone through the link. I can't make it work though. CLion throws same linking error. – Harsh Dec 21 '18 at 16:06
  • Then post your CMakeList.txt – arved Dec 21 '18 at 16:14
  • Please see the Edit. – Harsh Dec 21 '18 at 16:17
  • @Harsh SO is a Question and Answer platform, so do not update your question to include the Solution. if you think that the given answer(s) are missing a necessary detail to full answer your question then create your own answer. – t.niese Dec 21 '18 at 16:43
  • Possible duplicate of [How to add "-l" (ell) compiler flag in CMake](https://stackoverflow.com/questions/43136418/how-to-add-l-ell-compiler-flag-in-cmake) – Tsyvarev Dec 21 '18 at 20:50

1 Answers1

0

It is not the compiling step that is failing but the linking step.

The -l parts of your command line string are the linking options, and list the libraries to which you want to link your program to.

The names that at listed after each of these -l have to be added using the target_link_libraries(Partition boost_system ...)

t.niese
  • 39,256
  • 9
  • 74
  • 101
  • Did this : target_link_libraries(-lboost_system -lboost_filesystem -lpthread -lz). Which gave this error : CMake Error at CMakeLists.txt:8 (target_link_libraries): Cannot specify link libraries for target "-lboost_system" which is not built by this project. – Harsh Dec 21 '18 at 16:29