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

I'm aware similar questions have been posted, but I can't see how they relate to my case. I will preface this question by saying I'm not very familiar with CMake, so it's entirely possible this is a quick fix and I just don't see it!
I am collaborating on a project, and yesterday my teammate added the ncurses library to the project to build a terminal GUI. Ever since ncurses was added, I haven't been able to compile my project. However, I did install all 6 ncurses-* packages, so it should behave with my machine.
I have pulled down the latest version of the master branch from our GitHub repo, which compiles and runs perfectly on his machine. However it won't even compile on mine.
System:
Linux Mint 18.1 Cinnamon
CMake Version 3.5.1
Things I've tried:
I deleted CMakeCache.txt and reloaded it
I deleted my entire CMake build directory and 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 to `initscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:18:
undefined reference to `stdscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:18:
undefined reference to `stdscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:18:
undefined reference to `stdscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:18:
undefined reference to `stdscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:19:
undefined reference to `mvprintw'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:21:
undefined reference to `stdscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:21:
undefined reference to `wgetnstr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:22:
undefined reference to `LINES'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:22:
undefined reference to `mvprintw'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:23:
undefined reference to `stdscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:23:
undefined reference to `wgetch'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:24:
undefined reference to `endwin'
collect2: error: ld returned 1 exit status
CMakeFiles/client.dir/build.make:94: recipe for target 'client' failed
make[2]: *** [client] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/client.dir/all'
failed
make[1]: *** [CMakeFiles/client.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
Interestingly enough, if I copy/paste irc_client_gui.c somewhere else on my machine, compile it manually with gcc and run it, it works perfectly. So the issue isn't my machine, it's something with CMake trying to compile my entire project. Any ideas? Thanks so much!

The solution is to add a line like this:
target_link_libraries(client ncurses)
This tells CMake that when it is linking the client target, it should use the -lncurses option to link in the ncurses library.

Related

CMake can't find Boost_LIBRARIES variable

Final Edit: Solved.
Guys the problem occured because of the "WinSock32".
I've added
target_link_libraries(modernC__ -lws2_32)
and the code has been builded.
I have been using the Boost library on CLion in Ubuntu for about 1 year. But this week I also decided to install it on the Windows operating system.
so I downloaded the Boost library on GitHub and installed the Boost library using Find.Boost first and then "Find.Boost".
After writing the necessary commands in CMake settings section in CLion, I noticed that the variable $ {Boost_LIBRARIES} is empty.
When I don't use the message () function, the "CMake" part of the project does not give an error, but I get the error "undefined reference" after "build". Below are the CMake commands I wrote on CLion and the errors I received.
cmake_minimum_required(VERSION 3.16)
project(modernC__)
set(CMAKE_CXX_STANDARD 17)
find_package(Boost 1.66.0)
message(${Boost_INCLUDE_DIR})
message(${Boost_FOUND})
message(${Boost_LIBRARY_DIRS})
IF (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
add_executable(modernC__
main.cpp
#concurrencyExampleOne.cpp
#adapterExampleOne.cpp
)
target_link_libraries(modernC__ ${Boost_LIBRARIES})
message(${Boost_LIBRARIES})
endif()
My output is:
"C:\Program Files\JetBrains\CLion 2020.1.1\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Berke\CLionProjects\modernC++
C:/boost/include/boost-1_66
TRUE
C:/boost/lib
CMake Error at CMakeLists.txt:22 (message):
message called with incorrect number of arguments
-- Configuring incomplete, errors occurred!
In this case, obviously Cmake is currently unable to find the .lib files that should link to my code.
My question is; How can I permanently drop .lib files into this variable, or is there any other way to do this?
If I do not use "message(${Boost_LIBRARIES}" so the compiler gives me this error;
[ 50%] Linking CXX executable modernC__.exe
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition':
C:/boost/include/boost-1_66/boost/system/error_code.hpp:676: undefined reference to `boost::system::generic_category()'
C:/boost/include/boost-1_66/boost/system/error_code.hpp:679: undefined reference to `boost::system::generic_category()'
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei':
C:/boost/include/boost-1_66/boost/system/error_code.hpp:706: undefined reference to `boost::system::generic_category()'
C:/boost/include/boost-1_66/boost/system/error_code.hpp:709: undefined reference to `boost::system::generic_category()'
C:/boost/include/boost-1_66/boost/system/error_code.hpp:721: undefined reference to `boost::system::generic_category()'
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio5error19get_system_categoryEv':
C:/boost/include/boost-1_66/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio6detail17winsock_init_base7startupERNS2_4dataEhh':
C:/boost/include/boost-1_66/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to `_imp__WSAStartup#8'
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio6detail17winsock_init_base7cleanupERNS2_4dataE':
C:/boost/include/boost-1_66/boost/asio/detail/impl/winsock_init.ipp:56: undefined reference to `_imp__WSACleanup#0'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\modernC__.dir\build.make:86: modernC__.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:75: CMakeFiles/modernC__.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/modernC__.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: modernC__] Error 2
I think, you should specify boost libraries (as components) explicitly.
And you should add libraries to target.
Like this:
find_package(Boost COMPONENTS filesystem system locale context REQUIRED)
...
target_link_libraries(${PROJECT_NAME}
...
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${Boost_LOCALE_LIBRARY}
${Boost_CONTEXT_LIBRARY}
...
)

