2

I'm importing a C project into the Clion IDE, that uses Cmake. My project uses these external libraries: Math and Ncurses. However i'm not able to get the script CMakeLists.txt working.

This is the script:

cmake_minimum_required(VERSION 2.8.4)
project(thegame)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lncurses -lm")

set(SOURCE_FILES thegame.c ./src/headers/set.h ./src/headers/functions.h ./src/headers/game.h ./src/headers/heap.h ./src/headers/lib.h
./src/headers/parser.h ./src/headers/pathfind.h ./src/headers/structures.h

./src/functions.c ./src/game.c ./src/heap.c ./src/lib.c ./src/parser.c ./src/pathfind.c ./src/set.c
)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "~/Binaries")

add_executable(thegame ${SOURCE_FILES})

I'm getting a lot of messages like this:

thegame.c:(.text.startup+0x1c): undefined reference to "mousemask"
...

What I'm doing Wrong?

Ozeta
  • 321
  • 4
  • 18
  • Where is `mousemask` supposed to be defined? – ysap Feb 04 '15 at 00:50
  • it's defined in ncurses.h . but mousemask is an example. i've got a lot of undefined reference to "pow", undefined reference to "floor", etc, all defined in math.h. I think for every time I use one of that function in the project, I get an error in the log – Ozeta Feb 04 '15 at 00:52
  • Looks like your linker does not find its libraries. What is `CMAKE_CXX_FLAGS`? Its name suggests C++, but your question is C. – ysap Feb 04 '15 at 00:54
  • Oh, in the last line, I don't see where you include those flags, only `SOURCE_FILES`. (If that's the thing, I'll make this an answer). – ysap Feb 04 '15 at 00:55
  • How do I include the flags in the last line? – Ozeta Feb 04 '15 at 01:03
  • Honestly, I a know nothing about CMake... but my guess is that it should look something like: `add_executable(thegame ${CMAKE_CXX_FLAGS} ${SOURCE_FILES})` or `add_executable(thegame ${SOURCE_FILES} ${CMAKE_CXX_FLAGS})` – ysap Feb 04 '15 at 01:09
  • nope, I get other kind of errors with this solution – Ozeta Feb 04 '15 at 01:17
  • But, does it find the libraries now? – ysap Feb 04 '15 at 01:22
  • No, it's the syntax of the command "add_executable..." that is not correct – Ozeta Feb 04 '15 at 01:24
  • Where is the `target_link_library` for ncurses? – usr1234567 Feb 12 '15 at 06:20

0 Answers0