I have two git repositories with CMake, one is a game engine, and the other is a game that I am making with the game engine.
It turns out, this game engine has a submodule that is included in the project's CMakeLists.txt, and in the game repository, the game engine is added as a submodule that is also included in CMakeLists.txt. However, when compiling the two projects, the Game Engine compiles everything normal without errors, I update the game repository to update the submodules, and when compiling the game, it does not find the game engine submodule for some unknown reason.
Game Engine CMakeLists:
cmake_minimum_required(VERSION 3.8)
set(PROJECT_NAME "Enel")
set(CMAKE_CXX_STANDARD 17)
project(${PROJECT_NAME} VERSION 0.1.0)
include_directories(
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/libs/spdlog/include"
"${PROJECT_SOURCE_DIR}/libs/spdlog/src"
)
file(GLOB SRC_FILES
"${PROJECT_SOURCE_DIR}/include/**/*.h"
"${PROJECT_SOURCE_DIR}/include/**/*.hh"
"${PROJECT_SOURCE_DIR}/include/**/*.hpp"
"${PROJECT_SOURCE_DIR}/src/**/*.c"
"${PROJECT_SOURCE_DIR}/src/**/*.cc"
"${PROJECT_SOURCE_DIR}/src/**/*.cpp"
)
add_library(${PROJECT_NAME} STATIC ${SRC_FILES})
Game CMakeLists:
cmake_minimum_required(VERSION 3.8)
set(PROJECT_NAME "Minicraft")
set(CMAKE_CXX_STANDARD 17)
project(${PROJECT_NAME} VERSION 0.1.0)
include_directories(
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/libs/enel/include"
"${PROJECT_SOURCE_DIR}/libs/enel/src"
)
link_directories(${PROJECT_SOURCE_DIR}/libs/enel)
file(GLOB SRC_FILES
"${PROJECT_SOURCE_DIR}/include/**/*.h"
"${PROJECT_SOURCE_DIR}/include/**/*.hh"
"${PROJECT_SOURCE_DIR}/include/**/*.hpp"
"${PROJECT_SOURCE_DIR}/src/**/*.c"
"${PROJECT_SOURCE_DIR}/src/**/*.cc"
"${PROJECT_SOURCE_DIR}/src/**/*.cpp"
"${PROJECT_SOURCE_DIR}/libs/enel/src/**/*.c"
"${PROJECT_SOURCE_DIR}/libs/enel/src/**/*.cc"
"${PROJECT_SOURCE_DIR}/libs/enel/src/**/*.cpp"
"${PROJECT_SOURCE_DIR}/libs/enel/include/**/*.h"
"${PROJECT_SOURCE_DIR}/libs/enel/include/**/*.hh"
"${PROJECT_SOURCE_DIR}/libs/enel/include/**/*.hpp"
)
add_executable(${PROJECT_NAME} ${SRC_FILES})
Build Output:
[ 33%] Building CXX object CMakeFiles/Minicraft.dir/src/MC/Game.cc.o
In file included from /home/yorichii/repos/minicraft/libs/enel/include/Enel/Platform/EntryPoint.hh:4,
from /home/yorichii/repos/minicraft/src/MC/Game.cc:2:
/home/yorichii/repos/minicraft/libs/enel/include/Enel/Util/Log.hh:3:10: fatal error: spdlog/spdlog.h: Arquivo ou diretório inexistente
3 | #include <spdlog/spdlog.h>
| ^~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/Minicraft.dir/build.make:76: CMakeFiles/Minicraft.dir/src/MC/Game.cc.o] Erro 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/Minicraft.dir/all] Erro 2
make: *** [Makefile:84: all] Erro 2
If you use directory based property like include_directory or link_directory, you'll have to repeat requirements:
include_directories(
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/libs/enel/include"
"${PROJECT_SOURCE_DIR}/libs/enel/src"
# Repeat all requirements
"${PROJECT_SOURCE_DIR}/libs/enel/libs/spdlog/include"
"${PROJECT_SOURCE_DIR}/libs/enel/libs/spdlog/src"
)
This is why you should strongly consider target based property, as all modern build system are using, including modern CMake:
In Enel:
cmake_minimum_required(VERSION 3.8)
set(PROJECT_NAME "Enel")
set(CMAKE_CXX_STANDARD 17)
project(${PROJECT_NAME} VERSION 0.1.0)
# If you can install spdlog in a local directory in the project,
# prefer find_package(spdlog REQUIRED)
add_subdirectrory(libs/spdlog)
file(GLOB SRC_FILES
"strongly/consider/not/globbing/**/*.cpp"
)
add_library(Enel STATIC ${SRC_FILES})
target_link_libraries(Enel PUBLIC spdlog)
target_include_directories(Enel PUBLIC src include)
Then in your game, do this:
cmake_minimum_required(VERSION 3.8)
set(PROJECT_NAME "Minicraft")
set(CMAKE_CXX_STANDARD 17)
project(${PROJECT_NAME} VERSION 0.1.0)
add_subdirectory(libs/enel)
file(GLOB SRC_FILES
...
)
add_executable(Minicraft ${SRC_FILES})
# Links to all required libraries, add all required include directories
target_link_libraries(Minicraft PUBLIC Enel)
target_include_directory(Minicraft PUBLIC include src)
Related
I built Open3D from source into a /home/user/custom_location/Open3D/build
I have a project with a dependency on Open3D and a CMakeLists.txt like this:
cmake_minimum_required(VERSION 3.12)
project(graph_filter)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)
# Pybind11
find_package(pybind11 REQUIRED)
# OpenMP
find_package(OpenMP REQUIRED)
# Eigen
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
# Open3D
list(APPEND CMAKE_INSTALL_PREFIX "~/libraries/")
find_package(Open3D HINTS ${CMAKE_INSTALL_PREFIX}/lib/CMake)
list(APPEND Open3D_LIBRARIES dl)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Open3D_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${Open3D_EXE_LINKER_FLAGS}")
include_directories(${Open3D_INCLUDE_DIRS})
link_directories(${Open3D_LIBRARY_DIRS})
pybind11_add_module(
graph_filter
wrapper.cpp
)
target_link_libraries(graph_filter PRIVATE ${Open3D_LIBRARIES} Eigen3::Eigen OpenMP::OpenMP_CXX)
How can I link it? When I run
INSTALL_DIR=/home/user/custom_location/Open3D/build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}```
I am getting:
Could NOT find Open3D (missing: Open3D_DIR)
fatal error: Open3D/Open3D.h: No such file or directory
2 | #include <Open3D/Open3D.h>
What is more confusing is the contents of Open3D/build folder after building from source.
I just want to resolve this dependency on Open3D. Thanks for any help!!!
Hello I was working on a C++ project, and had a cmake file that was working just fine, until I tried to add cuda into the C++ project. I am building this project on the NVIDIA Jetson Nano.
I get this error while building:
nvlink fatal : Could not open input file 'CMakeFiles/MY_APP.dir/src/MY_APP.cpp.o' (target: sm_35)
The rest of the error underneath that looks like this:
CMakeFiles/MY_APP.dir/build.make:552: recipe for target
'CMakeFiles/MY_APP.dir/cmake_device_link.o' failed
make[2]: *** [CMakeFiles/MY_APP.dir/cmake_device_link.o] Error 1
make[2]: Leaving directory '/home/me/Code/MyApp/build'
CMakeFiles/Makefile2:127: recipe for target 'CMakeFiles/MY_APP.dir/all' failed
make[1]: *** [CMakeFiles/MY_APP.dir/all] Error 2
make[1]: Leaving directory '/home/me/Code/MY_APP/build'
Makefile:155: recipe for target 'all' failed
make: *** [all] Error 2
make: Leaving directory '/home/me/Code/MY_APP/build'
I run my cmake file using a script I called confgure.sh, which looks like this:
#!/bin/sh
cmake -S . -B build -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.2 -DCMAKE_CUDA_COMPILER=/usr/local/cuda-10.2/bin/nvcc
I run my make file using a script I called build.sh, which looks like this:
#!/bin/sh
make -C build
My Cmake File looks like this:
cmake_minimum_required(VERSION 3.21.0)
project(MY_APP VERSION 0.0.0)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
enable_language(CUDA)
# Pass options to NVCC
set(
CUDA_NVCC_FLAGS
${CUDA_NVCC_FLAGS};
-O3 -gencode arch=compute_35,code=sm_35
)
set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
FILE(GLOB_RECURSE MY_CUDA_SRCS src/*.cu)
configure_file(src/MyAppConfig.h.in MyAppConfig.h)
#collect cpp files
FILE(GLOB_RECURSE SRC src/*.cpp)
find_package(CUDA QUIET)
if(CUDA_FOUND)
SET(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
include_directories(${CUDA_INCLUDE_DIRS})
get_filename_component(CUDA_LIBRARY_DIR ${CUDA_CUDART_LIBRARY} DIRECTORY)
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-L${CUDA_LIBRARY_DIR}")
SET(ALL_CUDA_LIBS ${CUDA_LIBRARIES} ${CUDA_cusparse_LIBRARY} ${CUDA_cublas_LIBRARY})
#${CUDA_CUDART_LIBRARY}
#${CMAKE_CUDA_RUNTIME_LIBRARY}
#)
SET(LIBS ${LIBS} ${ALL_CUDA_LIBS})
message(STATUS "CUDA_LIBRARIES: ${CUDA_INCLUDE_DIRS} ${ALL_CUDA_LIBS}")
set(CUDA_PROPAGATE_HOST_FLAGS ON)
set(CUDA_SEPARABLE_COMPILATION ON)
list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_35,code=sm_35)
#collect CUDA files
FILE(GLOB_RECURSE CUDA_SRC src/*.cu)
#build static library
#CUDA_ADD_LIBRARY(my_cuda_lib ${CUDA_SRC} STATIC)
cuda_compile(cuda_objs ${CUDA_SRC})
SET(SRC ${cuda_objs} ${SRC})
SET(LIBS ${LIBS} ${my_cuda_lib})
endif()
link_libraries(${cuda_objs})
set_source_files_properties(${SRC} PROPERTIES LANGUAGE CUDA)
message("using cuda_add_executable")
cuda_add_executable(${PROJECT_NAME} ${SRC})
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_BINARY_DIR})
target_link_libraries(${PROJECT_NAME} ${LIBS})
#DOWNLOAD ALL THE SUBMODULES
find_package(Git QUIET)
if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE, "Check submodules during build" ON)
if (GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE}
submodule update --init --recursvie
WORKING_DIRECTORY {CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE_GIT_SUBMOD_RESULT)
if (NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR
"git submodule update --init failed with ${GIT_SUMOD_RESULT},
please check submodule")
endif()
endif()
endif()
#CHECK ALL THE SUBMODULES
if (NOT EXISTS
"${PROJECT_SOURCE_DIR}/external/Simple-Websocket-Server/CMakeLists.txt")
message(FATAL_ERROR
"The Simple-Websocket-Server submodule was not downloaded!
GIT_SUBMODULE was turned off or failed. Please update submodule")
endif()
add_subdirectory(external/Simple-Websocket-Server)
include_directories(PUBLIC external/Simple-Websocket-Server)
find_package(PythonLibs REQUIRED)
find_package(pybind11 REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}
curl pthread crypto boost_system jsoncpp ${PYTHON_LIBRARIES} cudart
#<some-of-my-other-libraries>
)
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/MyAppConfig.h" DESTINATION include)
include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "${MY_APP_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${MY_APP_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${MY_APP_VERSION_PATCH}")
include(CPack)
set(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION
"${CMAKE_CUDA_COMPILER} ${_CMAKE_CUDA_EXTRA_FLAGS} -c ${MY_CUDA_SRCS}")
message(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION)
I am lost on how to get CUDA added to my project that already contains a bunch of C++ files, and I need to be able to call my .cu files from a .cpp file other then main.cpp, and I need to get this building in CMake, and I am doing it on the jetson nano. Any help on solving this error?
You are mixing up a lot of CUDA-related definitions and commands, including some from an earlier "era" of CUDA support in CMake.
Among other things:
Your CMakeLists.txt is overriding your environment setting for the CUDA compiler location.
... and actually, you shouldn't bother setting that location anyway, since you've already set the CUDA toolkit root.
Don't use find_package(CUDA) with CMake versions of 3.17 or 3.18, or later. For all relevant toolkit-related paths, use find_package(CUDAToolkit)`, which does... well, less but also more.
Don't use cuda_add_+suffix commands. Since CMake supports CUDA natively, you use regular add_executable, add_library etc.
There are further issues with your CMakeLists.txt file - not all of them CUDA-related, but that should be enough to get you started. It may not in itself resolve the specific bottom-line problem you have, though.
You may want to have a look at public repositories using CUDA and recent CMake versions to get an idea of how this is done.
I am still scraping the rust off of my c++ after many years of not doing this.
Here is my directory structure.
src
src/core
src/exe
This is so my unit tests don't have to fight with another main function which I've defined in src/exe.
Each of these directories has a CMakeLists.txt. (I'm building all of this using CLion.)
This is the one in src
cmake_minimum_required(VERSION 3.19)
project(${PROJECT_NAME}_src)
set(CMAKE_CXX_STANDARD 20)
include_directories(core)
add_subdirectory(core)
add_subdirectory(exe)
The one in src/core
cmake_minimum_required(VERSION 3.19)
project(rookery_core)
file(GLOB_RECURSE SOURCES LIST_DIRECTORIES true *.h *.cpp)
set(SOURCES ${SOURCES})
set(CMAKE_CXX_STANDARD 20)
add_library(${CMAKE_PROJECT_NAME}_core STATIC ${SOURCES})
and then the one in exe
cmake_minimum_required(VERSION 3.19)
project(rookery_exe)
set(CMAKE_CXX_STANDARD 20)
file(GLOB_RECURSE SOURCES LIST_DIRECTORIES true *.h *.cpp)
set(SOURCES ${SOURCES})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME}_exe ${CMAKE_PROJECT_NAME}_core)
and when I run it I get
[ 35%] Building CXX object src/core/CMakeFiles/rookery_core.dir/WorkFile.cpp.o
[ 40%] Linking CXX static library librookery_core.a
[ 40%] Built target rookery_core
[ 45%] Building CXX object src/exe/CMakeFiles/rookery_exe.dir/main.cpp.o
make[2]: *** No rule to make target 'src/core/librookery_core.a', needed by 'src/exe/rookery_exe'. Stop.
make[1]: *** [CMakeFiles/Makefile2:229: src/exe/CMakeFiles/rookery_exe.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
and it just built librookery_core library. Don't know what to do next.
Thanks.
Since asked for, here is the root CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(rookery)
set(CMAKE_CXX_STANDARD 20)
include_directories(src)
add_subdirectory(src)
add_subdirectory(tst)
add_subdirectory(lib/googletest)
I would like to compile my own project. I have error with **make**. cmake .. works properly.
I tried to compile the example in /Onboard-SDK/sample/platform/telemetry.
I did mkdir build and cd build in telemetry directory.
This is my CMakeList.txt
cmake_minimum_required(VERSION 2.8)
project(djiosdk-telemetry-sample)
# Compiler flags: link with pthread and enable C++11 support
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -g -O0")
# Tell the project where osdk-core is located
if(NOT ONBOARDSDK_SOURCE)
set(ONBOARDSDK_SOURCE "/home/pi/Onboard-SDK/osdk-core")
#set(ONBOARDSDK_SOURCE "/usr/local/include")
endif()
# Specify locations for osdk-core headers
include_directories(${ONBOARDSDK_SOURCE}/api/inc)
include_directories(${ONBOARDSDK_SOURCE}/utility/inc)
include_directories(${ONBOARDSDK_SOURCE}/hal/inc)
include_directories(${ONBOARDSDK_SOURCE}/protocol/inc)
include_directories(${ONBOARDSDK_SOURCE}/platform/linux/inc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../osal)
include_directories(include /usr/local/include)
include_directories(${ONBOARDSDK_SOURCE}/../sample/core/inc)
# User-code related project files
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common)
FILE(GLOB SOURCE_FILES *.hpp *.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../common/dji_linux_environment.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../common/dji_linux_helpers.cpp
main.cpp
telemetry_sample.cpp
)
if (OSDK_HOTPLUG)
FILE(GLOB SOURCE_FILES ${SOURCE_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/../hal/hotplug/*.c)
endif ()
# Target and linking
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} djiosdk-core)
This is the result after make
[ 20%] Linking CXX executable djiosdk-telemetry-sample
/usr/bin/ld: //usr/local/lib/libdjiosdk-core.a(dji_legacy_linker.cpp.o): in function `DJI::OSDK::LegacyLinker::legacyX5SEnableTask(void*)':
/home/pi/Onboard-SDK/osdk-core/api/src/dji_legacy_linker.cpp:69: **undefined reference to `DJI::OSDK**::Linker::getLocalSenderId()'
/usr/bin/ld: /home/pi/Onboard-SDK/osdk-core/api/src/dji_legacy_linker.cpp:71: **undefined reference** to `OsdkOsal_TaskSleepMs'
/usr/bin/ld: /home/pi/Onboard-SDK/osdk-core/api/src/dji_legacy_linker.cpp:72: **undefined reference** to `**DJI::OSDK**::Linker::isUSBPlugged()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/djiosdk-telemetry-sample.dir/build.make:129: djiosdk-telemetry-sample] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/djiosdk-telemetry-sample.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I often have [100%] Linking CXX executable djiosdk-telemetry-sample.
The main problem is with "undefined reference".
I create CMakeList.txt according to: https://developer.dji.com/onboard-sdk/documentation/development-workflow/integrate-sdk.html
What I should do?
The proper CMakeList.txt for creating your own project (example based on telemetry sample):
cmake_minimum_required(VERSION 2.8)
project(djiosdk-telemetry-sample)
set(ARCH armv7)
# Compiler flags: link with pthread and enable C++11 support
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -g -O0")
# Tell the project where osdk-core is located
if(NOT ONBOARDSDK_SOURCE)
set(ONBOARDSDK_SOURCE "/home/pi/Onboard-SDK/osdk-core")
endif()
set(CURRENT_CMAKE_MODULE_PATH ${ONBOARDSDK_SOURCE}/cmake-modules)
# Specify locations for osdk-core headers
include_directories(${ONBOARDSDK_SOURCE}/api/inc)
include_directories(${ONBOARDSDK_SOURCE}/utility/inc)
include_directories(${ONBOARDSDK_SOURCE}/hal/inc)
include_directories(${ONBOARDSDK_SOURCE}/protocol/inc)
include_directories(${ONBOARDSDK_SOURCE}/platform/linux/inc)
include_directories(${ONBOARDSDK_SOURCE}/linker/${ARCH}/inc)
include_directories(${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal)
include_directories(${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal/hotplug)
include_directories(${ONBOARDSDK_SOURCE}/../sample/platform/linux/osal)
include_directories(include /usr/local/include)
include_directories(include /usr/local/lib)
include_directories(${ONBOARDSDK_SOURCE}/../sample/core/inc)
# User-code related project files
include_directories(${ONBOARDSDK_SOURCE}/../sample/platform/linux/common)
FILE(GLOB SOURCE_FILES *.hpp *.cpp
${ONBOARDSDK_SOURCE}/../sample/platform/linux/common/dji_linux_environment.cpp
${ONBOARDSDK_SOURCE}/../sample/platform/linux/common/dji_linux_helpers.cpp
${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal/osdkhal_linux.c
${ONBOARDSDK_SOURCE}/../sample/platform/linux/osal/osdkosal_linux.c
)
if (OSDK_HOTPLUG)
FILE(GLOB SOURCE_FILES ${SOURCE_FILES} ${ONBOARDSDK_SOURCE}/../sample/platform/linux/hal/hotplug/*.c)
endif ()
link_libraries(dji-linker)
link_directories(/usr/local/include /usr/local/lib)
link_libraries(${ONBOARDSDK_SOURCE}/linker/${ARCH}/lib/libdji-linker.a)
set(CMAKE_MODULE_PATH ${CURRENT_CMAKE_MODULE_PATH})
find_package(LibUSB REQUIRED)
find_package(FFMPEG REQUIRED)
include_directories(${ADVANCED_SENSING_HEADERS_DIR})
# Target and linking
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC djiosdk-core)
target_link_libraries(${PROJECT_NAME} PUBLIC dji-linker)
target_link_libraries(${PROJECT_NAME} PUBLIC ${ONBOARDSDK_SOURCE}/linker/${ARCH}/lib/libdji-linker.a)
target_include_directories(${PROJECT_NAME} PUBLIC ${LIBUSB_1_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBUSB_1_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PUBLIC ${FFMPEG_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${ADVANCED_SENSING_HEADERS_DIR}>)
target_link_libraries(${PROJECT_NAME} PRIVATE advanced-sensing)
target_include_directories(${PROJECT_NAME} PUBLIC ${FFMPEG_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC ${FFMPEG_LIBRARIES})
I have a problem when I include ZBar in my C++ script. I already tried adding it via a CMakelists.txt:
cmake_minimum_required(VERSION 2.8.12)
project( Barcode-cpp )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} ${ZBARCV_SOURCE_DIR} )
set(CMAKE_MODULE_PATH ${ZBARCV_SOURCE_DIRS})
add_compile_options(-std=c++11)
add_library( src
src/VideoVeed.h
src/VideoVeed.cpp
src/Crop.h
src/Crop.cpp
src/Barcodes.h
src/Barcodes.cpp
)
add_executable( program
program/main.cpp
)
target_link_libraries( program src ${OpenCV_LIBS} ${ZBAR_LIBRARIES} zbar )
I'm on mac. I looked and my zbar.h file is located in /usr/local/include/ where it's supposed to be.
I include it like this: #include <zbar.h>
I hope someone is able to help me. Thanks in advance!
EDIT:
Full make error log:
/Users/mathijs/Documents/Barcode-cpp/src/Barcodes.h:7:10: fatal error: 'zbar.h' file not found
#include <zbar.h>
^~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/src.dir/src/VideoVeed.cpp.o] Error 1
make[1]: *** [CMakeFiles/src.dir/all] Error 2
make: *** [all] Error 2
I just checked; the Brew package for ZBar includes a packageconfig file (zbar.pc)
That means you can use modern CMake tooling instead of cargo culting:
cmake_minimum_required(VERSION 3.8)
project( Barcode-cpp )
find_package( OpenCV REQUIRED )
include_directories(${OpenCV_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 11)
add_library( src
src/VideoVeed.h
src/VideoVeed.cpp
src/Crop.h
src/Crop.cpp
src/Barcodes.h
src/Barcodes.cpp
)
add_executable( program
program/main.cpp
)
target_link_libraries(program src ${OpenCV_LIBS})
find_package(PkgConfig REQUIRED)
pkg_check_modules(ZBar REQUIRED IMPORTED_TARGET zbar)
target_link_libraries(program PkgConfig::ZBar)
The pkg_check_modules will read the zbar.pc file and generate an IMPORTED target named PkgConfig::ZBar that will automatically set both include paths and linker paths for program.