Issue with cross-compiling using CMake and the SYSROOT path

When using CMake for crosscompiling ARM executables and setting the CMAKE_SYSROOT variable in a toolchain file, the linker does not automatically find libraries which other libraries (which were explicitly linked to) depend on, such as z and glib. When not using a toolchain file (and thus not cross-compiling) these do not need to be explicitly mentioned in target_link_libraries(), however when using the toolchain file they do or else there is always a linker error that they could not be found. I would like to understand why this is.
Brief description of my environment:
Using Linux Ubuntu 16 to compile for arm target running Ubuntu 18
Root file-system zipped from target and unzipped on development system
Linaro cross-build toolchain (7.4.1)
a toolchain file for cmake, which defines: CMAKE_SYSROOT, CMAKE_CXX_COMPILER, CMAKE_C_COMPILER and CMAKE_AR_COMPILER
Path to compiler: /home/brian/workspace/ddpx_xcompile/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu
Path to target root file system: /home/brian/workspace/ddpx_xcompile/ddpx-rootfs-05172019
I've tried many combinations of: setting the CMAKE_LIBRARY_PATH, link_directories etc. However, the only successful option seems to be adding the following inside the target_link_libraries() command: z dl glib-2.0 pcre)
Below is an example of the error message:
<path-to-toolchain>/aarch64-linux-gnu/bin/ld:
warning: libdl.so.2, needed by <path-to-sharedlib>/lib/libopencv_core.so.4.0.1, not found (try using -rpath or -rpath-link)
And this is followed by a short list of undefined functions which are within the indicated library. This error is for libdl.so.2 not found, there are others.
My error output:
/home/brian/workspace/ddpx_xcompile/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/7.4.1/../../../../aarch64-linux-gnu/bin/ld: warning: libdl.so.2, needed by /home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1, not found (try using -rpath or -rpath-link)
/home/brian/workspace/ddpx_xcompile/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/7.4.1/../../../../aarch64-linux-gnu/bin/ld: warning: libpthread.so.0, needed by /home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1, not found (try using -rpath or -rpath-link)
/home/brian/workspace/ddpx_xcompile/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/7.4.1/../../../../aarch64-linux-gnu/bin/ld: warning: libz.so.1, needed by /home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1, not found (try using -rpath or -rpath-link)
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `pthread_key_create#GLIBC_2.17'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `gzeof'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `pthread_setspecific#GLIBC_2.17'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `pthread_join#GLIBC_2.17'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `pthread_getspecific#GLIBC_2.17'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `pthread_key_delete#GLIBC_2.17'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `pthread_create#GLIBC_2.17'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `dlclose#GLIBC_2.17'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `gzrewind'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `dlopen#GLIBC_2.17'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `dladdr#GLIBC_2.17'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `gzopen'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `dlsym#GLIBC_2.17'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `gzclose'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `gzgets'
/home/brian/workspace/test/crossbuild/test_rootfs/ddpx-rootfs-05172019/home/nvidia/3rd_party_libs/opencv/install-cxx11/lib/libopencv_core.so.4.0.1: undefined reference to `gzputs'
collect2: error: ld returned 1 exit status
CMakeFiles/imshow.dir/build.make:95: recipe for target 'imshow' failed
make[2]: *** [imshow] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/imshow.dir/all' failed
make[1]: *** [CMakeFiles/imshow.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
My Cmake Toolchain file:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(TARGET_FS "/home/brian/workspace/ddpx_xcompile/ddpx-rootfs-05172019" CACHE STRING "test" FORCE)
set(CMAKE_SYSROOT ${TARGET_FS})
#Tried with and without the ${TARGET_FS} prefix, also tried with all uncommented and all commented
#link_directories(/lib/aarch64-linux-gnu)
#link_directories(/usr/lib)
#link_directories(/usr/lib/aarch64-linux-gnu)
#link_directories(${TARGET_FS}/lib/aarch64-linux-gnu)
#link_directories(${TARGET_FS}/usr/lib)
#link_directories(${TARGET_FS}/usr/lib/aarch64-linux-gnu)
#Did not try too much with these
#set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
#set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_SYSROOT}/lib/aarch64-linux-gnu)
#Tried with two different compiler versions
set(CROSSBIN /home/brian/workspace/ddpx_xcompile/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu)
#set(CROSSBIN /home/brian/workspace/ddpx_xcompile/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu)
set(CMAKE_CXX_COMPILER "${CROSSBIN}/bin/aarch64-linux-gnu-g++")
set(CMAKE_C_COMPILER "${CROSSBIN}/bin/aarch64-linux-gnu-gcc")
set(CMAKE_AR_COMPILER "${CROSSBIN}/bin/aarch64-linux-gnu-ar")
#This was also an experiment, no change
#set(CMAKE_PREFIX_PATH ${TARGET_FS})
#list(APPEND CMAKE_PREFIX_PATH ${TARGET_FS}/lib/aarch64-linux-gnu)
#list(APPEND CMAKE_PREFIX_PATH /lib/aarch64-linux-gnu)
#list(APPEND CMAKE_LIBRARY_PATH "/lib/aarch64-linux-gnu")
#list(APPEND CMAKE_LIBRARY_PATH "/usr/lib/aarch64-linux-gnu")
#Tried with the 4 below uncommented or just commented
#set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
#set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
#set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
#set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
message(STATUS "CMAKE_LIBRARY_PATH: ${CMAKE_LIBRARY_PATH}")

Undefined Reference error using OpenGL in CLion

So, I am using freeglut to try to do some openGL stuff, but I keep getting errors saying that references are undefined:
"C:\Program Files (x86)\JetBrains\CLion 2016.2.1\bin\cmake\bin\cmake.exe" --build C:\Users\Nick\.CLion2016.2\system\cmake\generated\cs455opengl-9b23e7f0\9b23e7f0\Debug --target all -- -j 4
Scanning dependencies of target cs455openGL
[ 50%] Building CXX object CMakeFiles/cs455openGL.dir/main.cpp.obj
[100%] Linking CXX executable cs455openGL.exe
CMakeFiles\cs455openGL.dir/objects.a(main.cpp.obj): In function `Z4initv':
C:/Users/Nick/ClionProjects/cs455opengl/main.cpp:12: undefined reference to `glClearColor#16'
C:/Users/Nick/ClionProjects/cs455opengl/main.cpp:13: undefined reference to `glMatrixMode#4'
C:/Users/Nick/ClionProjects/cs455opengl/main.cpp:14: undefined reference to `glLoadIdentity#0'
C:/Users/Nick/ClionProjects/cs455opengl/main.cpp:15: undefined reference to `glOrtho#48'
CMakeFiles\cs455openGL.dir/objects.a(main.cpp.obj): In function `Z7displayv':
C:/Users/Nick/ClionProjects/cs455opengl/main.cpp:20: undefined reference to `glClear#4'
C:/Users/Nick/ClionProjects/cs455opengl/main.cpp:21: undefined reference to `glColor3f#12'
C:/Users/Nick/ClionProjects/cs455opengl/main.cpp:22: undefined reference to `glVertex3f#12'
C:/Users/Nick/ClionProjects/cs455opengl/main.cpp:23: undefined reference to `glVertex3f#12'
C:/Users/Nick/ClionProjects/cs455opengl/main.cpp:24: undefined reference to `glVertex3f#12'
C:/Users/Nick/ClionProjects/cs455opengl/main.cpp:25: undefined reference to `glVertex3f#12'
C:/Users/Nick/ClionProjects/cs455opengl/main.cpp:26: undefined reference to `glEnd#0'
C:/Users/Nick/ClionProjects/cs455opengl/main.cpp:27: undefined reference to `glFlush#0'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\cs455openGL.dir\build.make:95: recipe for target 'cs455openGL.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/cs455openGL.dir/all' failed
mingw32-make.exe[2]: *** [cs455openGL.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles/cs455openGL.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
Makefile:82: recipe for target 'all' failed
I am using MinGW with CLion to do this project. I thought that I got everything correctly. I moved the appropriate files into the include folder in MinGW, as well as the bin folder, and also the lib folder. Then, I have this in my CMakeLists.txt:
cmake_minimum_required(VERSION 3.3)
project(cs455openGL)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(SOURCE_FILES main.cpp)
add_executable(cs455openGL ${SOURCE_FILES})
link_directories(${OPENGL_gl_LIBRARY})
target_link_libraries(cs455openGL libfreeglut.a libfreeglut_static.a)
The libraries I linked were the only library files that freeglut came with. I've been scouring the internet for answers and no one seems to have run into this.
So, what am I missing? CLion doesn't show any errors before it is compiled. I can even go into the functions in the header files provided by freeglut. Why then, are these functions not defined in my program?
This is a linking error, and tells you that the linker does not find the functions defined by the OpenGL library.
You have to add ${OPENGL_LIBRARIES} to target_link_libraries.
And for glut - and any other library - you should not use the library name (libfreeglut.a) directly, but always use the variables populated by the find_package:
target_link_libraries(cs455openGL ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})

Linker error while building from source code

I am trying to build an application from source. I am able to configure it using 'cmake .'. However, when I run 'make' it gives me this:
Linking CXX executable ../../bin/lux64/Release/od_batch_launcher
../../bin/lux64/Release/libBasic.so: undefined reference to `dlopen'
../../bin/lux64/Release/libBasic.so: undefined reference to `dlclose'
../../bin/lux64/Release/libBasic.so: undefined reference to `dlerror'
../../bin/lux64/Release/libBasic.so: undefined reference to `dlsym'
../../bin/lux64/Release/libBasic.so: undefined reference to `pthread_sigmask'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/lux64/Release/od_batch_launcher] Error 1
make[1]: *** [src/Basic/CMakeFiles/od_batch_launcher.dir/all] Error 2
make: *** [all] Error 2
I understand that its is unable to dynamically link to a c++ library. I don't quite know how to make the necessary changes to cmake. I am running gcc version: 4.9.2 on Linux Mint 17. I would be grateful for any help. Thank you!
Try passing -DCMAKE_EXE_LINKER_FLAGS=-ldl to the CMake executable. To change the CMake build scripts, add something like:
target_link_libraries(target_name dl)
where target_name is basically the executable name without any extensions (e.g. .exe).
EDIT: Actually, I just reread you question, and I'm putting this in the wrong place. You really want:
target_link_libraries(Basic dl)
Apparently, there were also pthread-related errors, so you'd also have to add:
target_compile_options(Basic PUBLIC -pthread)
Both of these go in whichever file contains add_library(Basic) (usually CMakeLists.txt).
EDIT 2: Instead of target_compile_options, try:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

