Hi!
I’m just starting out with cmake, so I expect that this might be a beginner question.
When I wrote my own make file, I could just add -lncurses
to my CXXFLAGS
variable and it would automatically pick up my ncurses library during linking.
But I can’t figure out how to do the same thing using cmake. I’ve tried using add_compile_options(-lncurses)
but that doesn’t seem to work, because my compiler keeps complaining about undefined references, such as:
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/langest/repos/terminal_defense/application/Main.cpp:21: undefined reference to `cbreak'
My Makefile (that works just fine):
maindeps = \
game.o \
gui.o \
menu.o \
coord.o \
player.o \
...
maindepsheaders = $(maindeps:.o=.hpp)
CXXFLAGS = \
-lncurses \
-ltinfo \
-g \
-Wall \
-std=c++11
all: main.cpp $(maindeps) $(maindepsheaders)
$(CXX) -o my_game.out main.cpp $(CXXFLAGS) $(maindeps)
ncurses_test: test/ncursestest.cpp
$(CXX) -std=c++0x -g -Wall test/ncursestest.cpp -lncurses -o ncursestest.out
gui_test: test/guitest.cpp gui.hpp gui.cpp
$(CXX) -std=c++0x -g -Wall test/guitest.cpp gui.hpp gui.cpp -lncurses -o guitest.out
clean:
rm -f $(maindeps) gui_mock.o gui.o my_game.out
clean_saves:
rm -f *.save
My root CMakeLists.txt:
cmake_minimum_required(VERSION 3.17.4)
project(TerminalDefense)
#add_compile_options(-std=c++11)
add_compile_options(-Wall)
add_compile_options(-g)
add_compile_options(-lncurses) # these are what doesn't seem to work
add_compile_options(-ltinfo) # these are what doesn't seem to work
add_subdirectory(source)
add_subdirectory(application)