I'm trying to create a CmakeLists.txt that uses ImGUI + SDL + SDLRenderer + OpenCv for my current class.
.
├── CMakeLists.txt
├── imgui
│ ├── imconfig.h
│ ├── imgui.cpp
│ ├── imgui_demo.cpp
│ ├── imgui_draw.cpp
│ ├── imgui.h
│ ├── imgui_impl_sdl.cpp
│ ├── imgui_impl_sdl.h
│ ├── imgui_impl_sdlrenderer.cpp
│ ├── imgui_impl_sdlrenderer.h
│ ├── imgui_internal.h
│ ├── imgui_tables.cpp
│ ├── imgui_widgets.cpp
│ ├── imstb_rectpack.h
│ ├── imstb_textedit.h
│ ├── imstb_truetype.h
│ └── LICENSE.txt
├── main.cpp
├── Makefile
└── testImages
└── test001.png
My current CMakeLists.
project(main)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
set(sources
imgui/imconfig.h
imgui/imgui.cpp
imgui/imgui.h
imgui/imgui_demo.cpp
imgui/imgui_draw.cpp
imgui/imgui_internal.h
imgui/imgui_widgets.cpp
imgui/imstb_rectpack.h
imgui/imstb_textedit.h
imgui/imstb_truetype.h
imgui/imgui_impl_sdlrenderer.cpp
imgui/imgui_impl_sdlrenderer.h
imgui/imgui_impl_sdl.cpp
imgui/imgui_impl_sdl.h
)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
find_package( OpenCV REQUIRED )
add_executable( main main.cpp ${sources} )
target_link_libraries( main ${OpenCV_LIBS} ${SDL2_LIBRARIES} )
But i get undefined references for all the ImGUI functions:
[ 12%] Linking CXX executable main
/usr/bin/ld: CMakeFiles/main.dir/imgui/imgui.cpp.o: in function `ImGuiListClipper_SeekCursorAndSetupPrevLine(float, float)':
imgui.cpp:(.text+0x60c6): undefined reference to `ImGui::TableEndRow(ImGuiTable*)'
/usr/bin/ld: CMakeFiles/main.dir/imgui/imgui.cpp.o: in function `ImGuiListClipper::Begin(int, float)':
imgui.cpp:(.text+0x62a3): undefined reference to `ImGui::TableEndRow(ImGuiTable*)'
/usr/bin/ld: CMakeFiles/main.dir/imgui/imgui.cpp.o: in function `ImGuiListClipper_StepInternal(ImGuiListClipper*)':
imgui.cpp:(.text+0x66d3): undefined reference to `ImGui::TableEndRow(ImGuiTable*)'
[...]
Currently i'm only trying to build this in linux, so I can think on the windows/ mac versions later.
What am I doing wrong?
Okay, so as said by drescherjm I missed one file imgui/imgui_tables.cpp. After I add this line to the set on the CMakeLists.txt it worked.
Related
I am developing a module, which depends on another library(wasmtime). I put files into:
modules/mod_wasm/src/include - header files, and
modules/mod_mine/src/lib/libwasmtime.a - the compiled library.
The problem which I faced is that when I compile the acore server with
./acore.sh compiler all
it gives me the error:
[100%] Linking CXX executable worldserver
/usr/bin/ld: ../../../modules/libmodules.a(ModWasm.cpp.o): in function `readWasmFile(char const*)':
ModWasm.cpp:(.text+0x63): undefined reference to `wasm_byte_vec_new_uninitialized'
/usr/bin/ld: ModWasm.cpp:(.text+0xce): undefined reference to `wasm_byte_vec_delete'
The question is it required somehow add to a config that library? If yes, then how to do that?
I was testing my code in simple main.cpp file and it was working with options like "-L${workspaceFolder}/lib" and "-lwasmtime".
Maybe, these options are also required for my module?
Here is a link to azerothcore project which I use.
my module locates in modules/mod-wasm folder
azerothcore-wotlk/modules ‹master*› » tree -L 3 mod-wasm
mod-wasm
├── CMakeLists.txt
├── LICENSE
├── Makefile
├── README.md
├── conf
│ ├── conf.sh.dist
│ └── wasm.conf.dist
├── include.sh
├── mod-wasm.cmake
├── setup_git_commit_template.sh
├── src
│ ├── ModWasm.cpp
│ ├── include
│ │ ├── doc-wasm.h
│ │ ├── wasi.h
│ │ ├── wasm.h
│ │ ├── wasmtime
│ │ ├── wasmtime.h
│ │ └── wasmtime.hh
│ ├── lib
│ │ ├── libwasmtime.a
│ │ └── libwasmtime.so
│ └── wasm_loader.cpp
└── wasm_modules
└── rust_wasm_app.wasm
As I understood from the logs what I see and because CMakeList.txt exists in modules folder, the project considers the folder as module. Which in its turn scans subdirs for *.cmake files and configures the project.
The question now is how to properly configure my module to show that it contains the compiled library wasmtime inside src/lib folder?
As I understood, I could use target_link_libraries, but it requires a target name, and I have no idea what it should be and where I can take it.
At the end, I was able to find an answer with try and catch.
Azerothcore modules supports modname.cmake file to be run when configure libmodules.a which contains all extra modules(if I understood it correctly.
this is part of modules/CMakeFiles.txt
# Enables Devs to Include a cmake file in their module that will get run inline with the config.
foreach(SOURCE_MODULE ${MODULES_MODULE_LIST})
message("SOURCE_MODULE: ${SOURCE_MODULE}")
include("${CMAKE_SOURCE_DIR}/modules/${SOURCE_MODULE}/${SOURCE_MODULE}.cmake" OPTIONAL)
endforeach()
here I have my dirty cmake file which allow me to compile the server
set(WASM_MODULE_DIR ${CMAKE_SOURCE_DIR}/modules/${SOURCE_MODULE})
set(WASM_MODULE_SRC_DIR ${WASM_MODULE_DIR}/src)
message("--------------------->>>>> APPLICATION_NAME : ${APPLICATION_NAME}")
message("--------------------->>>>> APP_PROJECT_NAME : ${APP_PROJECT_NAME}")
message("--------------------->>>>> SOURCE_MODULE : ${SOURCE_MODULE}")
message("--------------------->>>>> WASM_MODULE_DIR : ${WASM_MODULE_DIR}")
message("--------------------->>>>> WASM_MODULE_SRC_DIR : ${WASM_MODULE_SRC_DIR}")
# include wasmtime
target_include_directories(modules PUBLIC ${WASM_MODULE_SRC_DIR}/include)
target_link_directories(modules PUBLIC ${WASM_MODULE_SRC_DIR}/lib)
find_library(LIBWASMTIME_TO_INCLUDE NAMES wasmtime PATHS ${WASM_MODULE_SRC_DIR}/lib REQUIRED)
message("--------------------->>>>>>>>> LIBWASMTIME_TO_INCLUDE: ${LIBWASMTIME_TO_INCLUDE}")
target_link_libraries(modules PUBLIC wasmtime)
So, it compiles now.
But I have next problem, which I am trying to resolve. but this is another story.
Thank you all for the help
The project structure is as below
├── ast
│ ├── CMakeLists.txt
│ ├── expression
│ │ ├── CMakeLists.txt
│ │ ├── Expression.cpp
│ │ ├── Expression.hpp
│ │ ├── NumericExpression.cpp
│ │ └── NumericExpression.h
│ ├── Visitor.cpp
│ └── Visitor.hpp
├── callSlang
│ ├── CMakeLists.txt
│ └── main.cpp
├── CMakeLists.txt
├── contexts
│ ├── CMakeLists.txt
│ ├── Context.hpp
│ ├── Symbol.cpp
│ ├── Symbol.hpp
│ └── SymbolTable.hpp
├── frontend
│ ├── CMakeLists.txt
│ ├── Parser.cpp
│ └── Parser.hpp
├── Makefile
├── meta
│ ├── CMakeLists.txt
│ └── Meta.hpp
└── README.md
CMakeLists.txt
cmake_minimum_required(VERSION 3.16.3)
# set the project name
# https://stackoverflow.com/questions/71740678/cmake-error-in-findterminfo-with-clang-15-on-macos
project(slangLLvm VERSION 1.0 LANGUAGES C CXX)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_BUILD_TYPE "Debug")
set(LLVM_DIR /usr/lib/llvm-14/lib/cmake/llvm)
find_package(LLVM REQUIRED CONFIG
PATHS ${search_paths}
NO_DEFAULT_PATH)
add_subdirectory(meta)
add_subdirectory(contexts)
add_subdirectory(ast)
add_subdirectory(frontend)
add_subdirectory(callSlang)
callSlang/CMakeLists.txt
set(SOURCE_FILE main.cpp)
# add the files for creating executable
add_executable(slangLLVM ${SOURCE_FILE})
#link the libs
target_link_libraries(slangLLVM
PRIVATE
ast
frontend
)
ast/CMakeLists.txt
set(SOURCE_FILES Visitor.cpp)
add_library(ast ${SOURCE_FILES})
target_link_libraries(ast
PUBLIC
meta
contexts
LLVMSupport
expression
PRIVATE
frontend
)
# get the include dirs
target_include_directories(ast
INTERFACE
.
PUBLIC
${LLVM_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/meta
${PROJECT_SOURCE_DIR}/ast/expression
)
add_subdirectory(expression)
expression/CMakeLists.txt
set(SOURCE_FILES Expression.cpp NumericExpression.cpp)
add_library(experssion ${SOURCE_FILES})
target_link_libraries(experssion
PUBLIC
ast
)
# get the include dirs
target_include_directories(experssion
INTERFACE
.
PUBLIC
${LLVM_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/contexts
${PROJECT_SOURCE_DIR}/ast
${PROJECT_SOURCE_DIR}/meta
)
# INTERFACE tells to use includes to other libs but on the ast
frontend/CMakeLists.txt
set(SOURCE_FILES Parser.cpp)
add_library(frontend STATIC ${SOURCE_FILES})
target_link_libraries(frontend
PRIVATE
ast
)
# get the include dirs
target_include_directories(frontend
INTERFACE
.
PRIVATE
${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/ast
${PROJECT_SOURCE_DIR}/contexts
${PROJECT_SOURCE_DIR}/ast/expression
)
meta/CMakeLists.txt
add_library(meta INTERFACE)
# get the include dirs
target_include_directories(meta INTERFACE .)
This compiles without error but fails during linking with the following error
[100%] Linking CXX executable slangLLVM
/usr/bin/ld: cannot find -lexpression
collect2: error: ld returned 1 exit status
make[3]: *** [callSlang/CMakeFiles/slangLLVM.dir/build.make:93: callSlang/slangLLVM] Error 1
make[3]: Leaving directory '/home/nithin/learn/c-cpp/slang-llvm/build'
make[2]: *** [CMakeFiles/Makefile2:392: callSlang/CMakeFiles/slangLLVM.dir/all] Error 2
make[2]: Leaving directory '/home/nithin/learn/c-cpp/slang-llvm/build'
make[1]: *** [Makefile:84: all] Error 2
make[1]: Leaving directory '/home/nithin/learn/c-cpp/slang-llvm/build'
make: *** [Makefile:4: all] Error 2
CallSlang depends on ast, ast depends on the expression and vice versa.
I have tried the solution in the link but it not-working so far for me. I am really new to CMake. Is it caused by the circular call by ast and expression, if so how can correct the same?
The complete code can be found in this link
Could someone please tell me the possible cause and solution? If I've missed out anything, over- or under-emphasized a specific point, please let me know in the comments. Thank you so much in advance for your time.
I'm having a bit of trouble organizing my c++ project as a cmake project, which is something I'm new to. I'm trying to mimic the template given by this github repository. I think I'm almost there, but I'm getting a few linker errors when I try to compile with the following commands:
cd markets
rm -rf build/manual
mkdir build/manual
cd build/manual
cmake -G "Unix Makefiles" -D CMAKE_CXX_COMPILER=/usr/bin/g++-8 ../..
make
There's a lot of output, but here are the first few lines:
[100%] Linking CXX executable markets_tests
CMakeFiles/markets_tests.dir/src/test_data_handler.cpp.o: In function `Testtest_data_handler::RunImpl() const':
test_data_handler.cpp:(.text+0x12a): undefined reference to `Instrument::Instrument(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
test_data_handler.cpp:(.text+0x153): undefined reference to `Instrument::Instrument(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
test_data_handler.cpp:(.text+0x37f): undefined reference to `DataHandler::DataHandler(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, unsigned int const&, unsigned int const&)'
CMakeFiles/markets_tests.dir/src/test_data_reader.cpp.o: In function `Testtest_csv_reader::RunImpl() const':
test_data_reader.cpp:(.text+0xa9): undefined reference to `csv_reader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)'
I guess this must mean that something is wrong with my markets/test/CMakeLists.txt file, which I have now as:
cmake_minimum_required(VERSION 3.10)
project(markets_tests)
find_package(UnitTest++ REQUIRED)
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
SET(GCC_COVERAGE_COMPILE_FLAGS "-no-pie")
SET(CMAKE_CXX_FLAGS "${GCC_COVERAGE_COMPILE_FLAGS}")
include_directories(${MARKETS_HEADERS_DIR})
include_directories(${UTPP_INCLUDE_DIRS})
set(SOURCE_FILES main.cpp
src/test_data_handler.cpp
src/test_data_reader.cpp
src/test_exec_handler.cpp
src/test_fill.cpp
src/test_instrument.cpp
src/test_market_bar.cpp
src/test_market_snapshot.cpp
src/test_order.cpp
src/test_pnl_calculator.cpp
src/test_portfolio.cpp
src/test_position_summary.cpp)
add_executable(markets_tests ${SOURCE_FILES})
target_link_libraries(markets_tests markets Eigen3::Eigen UnitTest++) # added Eigen
install(TARGETS markets_tests DESTINATION bin)
Any ideas? Other questions seem to suggest that I could be linking things in the wrong order, but this project structure isn't that complicated (just an executable, a library, and some unit tests). This was compiling with my old makefile, so I doubt it's because I haven't defined some of the header definitions.
Here is the tree of my markets/ root directory if it helps:
.
├── bin
├── build
│ └── manual
├── CMakeLists.txt
├── docs
├── lib
├── README.md
├── src
│ ├── CMakeLists.txt
│ ├── main.cpp
│ └── markets
│ ├── CMakeLists.txt
│ ├── data_handlers.cpp
│ ├── data_handlers.h
│ ├── data_readers.cpp
│ ├── data_readers.h
│ ├── execution_handler.cpp
│ ├── execution_handler.h
│ ├── fill.cpp
│ ├── fill.h
│ ├── instrument.cpp
│ ├── instrument.h
│ ├── market_bar.cpp
│ ├── market_bar.h
│ ├── market_snapshot.cpp
│ ├── market_snapshot.h
│ ├── order.cpp
│ ├── order.h
│ ├── pnl_calculator.cpp
│ ├── pnl_calculator.h
│ ├── portfolio.cpp
│ ├── portfolio.h
│ ├── position_summary.cpp
│ └── position_summary.h
└── test
├── CMakeLists.txt
├── main.cpp
├── src
│ ├── test_data_handler.cpp
│ ├── test_data_reader.cpp
│ ├── test_exec_handler.cpp
│ ├── test_fill.cpp
│ ├── test_instrument.cpp
│ ├── test_market_bar.cpp
│ ├── test_market_snapshot.cpp
│ ├── test_order.cpp
│ ├── test_pnl_calculator.cpp
│ ├── test_portfolio.cpp
│ └── test_position_summary.cpp
└── test_data
├── QLD.csv
└── SPY.csv
Edit:
Here is src/markets/CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(markets)### C CXX)
set(SOURCE_FILES
data_handlers.h
data_handlers.cpp
data_readers.h
data_readers.cpp
execution_handler.h
execution_handler.cpp
fill.h
fill.cpp
instrument.h
instrument.cpp
market_bar.h
market_bar.cpp
market_snapshot.h
market_snapshot.cpp
order.h
order.cpp
pnl_calculator.h
pnl_calculator.cpp
portfolio.h
portfolio.cpp
position_summary.h
position_summary.cpp
)
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
add_library(markets SHARED STATIC ${SOURCE_FILES})
target_link_libraries(markets Eigen3::Eigen stdc++fs) #added this
install(TARGETS markets DESTINATION ${MARKETS_INSTALL_LIB_DIR})
install(FILES markets.h DESTINATION ${MARKETS_INSTALL_INCLUDE_DIR})
I feel I don't understand how to set up an "include" directory in a C++ project for header files, and also how to include these headers in the .cpp files.
I'm talking about a project in the context of a ROS package, but I don't think ROS would make the structure of the project any different.
To be specific, this is the structure of the directory I'm talking about:
yuqiong#yuqiong-G7-7588:/media/yuqiong/DATA/sdd_vio$ tree
.
├── CMakeLists.txt
├── CMakeModules
│ └── FindEigen.cmake
├── config
│ ├── camchain-imucam-euroc.yaml
│ ├── camchain-imucam-fla1_11052016.yaml
│ ├── camchain-imucam-snapdragon.yaml
│ ├── custom_rosconsole.conf
│ ├── disp_vo_param.yaml
│ ├── ukf_params.yaml
│ └── vo_param.yaml
├── include
│ └── sdd_vio
│ ├── grid.h
│ ├── pinhole_camera_stereo.h
│ ├── sdd_vio_nodelet.h
│ ├── utils
│ │ ├── calib_utils.h
│ │ ├── math_utils.h
│ │ ├── ros_params_helper.h
│ │ └── timer.hpp
│ ├── visualization.h
│ └── vo_stereo.h
├── launch
│ ├── bag_reader.launch
│ ├── disp_nodelet.launch
│ ├── image_proc_rectify.launch
│ ├── imu.launch
│ ├── vins_node.launch
│ ├── vins_nodelet_euroc.launch
│ ├── vins_nodelet.launch
│ ├── vins_robot.launch
│ └── visualization.launch
├── LICENSE
├── nodelet_plugins.xml
├── package.xml
├── readme.md
├── rviz
│ ├── rviz_config_gs.rviz
│ └── rviz_config.rviz
├── src
│ ├── grid.cpp
│ ├── imu_integration_nodelet.cpp
│ ├── pinhole_camera_stereo.cpp
│ ├── sdd_vio_bag_reader.cpp
│ ├── sdd_vio_node.cpp
│ ├── sdd_vio_nodelet.cpp
│ ├── utils
│ │ ├── calib_utils.cpp
│ │ └── math_utils.cpp
│ ├── visualization.cpp
│ ├── vo_stereo_1.cpp
│ ├── vo_stereo_2.cpp
│ ├── vo_stereo_3.cpp
│ └── vo_stereo_4.cpp
└── statistics
9 directories, 47 files
So we see all the header files in the ./include/sdd_vio folder.
But in the ./src/vo_stereo_1.cpp file, it includes a header file like this:
#include "sdd_vio/vo_stereo.h"
I feel it should use this instead:
#include "../include/sdd_vio/vo_stereo.h"
Why does it omit the ../include part?
Also, it would be good if there are good resources to help me learn about build / CMake / how to figure out the correct include path in general. I've read the official CMake tutorial, some tutorials on how compile + link actually work, but still feel my knowledge is not systematic... Thanks!
Edit
Adding the CMakeLists.txt file below as mentioned in the answer.
cmake_minimum_required(VERSION 2.8.3)
project(sdd_vio)
IF(DEFINED ENV{ARM_ARCHITECTURE})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -march=native -mfpu=neon")
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Ofast -fno-signed-zeros -fno-math-errno -funroll-loops -fno-strict-aliasing")
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -std=c++11")
ENDIF()
# set default build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
find_package(catkin REQUIRED COMPONENTS
roscpp
image_transport
sensor_msgs
cv_bridge
visualization_msgs
tf
nodelet
rosbag
)
FIND_PACKAGE(OpenCV 3 REQUIRED)
FIND_PACKAGE(Eigen3 REQUIRED)
find_package(Boost REQUIRED COMPONENTS thread)
#find_package(Ceres REQUIRED)
# Check if OpenCV package has been found
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# Check if Eigen package has been found
message(STATUS "Eigen library status:")
message(STATUS " version: ${EIGEN3_VERSION}")
message(STATUS " libraries: ${EIGEN3_LIBS}")
message(STATUS " include path: ${EIGEN3_INCLUDE_DIRS}")
catkin_package(
LIBRARIES vo_nodelet imu_integration_nodelet
DEPENDS EIGEN3 OpenCV
CATKIN_DEPENDS roscpp image_transport sensor_msgs visualization_msgs tf nodelet
LIBRARIES sdd_vio_nodelet
)
INCLUDE_DIRECTORIES(
include
${EIGEN3_INCLUDE_DIR}
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
add_library(pinhole_camera src/pinhole_camera_stereo.cpp)
target_link_libraries(pinhole_camera ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${OpenCV_LIBS} utils)
add_library(utils src/utils/math_utils.cpp src/utils/calib_utils.cpp)
target_link_libraries(utils ${OpenCV_LIBS} ${catkin_LIBRARIES})
add_library(vo src/vo_stereo_1.cpp src/vo_stereo_2.cpp src/vo_stereo_3.cpp src/vo_stereo_4.cpp src/grid.cpp)
# add_library(vo src/disp_vo_stereo.cpp src/grid.cpp)
target_link_libraries(vo utils pinhole_camera ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${OpenCV_LIBS}) # ${CERES_LIBRARIES}
# for nodelet
add_library(vo_nodelet src/sdd_vio_nodelet.cpp src/visualization.cpp)
add_dependencies(vo_nodelet ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(vo_nodelet vo ${catkin_LIBRARIES} ${Boost_LIBRARIES})
add_library(imu_integration_nodelet src/imu_integration_nodelet.cpp)
add_dependencies(imu_integration_nodelet ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(imu_integration_nodelet ${catkin_LIBRARIES})
# for node
ADD_EXECUTABLE(sdd_vio_node src/sdd_vio_node.cpp src/visualization.cpp)
TARGET_LINK_LIBRARIES(
sdd_vio_node
pinhole_camera
vo
${OpenCV_LIBS}
${catkin_LIBRARIES}
)
add_executable(sdd_vio_bag_reader src/sdd_vio_bag_reader.cpp)
target_link_libraries(sdd_vio_bag_reader vo_nodelet)
Why does it omit the ../include part?
Your CMakeLists.txt file contains the following lines in it:
INCLUDE_DIRECTORIES(
include
${EIGEN3_INCLUDE_DIR}
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
INCLUDE_DIRECTORIES tells the compiler where to look for header files. In this case one of the places is the include directory in your project, hence allows you to omit the ../include part. This is also the better form to use because using an absolute path and then moving the .cpp file that contains the include statement to some sub-folder in the future might break your code.
it would be good if there are good resources to help me learn about build / CMake
There are a couple of good books about Cmake, like Cmake CookBook. But in this case since you are dealing with ROS, I would suggest you start with ROS tutorials, they cover some of the basics of what you wish to know.
RT~ ps: cmake version 3.9.2
My codebase just like this.
suzanwen#n224-004-133:~/repos/C++/ttt:)$ tree -L 2
.
├── build
│ ├── bin
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── lib
│ ├── Makefile
│ ├── test
│ └── thirdparty
├── build.sh
├── CMakeLists.txt
├── Makefile
├── test
│ ├── CMakeLists.txt
│ └── main.cc
└── thirdparty
├── CMakeLists.txt
├── gflags
└── hellolib
10 directories, 9 files
my thirdparty/hellolib/CMakeLists.txt is
PROJECT(hello)
SET(LIBHELLO_SRC hello.cc)
MESSAGE(STATUS "LIBRARY PATH=" ${LIBRARY_OUTPUT_PATH})
ADD_LIBRARY(hello_static STATIC ${LIBHELLO_SRC})
SET_TARGET_PROPERTIES(hello_static PROPERTIES ARCHIVE_OUTPUT_NAME "hello")
my test/CMakeLists.txt is
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/thirdparty/hellolib
${PROJECT_SOURCE_DIR}/thirdparty/gflags/include)
IF(LIBRARY_OUTPUT_PATH)
LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH})
ENDIF(LIBRARY_OUTPUT_PATH)
ADD_EXECUTABLE(main main.cc)
TARGET_LINK_LIBRARIES(main hello)
# TARGET_LINK_LIBRARIES(main hello_static)
when I build my top-level project, an error occurs like this.
/usr/bin/c++ -rdynamic CMakeFiles/main.dir/main.cc.o -o ../bin/main -L/home/suzanwen/repos/C++/ttt/build/lib -Wl,-rpath,/home/suzanwen/repos/C++/ttt/build/lib -lhello
/usr/bin/ld: cannot find -lhello
But when I comment the line # SET_TARGET_PROPERTIES(hello_static PROPERTIES ARCHIVE_OUTPUT_NAME "hello") and TARGET_LINK_LIBRARIES with hello_static, everything goes fine.
It seems that TARGET_LINK_LIBRARIES cannot find renamed lib target. Could anyone explain it? thanks in advance.
It seems that TARGET_LINK_LIBRARIES cannot find renamed lib target.
Setting ARCHIVE_OUTPUT_NAME property renames not a target, but an output file. So linking with a target still works:
TARGET_LINK_LIBRARIES(main hello_static)
One cannot rename the target once it is created, but it is possible to create ALIAS for a target:
ADD_LIBRARY(hello ALIAS hello_static)
After that it is possible to link with the alias:
TARGET_LINK_LIBRARIES(main hello)