GLFW MinGW link error

I've been attempting to test out GLFW with C++ for quite a while and am having constant linker issues. I am fairly new to C++, although I have experience in Java and C#, working directly with the compiler is fairly new to me. Here's my setup information.
IDE: Qt Creator
OS: Windows 7 64-bit
Compiler: MinGW32 4.8.1
01:23:26: Starting: "C:\MinGW\bin\mingw32-make.exe"
C:/MinGW/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'A:/workspace_cpp/Test-Debug'
g++ -Wl,-subsystem,console -mthreads -o debug\Test.exe debug/main.o -lglfw3 -lopengl32
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor.::(.text+0x2c7): undefined reference to `CreateDCW#16'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x358): undefined reference to `GetDeviceCaps#8'
Makefile.Debug:77: recipe for target 'debug\Test.exe' failed
mingw32-make[1]: Leaving directory 'A:/workspace_cpp/Test-Debug'
Makefile:34: recipe for target 'debug' failed
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x370): undefined reference to `GetDeviceCaps#8'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor .c:(.text+0x39e): undefined reference to `DeleteDC#4'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj): bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
The code I'm testing is the code on the GLFW Documentation Page, I'm using my own build of GLFW, and have already tried this and several other potential solutions. I have tried using the prebuilt GLFW mingw libraries but I couldn't get them to work.
The solution as posted by enhzflep was to include to gdi32 library when compiling, making all the necessary linkers -lglfw3 -lgdi32 -lopengl32, as the missing methods, CreateDCW, GetDeviceCaps and DeleteDC are all inside of libgdi32.a in the MinGW lib folder C:\MinGW\lib\libgdi32.a in this case.