# \[solved\] How to include library

**URL:** <https://discourse.cmake.org/t/solved-how-to-include-library/2670>\
**Category:** Code\
**Created:** [February 1, 2021, 8:05pm UTC](https://discourse.cmake.org/t/solved-how-to-include-library/2670 "2021-02-01T20:05:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![start\_something](https://discourse.cmake.org/user_avatar/discourse.cmake.org/start_something/32/1169_2.png) [@start\_something](https://discourse.cmake.org/u/start_something)\
**Post date:** [February 1, 2021, 8:05pm UTC](https://discourse.cmake.org/t/solved-how-to-include-library/2670/1 "2021-02-01T20:05:12Z")

</div>

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:

```auto
/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):

```auto
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:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![start\_something](https://discourse.cmake.org/user_avatar/discourse.cmake.org/start_something/32/1169_2.png) [@start\_something](https://discourse.cmake.org/u/start_something)\
**Post date:** [February 1, 2021, 8:56pm UTC](https://discourse.cmake.org/t/solved-how-to-include-library/2670/2 "2021-02-01T20:56:20Z")

</div>

Solved it, it needed to be added to `target_linked_libraries`.
