c++ - Can't compile with CMake and ncurses -


i'm aware similar questions have been posted, can't see how relate case. preface question saying i'm not familiar cmake, it's entirely possible quick fix , don't see it!

i collaborating on project, , yesterday teammate added ncurses library project build terminal gui. ever since ncurses added, haven't been able compile project. however, did install 6 ncurses-* packages, should behave machine.

i have pulled down latest version of master branch our github repo, compiles , runs on machine. won't compile on mine.

system:
linux mint 18.1 cinnamon
cmake version 3.5.1

things i've tried:
deleted cmakecache.txt , reloaded it
deleted entire cmake build directory , redid make

cmakelists.txt:

cmake_minimum_required(version 2.8) project(irc)  set(shared_flags " -wall -wextra -wshadow -werror -g -d_posix_c_source=200809l -lncurses") set(cmake_c_flags "-std=c11 ${shared_flags}") set(cmake_cxx_flags "-std=c++11 ${shared_flags}")  include_directories(include)  add_library(client_core shared src/client/irc_client.c)  add_executable(client src/client/irc_client_gui.c) add_executable(server src/server/irc_server.c)  // solution - missing line target_link_libraries(client ncurses)  install(files include/irc_client.h destination include) install(files include/irc_server.h destination include) 

cmakeoutput:

cmakefiles/client.dir/src/client/irc_client_gui.c.o: in function `main': /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:17:  undefined reference `initscr' /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:18:  undefined reference `stdscr' /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:18:  undefined reference `stdscr' /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:18:  undefined reference `stdscr' /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:18:  undefined reference `stdscr' /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:19:  undefined reference `mvprintw' /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:21:  undefined reference `stdscr' /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:21:  undefined reference `wgetnstr' /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:22:  undefined reference `lines' /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:22:  undefined reference `mvprintw' /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:23:  undefined reference `stdscr' /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:23:  undefined reference `wgetch' /home/chrisjansson/documents/irc/src/client/irc_client_gui.c:24:  undefined reference `endwin' collect2: error: ld returned 1 exit status cmakefiles/client.dir/build.make:94: recipe target 'client' failed make[2]: *** [client] error 1 cmakefiles/makefile2:104: recipe target 'cmakefiles/client.dir/all'  failed make[1]: *** [cmakefiles/client.dir/all] error 2 makefile:127: recipe target 'all' failed make: *** [all] error 2 

interestingly enough, if copy/paste irc_client_gui.c somewhere else on machine, compile manually gcc , run it, works perfectly. issue isn't machine, it's cmake trying compile entire project. ideas? much!

the solution add line this:

target_link_libraries(client ncurses) 

this tells cmake when linking client target, should use -lncurses option link in ncurses library.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -