What causes the following linking error with CMake and Imagemagick library? - cmake

I have a main.cpp file that includes a header file from the same directory where I have used the boost library, magickimage c++ library, and eigen library. Here is my CMakeLists.txt file where I have linked the .lib and .a files to my target and set the includer paths.
cmake_minimum_required(VERSION 3.20.2)
project(blackjackAI)
add_executable(blackjackAI main.cpp)
target_link_libraries(blackjackAI PRIVATE C:/Users/Ejer/Desktop/c++/c++Dep/boost_1_77_0/stage/lib/libboost_filesystem-gcc10-mt-x64-1_77.a)
target_link_libraries(blackjackAI PRIVATE C:/Users/Ejer/Desktop/c++/c++Dep/ImageMagick-7.1.0-Q16-HDRI/lib/CORE_RL_Magick++_.lib)
target_link_libraries(blackjackAI PRIVATE C:/Users/Ejer/Desktop/c++/c++Dep/ImageMagick-7.1.0-Q16-HDRI/lib/CORE_RL_MagickCore_.lib)
target_link_libraries(blackjackAI PRIVATE C:/Users/Ejer/Desktop/c++/c++Dep/ImageMagick-7.1.0-Q16-HDRI/lib/CORE_RL_MagickWand_.lib)
target_include_directories(blackjackAI PRIVATE C:/Users/Ejer/Desktop/c++/c++Dep/ImageMagick-7.1.0-Q16-HDRI/include)
target_include_directories(blackjackAI PRIVATE C:/Users/Ejer/Desktop/c++/c++Dep/eigen-3.4.0)
target_include_directories(blackjackAI PRIVATE C:/Users/Ejer/Desktop/c++/c++Dep/boost_1_77_0)
target_include_directories(blackjackAI PRIVATE C:/Users/Ejer/Desktop/c++/blackjackAI)
For some reason when I compile my CMakeLists.txt file with the "MinGW Makefiles" generator and then use the makefile I get the following linker error:
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles\blackjackAI.dir/objects.a(main.cpp.obj):C:\Users\Ejer
\Desktop\c++\blackjackAI\main.cpp:(.text$_ZN6CnnNetC1ESs[_ZN6CnnNetC1ESs]+0x3dd): undefined reference to `Magick::Image::Image()'
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles\blackjackAI.dir/objects.a(main.cpp.obj):C:\Users\Ejer
\Desktop\c++\blackjackAI\main.cpp:(.text$_ZN6CnnNetC1ESs[_ZN6CnnNetC1ESs]+0x413): undefined reference to `Magick::Image::read(std::str
ing const&)'
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles\blackjackAI.dir/objects.a(main.cpp.obj):C:\Users\Ejer
\Desktop\c++\blackjackAI\main.cpp:(.text$_ZN6CnnNetC1ESs[_ZN6CnnNetC1ESs]+0x436): undefined reference to `Magick::Image::type(MagickCo
re::ImageType)'
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles\blackjackAI.dir/objects.a(main.cpp.obj):C:\Users\Ejer
\Desktop\c++\blackjackAI\main.cpp:(.text$_ZN6CnnNetC1ESs[_ZN6CnnNetC1ESs]+0x45b): undefined reference to `Magick::Image::~Image()'
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles\blackjackAI.dir/objects.a(main.cpp.obj):C:\Users\Ejer
\Desktop\c++\blackjackAI\main.cpp:(.text$_ZN6CnnNetC1ESs[_ZN6CnnNetC1ESs]+0x539): undefined reference to `Magick::Image::~Image()'
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles\blackjackAI.dir/objects.a(main.cpp.obj):C:\Users\Ejer
\Desktop\c++\blackjackAI\main.cpp:(.text$_ZN9__gnu_cxx13new_allocatorIN6Magick5ImageEE9constructIS2_JRKS2_EEEvPT_DpOT0_[_ZN9__gnu_cxx1
3new_allocatorIN6Magick5ImageEE9constructIS2_JRKS2_EEEvPT_DpOT0_]+0x46): undefined reference to `Magick::Image::Image(Magick::Image co
nst&)'
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles\blackjackAI.dir/objects.a(main.cpp.obj):C:\Users\Ejer
\Desktop\c++\blackjackAI\main.cpp:(.text$_ZSt10_ConstructIN6Magick5ImageEJRKS1_EEvPT_DpOT0_[_ZSt10_ConstructIN6Magick5ImageEJRKS1_EEvP
T_DpOT0_]+0x42): undefined reference to `Magick::Image::Image(Magick::Image const&)'
collect2: error: ld returned 1 exit status
CMakeFiles\blackjackAI.dir\build.make:102: recipe for target 'blackjackAI.exe' failed
mingw32-make[2]: *** [blackjackAI.exe] Error 1
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/blackjackAI.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/blackjackAI.dir/all] Error 2
Makefile:89: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
It says that I have undefined references to the use of the Image class in my header file, even though I have linked my includer path and .lib files in CMakeLists.txt file and my main.cpp file to the imagemagick library. What is causing the problem?

Related

How to add Paho Mqtt C and Cpp libraries to a CMakeLists.txt

I am trying to build a cpp project using CMakeLists.txt.
I installed both Paho Mqtt C and Cpp and their Config.cmake can be found at /usr/local/lib/cmake/eclipse-paho-mqtt-c/eclipse-paho-mqtt-cConfig.cmake and /usr/local/lib/cmake/PahoMqttCpp/PahoMqttCppConfig.cmake in my system.
I am trying to compile the async_publish.cpp. For now I could only get it built running the following CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project("Mqtt Test")
#find_package(PahoMqttCpp REQUIRED)
#find_package(eclipse-paho-mqtt-c REQUIRED)
add_executable(mqtt_client mqtt_client.cpp)
target_link_libraries(mqtt_client pthread crypto ssl paho-mqtt3as paho-mqttpp3)
The problem is ... how do I get the libraries from find_package() and pick the right ${whatever_pkg_LIB} and maybe include files?
I tried
target_link_libraries(mqtt_client pthread crypto ssl ${PAHO_MQTT_C_LIBRARIES} ${PAHO_MQTT_CPP_LIBRARIES})
but it didn't work. I got the following error
CMakeFiles/mqtt_client.dir/mqtt_client.cpp.o: In function `main':
mqtt_client.cpp:(.text+0x3ae): undefined reference to `mqtt::async_client::async_client(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, mqtt::iclient_persistence*)'
mqtt_client.cpp:(.text+0x401): undefined reference to `mqtt::async_client::set_connected_handler(std::function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>)'
mqtt_client.cpp:(.text+0x445): undefined reference to `mqtt::async_client::set_connection_lost_handler(std::function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>)'
mqtt_client.cpp:(.text+0x463): undefined reference to `mqtt::connect_options::connect_options()'
mqtt_client.cpp:(.text+0x4b7): undefined reference to `mqtt::message::message(mqtt::buffer_ref<char>, mqtt::buffer_ref<char>, int, bool)'
mqtt_client.cpp:(.text+0x4ee): undefined reference to `mqtt::will_options::will_options(mqtt::message const&)'
mqtt_client.cpp:(.text+0x507): undefined reference to `mqtt::connect_options::set_will(mqtt::will_options const&)'
mqtt_client.cpp:(.text+0x520): undefined reference to `mqtt::connect_options::set_automatic_reconnect(int, int)'
mqtt_client.cpp:(.text+0x561): undefined reference to `mqtt::connect_options::connect_options(mqtt::connect_options const&)'
mqtt_client.cpp:(.text+0x581): undefined reference to `mqtt::async_client::connect(mqtt::connect_options)'
mqtt_client.cpp:(.text+0x6d1): undefined reference to `mqtt::topic::publish(mqtt::buffer_ref<char>)'
mqtt_client.cpp:(.text+0x798): undefined reference to `mqtt::topic::publish(mqtt::buffer_ref<char>)'
mqtt_client.cpp:(.text+0x8d9): undefined reference to `mqtt::async_client::~async_client()'
mqtt_client.cpp:(.text+0xb9c): undefined reference to `mqtt::async_client::~async_client()'
CMakeFiles/mqtt_client.dir/mqtt_client.cpp.o: In function `mqtt::async_client::disconnect()':
mqtt_client.cpp:(.text._ZN4mqtt12async_client10disconnectEv[_ZN4mqtt12async_client10disconnectEv]+0x45): undefined reference to `mqtt::disconnect_options::disconnect_options()'
collect2: error: ld returned 1 exit status
CMakeFiles/mqtt_client.dir/build.make:95: recipe for target 'mqtt_client' failed
make[2]: *** [mqtt_client] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/mqtt_client.dir/all' failed
make[1]: *** [CMakeFiles/mqtt_client.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
this is the CMakeLists.txt I use to make my project
cmake_minimum_required(VERSION 3.1) set(CMAKE_CXX_STANDARD 20)
project(Farm_interface)
include_directories(${PROJECT_SOURCE_DIR}/include)
add_executable(Farm.exe src/main.cpp src/subscriber.cpp)
target_link_libraries( Farm.exe paho-mqttpp3 paho-mqtt3as pthread)

SDL2 Cmake undefined reference to `WinMain#16' on Win10 MinGW

I am trying to set up SDL in CLion with MinGW, but I get errors after errors, and I just can't imagine where do I go wrong. Now I have this Cmake code, and I get the error undefined reference to 'WinMain#16' . I suppose I forget to link something, probably SDLmain, but I think I wrote it there in the target_link_libraries(). I would greatly appreciate some help to make it work.
cmake_minimum_required(VERSION 3.15)
project(SDL_project)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
add_executable(SDL_project main.cpp)
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARY} -lmingw32 -lSDL2main -lSDL2 -mwindows)
The error message:
====================[ Build | SDL_project | Debug ]=============================
"A:\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" --build D:\SDL_project\cmake-build-debug --target SDL_project -- -j 4
Scanning dependencies of target SDL_project
[ 50%] Building CXX object CMakeFiles/SDL_project.dir/main.cpp.obj
[100%] Linking CXX executable SDL_project.exe
A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o): in function `main':
D:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\SDL_project.dir\build.make:86: recipe for target 'SDL_project.exe' failed
CMakeFiles\Makefile2:74: recipe for target 'CMakeFiles/SDL_project.dir/all' failed
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/SDL_project.dir/rule' failed
mingw32-make.exe[3]: *** [SDL_project.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/SDL_project.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/SDL_project.dir/rule] Error 2
mingw32-make.exe: *** [SDL_project] Error 2
Makefile:117: recipe for target 'SDL_project' failed
And I also made a cmake folder in the project folder, for the SDL find, but I am not sure if it is necessary.
set(FIND_SDL2_PATHS D:/SDL2/SDL2-devel-2.0.12-mingw/SDL2-2.0.12/x86_64-w64-mingw32)
find_path(SDL2_INCLUDE_DIR SDL2
PATH_SUFFIXES include
PATHS ${FIND_SDL2_PATHS})
find_library(SDL2_LIBRARY
NAMES SDL2
PATH_SUFFIXES lib
PATHS ${FIND_SDL2_PATHS})
The solution was to add a new line to the end: add_definitions(-DSDL_MAIN_HANDLED).
Now the CMakeLists.txt code looks like this:
cmake_minimum_required(VERSION 3.15)
project(SDL_project)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
add_executable(SDL_project main.cpp)
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARY} -lmingw32 -mwindows)
add_definitions(-DSDL_MAIN_HANDLED)
And in the project folder in a separete folder called cmake there is the FindSDL2.cmake file, to locate SDL2:
set(FIND_SDL2_PATHS D:/SDL2/SDL2-devel-2.0.12-mingw/SDL2-2.0.12/x86_64-w64-mingw32)
find_path(SDL2_INCLUDE_DIR SDL2
PATH_SUFFIXES include
PATHS ${FIND_SDL2_PATHS})
find_library(SDL2_LIBRARY
NAMES SDL2 SDL2main
PATH_SUFFIXES lib
PATHS ${FIND_SDL2_PATHS})
From the CMakeLists.txt I removed -lSDL2 and -lSDL2main flags, because they resulted in errors:
====================[ Build | SDL_project | Debug ]=============================
"A:\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" --build D:\SDL_project\cmake-build-debug --target SDL_project -- -j 4
[ 50%] Linking CXX executable SDL_project.exe
A:/MSYS2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2
A:/MSYS2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2main
collect2.exe: error: ld returned 1 exit status
CMakeFiles\SDL_project.dir\build.make:86: recipe for target 'SDL_project.exe' failed
CMakeFiles\Makefile2:74: recipe for target 'CMakeFiles/SDL_project.dir/all' failed
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/SDL_project.dir/rule' failed
Makefile:117: recipe for target 'SDL_project' failed
mingw32-make.exe[3]: *** [SDL_project.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/SDL_project.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/SDL_project.dir/rule] Error 2
mingw32-make.exe: *** [SDL_project] Error 2
Also, it is important to use 64-bit mingw-w64, because mingw-w32 also gives errors, like:
====================[ Build | SDL_project | Debug ]=============================
"A:\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" --build D:\SDL_project\cmake-build-debug --target SDL_project -- -j 4
[ 50%] Linking CXX executable SDL_project.exe
A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\SDL_project.dir/objects.a(main.cpp.obj):D:/SDL_project/main.cpp:17: undefined reference to `SDL_Init'
A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\SDL_project.dir/objects.a(main.cpp.obj): in function `main':
D:/SDL_project/main.cpp:19: undefined reference to `SDL_GetError'
A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: D:/SDL_project/main.cpp:24: undefined reference to `SDL_CreateWindow'
A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: D:/SDL_project/main.cpp:27: undefined reference to `SDL_GetError'
A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: D:/SDL_project/main.cpp:32: undefined reference to `SDL_GetWindowSurface'
A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: D:/SDL_project/main.cpp:35: undefined reference to `SDL_MapRGB'
A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: D:/SDL_project/main.cpp:35: undefined reference to `SDL_FillRect'
A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: D:/SDL_project/main.cpp:38: undefined reference to `SDL_UpdateWindowSurface'
A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: D:/SDL_project/main.cpp:41: undefined reference to `SDL_Delay'
A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: D:/SDL_project/main.cpp:45: undefined reference to `SDL_DestroyWindow'
A:/MSYS2/mingw32/bin/../lib/gcc/i686-w64-mingw32/9.3.0/../../../../i686-w64-mingw32/bin/ld.exe: D:/SDL_project/main.cpp:48: undefined reference to `SDL_Quit'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\SDL_project.dir\build.make:86: recipe for target 'SDL_project.exe' failed
CMakeFiles\Makefile2:74: recipe for target 'CMakeFiles/SDL_project.dir/all' failed
CMakeFiles\Makefile2:81: recipe for target 'CMakeFiles/SDL_project.dir/rule' failed
Makefile:117: recipe for target 'SDL_project' failed
mingw32-make.exe[3]: *** [SDL_project.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/SDL_project.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/SDL_project.dir/rule] Error 2
mingw32-make.exe: *** [SDL_project] Error 2
And, the SDL.dll file from the binary folder has to be added to the compiler, to avoid exit code -1073741515 (0xC0000135). It can be done by setting a path to the folder, or by copying the SDL.dll from the SDL\bin folder to the mingw64\bin folder.

