I want to build an executable that includes all of libs that I used (opencv, dlib) so it can work on any computer.
Here is my current CMakeList.txt
cmake_minimum_required(VERSION 3.5.1)
project(adc_fr)
set(CMAKE_CXX_STANDARD 14)
add_subdirectory(/media/sf_dlib-19.9/dlib dlib_build)
FIND_PACKAGE(OpenCV REQUIRED)
set(SOURCE_FILES
FDetect.cpp
FDetect.h
FExtract.cpp
FExtract.h
main.cpp
)
add_executable(adc_fr ${SOURCE_FILES})
set_target_properties(adc_fr PROPERTIES LINK_FLAGS "-static")
target_link_libraries(adc_fr
${OpenCV_LIBS}
dlib
)
Here is the error I got when linking
/usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libwebp.so'
collect2: error: ld returned 1 exit status
CMakeFiles/adc_fr.dir/build.make:409: recipe for target 'adc_fr' failed
make[2]: *** [adc_fr] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/adc_fr.dir/all' failed
make[1]: *** [CMakeFiles/adc_fr.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I do have libwebp.a available in /usr/lib/x86_64-linux-gnu/
How can I force to use static libwebp.a instead of libwebp.so?
I did try to add #SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") but it still gave the same error.
Much appreciated!
How about this:
find_library(LIBWEBP_LOCATION libwebp.a)
target_link_libraries(adc_fr
${OpenCV_LIBS}
dlib
${LIBWEBP_LOCATION}
)
Related
I have been pulling out of my hair because of CMakelists.txt. I would like to create a C++ application with GLFW, GLEW libraries, using MinGW and CLion IDE.
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.17.3)
project(imguiTask)
set(CMAKE_CXX_STANDARD 17)
add_compile_options(-DGLEW_NO_GLU)
add_executable(${PROJECT_NAME}
src/main.cpp
src/imgui.cpp
src/imgui_draw.cpp
src/imgui_widgets.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC includes)
add_library(libraries STATIC IMPORTED)
target_link_libraries(${PROJECT_NAME} glfw3)
I placed the needed libraries in the libraries folder as you can see in the picture. The folder is located in the project root. It is giving me the following error:
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -lglfw3
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [imguiTask.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/imguiTask.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/imguiTask.dir/rule] Error 2
mingw32-make.exe: *** [imguiTask] Error 2
It seeems to me, that it does not search in the folder I specified. I don't know why.
I've been trying to get SDL2 to link with my project but I think my cmake file is no good. I get this error
====================[ Build | Chip_8_Interpreter | Debug ]======================
"C:\Program Files\JetBrains\CLion 2018.3.4\bin\cmake\win\bin\cmake.exe" --build "D:\Dropbox\Programming\Chip-8 Interpreter\cmake-build-debug" --target Chip_8_Interpreter -- -j 4
[ 50%] Linking CXX executable Chip_8_Interpreter.exe
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Chip_8_Interpreter.exe] Error 1
CMakeFiles\Chip_8_Interpreter.dir\build.make:87: recipe for target 'Chip_8_Interpreter.exe' failed
mingw32-make.exe[2]: *** [CMakeFiles/Chip_8_Interpreter.dir/all] Error 2
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/Chip_8_Interpreter.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/Chip_8_Interpreter.dir/rule] Error 2
CMakeFiles\Makefile2:83: recipe for target 'CMakeFiles/Chip_8_Interpreter.dir/rule' failed
mingw32-make.exe: *** [Chip_8_Interpreter] Error 2
Makefile:117: recipe for target 'Chip_8_Interpreter' failed
And currently my CMakeLists.txt looks like this
cmake_minimum_required(VERSION 3.14)
project(Chip_8_Interpreter)
set(CMAKE_CXX_STANDARD 14)
# include cmake/FindSDL2.cmake
set(SDL2_PATH "C:\\SDL2-2.0.12\\i686-w64-mingw32")
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
add_executable(Chip_8_Interpreter main.cpp)
target_link_libraries(Chip_8_Interpreter ${SDL2_LIBRARY} -lmingw32 -lSDL2main -lSDL2 -mwindows)
And my main.cpp is just the basic SDL example. I've also recently installed MinGW and SDL2, so they should both be the newest stable release.
As part of a project I'm working on, I need to make use of the WebKitGTK+ library.
I downloaded the library (tarball) and compiled it as described here.
After the compilation was done:
The lib's headers are in /usr/local/include.
The lib's .so files are in /usr/local/lib.
In my C++ project I tried to add the following CMakeLists.txt file:
cmake_minimum_required(VERSION 3.7)
project(CVE_2016_4657)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(CVE_2016_4657 ${SOURCE_FILES})
find_package(PkgConfig REQUIRED)
include_directories(/usr/local/include/webkitgtk-4.0)
link_directories(/usr/local/lib/webkit2gtk-4.0)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER})
pkg_check_modules(SOUP REQUIRED libsoup-2.4)
include_directories(${SOUP_INCLUDE_DIRS})
link_directories(${SOUP_LIBRARY_DIRS})
add_definitions(${SOUP_CFLAGS_OTHER})
target_link_libraries(
CVE_2016_4657
${GTK3_LIBRARIES}
${SOUP_LIBRARIES})
However, when compiling the project I'm getting the following error:
[ 50%] Linking CXX executable CVE_2016_4657
CMakeFiles/CVE_2016_4657.dir/main.cpp.o: In function `main':
/home/idanas/CLionProjects/Switcheroo/main.cpp:17: undefined reference to
`webkit_web_view_get_type'
/home/idanas/CLionProjects/Switcheroo/main.cpp:17: undefined reference to
`webkit_web_view_new'
/home/idanas/CLionProjects/Switcheroo/main.cpp:29: undefined reference to
`webkit_web_view_load_uri'
collect2: error: ld returned 1 exit status
CMakeFiles/CVE_2016_4657.dir/build.make:94: recipe for target
'CVE_2016_4657' failed
make[3]: *** [CVE_2016_4657] Error 1
CMakeFiles/Makefile2:67: recipe for target
'CMakeFiles/CVE_2016_4657.dir/all' failed
make[2]: *** [CMakeFiles/CVE_2016_4657.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target
'CMakeFiles/CVE_2016_4657.dir/rule' failed
make[1]: *** [CMakeFiles/CVE_2016_4657.dir/rule] Error 2
Makefile:118: recipe for target 'CVE_2016_4657' failed
make: *** [CVE_2016_4657] Error 2
I have little-to-none experience with CMake and could really use some help.
You are trying to use WebKitGTK+, which is a separate library from both GTK+ and libsoup. You will need to duplicate your pkg_check_modules() code again for WebKitGTK+. You'll need to determine first if you are using WebKit1 or WebKit2 (they have subtly different APIs), and then find the appropriate pkg-config name for that version of WebKitGTK+; check the documentation and the contents of your /usr/lib/pkgconfig directory.
I have Clion IDE on Kubuntu 15.04. I have problem, when i build my application there is this problem :
/home/pierre/Bureau/CLion/bin/cmake/bin/cmake --build /home/pierre/.CLion12/system/cmake/generated/2a804d19/2a804d19/Debug --target WCPLauncher -- -j 4
Scanning dependencies of target WCPLauncher
[ 50%] Linking CXX executable WCPLauncher
/home/pierre/Qt5.0.2/5.0.2/gcc/lib/libQt5Widgets.so.5.0.2: error adding symbols: Fichier dans un mauvais format
collect2: error: ld returned 1 exit status
CMakeFiles/WCPLauncher.dir/build.make:97: recipe for target 'WCPLauncher' failed
make[3]: *** [WCPLauncher] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/WCPLauncher.dir/all' failed
make[2]: *** [CMakeFiles/WCPLauncher.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/WCPLauncher.dir/rule' failed
make[1]: *** [CMakeFiles/WCPLauncher.dir/rule] Error 2
Makefile:118: recipe for target 'WCPLauncher' failed
make: *** [WCPLauncher] Error 2
This is my cmake.txt :
cmake_minimum_required(VERSION 3.2)
project(WCPLauncher)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(WCPLauncher ${SOURCE_FILES})
find_package( Qt5Core REQUIRED )
find_package( Qt5Widgets REQUIRED )
find_package( Qt5Gui REQUIRED )
qt5_use_modules( WCPLauncher Core Widgets Gui )
Thanks !
I've been at this for a few hours now, and feeling rather stupid. The library in question is spdlog, which is just a whole bunch of headers. I am using CMake and cygwin to compile.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.3)
project(spdlog_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include_directories(E:/Dev/libraries/spdlog)
link_directories(E:/Dev/libraries/spdlog)
set(SOURCE_FILES main.cpp)
add_executable(spdlog_test ${SOURCE_FILES})
target_link_libraries(spdlog_test spdlog)
All the paths are definetely correct.
Output when building:
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lspdlog
collect2: error: ld returned 1 exit status
CMakeFiles/spdlog_test.dir/build.make:94: recipe for target 'spdlog_test.exe' failed
make[2]: *** [spdlog_test.exe] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/spdlog_test.dir/all' failed
make[1]: *** [CMakeFiles/spdlog_test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2