How do I solve GATE building file make error

I am installing gate on centOS 7. Almost finish all installation besides a little error when I try to build installation file in build directory before final installation, make install. Here is the command line response:
100%] Building CXX object CMakeFiles/Gate.dir/source/physics/src/GateXrayBoundaryPB.cc.o
[100%] Building CXX object CMakeFiles/Gate.dir/source/physics/src/GateeMultipleScatteringPB.cc.o
[100%] Building CXX object CMakeFiles/Gate.dir/source/physics/src/GatehMultipleScatteringPB.cc.o
[100%] Linking CXX executable Gate
/usr/bin/ld: warning: libtbb.so.2, needed by /home/xincao/GATE/root_v6.18/lib/libImt.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libvdt.so, needed by /home/xincao/GATE/root_v6.18/lib/libROOTVecOps.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libRDAVIX.so.6.18, needed by /home/xincao/GATE/root_v6.18/lib/libROOTDataFrame.so, not found (try using -rpath or -rpath-link)
/home/xincao/GATE/root_v6.18/lib/libROOTDataFrame.so: undefined reference to `Davix::DavPosix::pread(Davix_fd*, void*, unsigned long, long, Davix::DavixError**)'
/home/xincao/GATE/root_v6.18/lib/libImt.so: undefined reference to `tbb::task_scheduler_init::initialize(int)'
/home/xincao/GATE/root_v6.18/lib/libImt.so: undefined reference to `tbb::task::note_affinity(unsigned short)'
/home/xincao/GATE/root_v6.18/lib/libImt.so: undefined reference to `tbb::internal::throw_exception_v4(tbb::internal::exception_id)'
/home/xincao/GATE/root_v6.18/lib/libImt.so: undefined reference to `tbb::task_group_context::is_group_execution_cancelled() const'
/home/xincao/GATE/root_v6.18/lib/libImt.so: undefined reference to `vtable for tbb::task'
/home/xincao/GATE/root_v6.18/lib/libImt.so: undefined reference to `tbb::task_group_context::reset()'
/home/xincao/GATE/root_v6.18/lib/libImt.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_terminate()'
...
/home/xincao/GATE/root_v6.18/lib/libROOTDataFrame.so: undefined reference to `Davix::DavPosix::stat(Davix::RequestParams const*, std::string const&, stat*, Davix::DavixError**)'
/home/xincao/GATE/root_v6.18/lib/libROOTDataFrame.so: undefined reference to `Davix::DavixError::getErrMsg() const'
/home/xincao/GATE/root_v6.18/lib/libImt.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const'
/home/xincao/GATE/root_v6.18/lib/libROOTDataFrame.so: undefined reference to `Davix::Context::~Context()'
/home/xincao/GATE/root_v6.18/lib/libImt.so: undefined reference to `tbb::internal::allocate_root_with_context_proxy::allocate(unsigned long) const'
collect2: error: ld returned 1 exit status
make[2]: *** [Gate] Error 1
make[1]: *** [CMakeFiles/Gate.dir/all] Error 2
make: *** [all] Error 2
Does anyone can help? Any reply will be highly appreciated!!
Thanks!
It is because the geant4.sh script in the Geant4 bin has not been run. This sets up the LD_LIBRARY_PATH variable which then allows these libraries to be found. (Note that you will need the data from CERN in order to successfully run geant4.sh)

Adding libconfig++ to CMake

I'm trying to add libconfig++ to my CMake project, but it still complains
Libconfig library is config++
...
CMakeFiles/CustomCamReaderTask.dir/acA2440-20gc_ConfigUtility.cc.o: undefined reference to symbol '_ZN13ConfigSection3getERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERl'
.../lib/libconfig.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Here is my CMakeLists.txt
find_package(PkgConfig)
pkg_check_modules(LIBCONFIG_PLUSPLUS libconfig++ REQUIRED)
add_executable(CustomCamReaderTask
CustomCamReaderTask.cc
acA2440-20gc_ConfigUtility.cc)
target_include_directories(CustomCamReaderTask
PRIVATE ${CMAKE_SOURCE_DIR}/src/include/Pylon5
/opt/pylon5/include)
message("Libconfig library is ${LIBCONFIG_PLUSPLUS_LIBRARIES}")
target_link_libraries(CustomCamReaderTask
${LIBCONFIG_PLUSPLUS_LIBRARIES}
${PYLON_LIBS}
task
imageUtility
${OPENCV_LIBRARIES})
link_directories(/opt/pylon5/lib64)
link_libraries(${LIBCONFIG_PLUSPLUS_LIBRARIES})
It seems to find config++, I linked the directory, linked the library, not sure what else is wrong..

cmake on windows. Link libraries in folder

Disclaimer: I'm new to cmake so i have no idea what I'm doing.
All guides and tutorials i find seem to think I'm running a 20 man team that needs to work together.
All I'm trying to do is put all my libraries in an include folder and lib folder.
In visual studio and code::blocks i just set up the linker in the IDE, but cmake is a little hard for me to wrap my head around.
I've set include and link directories with
include_directories(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)
Then i try to
target_link_libraries(${PROJECT_NAME} jsoncpp)
This however produces undefined references. Is there a simple way to add and link libraries without me having to google and add a cmake module for each one?
Edit:
attempts:
target_link_libraries(${PROJECT_NAME} libjsoncpp.a)
error: undefined reference
target_link_libraries(${PROJECT_NAME} libjsoncpp)
error: cannot find -llibjsoncpp
target_link_libraries(${PROJECT_NAME} jsoncpp)
error: undefined reference
target_link_libraries(${PROJECT_NAME} C:/Repos/prosjekt-bad-racoon/lib/libjsoncpp.a)
error: undefined reference
target_link_libraries(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/lib/libjsoncpp.a)
error: undefined reference
Edit:
Full cmake file
cmake_minimum_required(VERSION 3.8)
project(prosjekt_bad_racoon)
set(CMAKE_CXX_STANDARD 11)
include_directories(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)
set(SOURCE_FILES main.cpp Core.cpp Core.h Collider.cpp Collider.h Player.cpp Player.h Texture.cpp Texture.h AudioController.cpp AudioController.h)
add_executable(prosjekt_bad_racoon ${SOURCE_FILES})
set(EXECUTABLE_NAME ${PROJECT_NAME})
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
target_link_libraries(${PROJECT_NAME} libjsoncpp.a)
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
link_directories("${PROJECT_SOURCE_DIR}")
endif()
"C:\Program Files\JetBrains\CLion 2017.2.2\bin\cmake\bin\cmake.exe" --build C:\Repos\prosjekt-bad-racoon\cmake-build-debug --target prosjekt_bad_racoon -- -j 2
[ 14%] Linking CXX executable prosjekt_bad_racoon.exe
CMakeFiles\prosjekt_bad_racoon.dir/objects.a(Core.cpp.obj): In function `ZN4CoreC2Ev':
C:/Repos/prosjekt-bad-racoon/Core.cpp:3: undefined reference to `Json::Value::Value(char const*)'
CMakeFiles\prosjekt_bad_racoon.dir/objects.a(Core.cpp.obj): In function `ZN4CoreD2Ev':
C:/Repos/prosjekt-bad-racoon/Core.cpp:8: undefined reference to `Json::Value::~Value()'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\prosjekt_bad_racoon.dir\build.make:236: recipe for target 'prosjekt_bad_racoon.exe' failed
mingw32-make.exe[3]: *** [prosjekt_bad_racoon.exe] Error 1
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/prosjekt_bad_racoon.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/prosjekt_bad_racoon.dir/all] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/prosjekt_bad_racoon.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/prosjekt_bad_racoon.dir/rule] Error 2
Makefile:117: recipe for target 'prosjekt_bad_racoon' failed
mingw32-make.exe: *** [prosjekt_bad_racoon] Error 2