I would like to build a C++ library using cmake.
The library would require a on-the-fly opencv download and build then this library will be used in an other cmake project as a library.
The project structure is like that:
template_matching_project
|
|-- build
|-- template_matching_project
| |
| |-- template_matching_library
| |
| | -- src
| | -- include
| | -- CMakeLists.txt
|-- main.cpp
|-- CMakeLists.txt
The template_matching_library performs some image processing using opencv, there is the content of its cmake file in template_matching_project/template_matching_library/CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_STANDARD 11)
project(template_matching)
# third party
include(ExternalProject)
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/3rdparty)
set(EXTERNAL_DOWNLOAD_LOCATION ${CMAKE_BINARY_DIR}/Download)
# OpenCV
ExternalProject_Add(opencv-contrib
GIT_REPOSITORY https://github.com/opencv/opencv_contrib.git
GIT_TAG e6f32c6
SOURCE_DIR "${EXTERNAL_DOWNLOAD_LOCATION}/opencv-contrib"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
ExternalProject_Add(opencv
GIT_REPOSITORY https://github.com/opencv/opencv.git
GIT_TAG 01b2c5a
SOURCE_DIR "${EXTERNAL_DOWNLOAD_LOCATION}/opencv"
CMAKE_ARGS
-DBUILD_DOCS:BOOL=OFF
...
)
add_dependencies(opencv opencv-contrib)
# set source directories
set(PROJECT_SOURCE_DIR source)
set(INCLUDE_DIR include)
# set source files
file(GLOB_RECURSE SRCS ${PROJECT_SOURCE_DIR}/*)
file(GLOB_RECURSE HEADERS ${INCLUDE_DIR}/*)
# build library
link_directories(${EXTERNAL_INSTALL_LOCATION}/opencv/lib)
include_directories(${EXTERNAL_INSTALL_LOCATION}/opencv/include/opencv4)
include_directories(${INCLUDE_DIR})
add_library(${PROJECT_NAME} SHARED ${SRCS} ${HEADERS})
add_dependencies(${PROJECT_NAME} opencv)
target_link_libraries(${PROJECT_NAME} opencv_core opencv_highgui opencv_imgproc)
target_include_directories(${PROJECT_NAME} PUBLIC ${INCLUDE_DIR})
The template_matching_library is correctly build with this cmake, but the build of the main.cpp executable fails
Here is the template_matching_project/CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_STANDARD 11)
project(markers)
# include library
add_subdirectory(template_matching_library)
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/3rdparty)
include_directories(${EXTERNAL_INSTALL_LOCATION}/opencv/include/opencv4)
# add file to compile
set(SRCS main.cpp)
# add executable
add_executable(${PROJECT_NAME} ${SRCS})
# add dependencies
target_link_libraries(${PROJECT_NAME} template_matching)
Then trying the build with the convetional
cd build
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
make
I have the following error
[ 95%] Building CXX object CMakeFiles/markers.dir/main.cpp.o
[100%] Linking CXX executable markers
/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_highgui
/usr/bin/ld: cannot find -lopencv_imgproc
collect2: error: ld returned 1 exit status
Any suggestion to solve my problem? Should I change one/both of those CMakeLists.txt.
Thanks.
I have it worked with those two CMakeLists.txt, if some have any suggestions or better solution.
template_matching_project/CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_STANDARD 11)
project(markers)
add_subdirectory(template_matching_library)
set(SRCS main.cpp)
add_executable(${PROJECT_NAME} ${SRCS})
target_link_libraries(${PROJECT_NAME} template_matching ${OpenCV_LIBS})
template_matching_project/template_matching_library/CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_STANDARD 11)
project(template_matching)
# third party
include(ExternalProject)
set(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/3rdparty)
set(EXTERNAL_DOWNLOAD_LOCATION ${CMAKE_BINARY_DIR}/Download)
# OpenCV
ExternalProject_Add(opencv-contrib
GIT_REPOSITORY https://github.com/opencv/opencv_contrib.git
GIT_TAG e6f32c6
SOURCE_DIR "${EXTERNAL_DOWNLOAD_LOCATION}/opencv-contrib"
...
)
ExternalProject_Add(opencv
GIT_REPOSITORY https://github.com/opencv/opencv.git
GIT_TAG 01b2c5a
SOURCE_DIR "${EXTERNAL_DOWNLOAD_LOCATION}/opencv"
CMAKE_ARGS
-DBUILD_DOCS:BOOL=OFF
...
-DOPENCV_EXTRA_MODULES_PATH:PATH=${EXTERNAL_DOWNLOAD_LOCATION}/opencv-contrib/modules
)
add_dependencies(opencv opencv-contrib)
set(OpenCV_DIR ${EXTERNAL_INSTALL_LOCATION}/opencv/lib/cmake/opencv4)
find_package(OpenCV REQUIRED PATHS ${EXTERNAL_INSTALL_LOCATION}/opencv)
# set source directories
set(PROJECT_SOURCE_DIR source)
set(INCLUDE_DIR include)
# set source files
file(GLOB_RECURSE SRCS ${PROJECT_SOURCE_DIR}/*)
file(GLOB_RECURSE HEADERS ${INCLUDE_DIR}/*)
# build library
include_directories(${EXTERNAL_INSTALL_LOCATION}/opencv/include/opencv4)
include_directories(${INCLUDE_DIR})
add_library(${PROJECT_NAME} SHARED ${SRCS} ${HEADERS})
add_dependencies(${PROJECT_NAME} opencv)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
target_include_directories(${PROJECT_NAME} PUBLIC ${INCLUDE_DIR})
Nevertheless, using my two CMakeLists.txt, I do have to run twice cmake and make commands, unless I have a links errors with opencv, like the following:
cd build
cmake .. -G "Unix Makefiles
make
cmake .. -G "Unix Makefiles
make
Is there a way to have work with a single run cmake/make?
I try some FetchContent but was not able to make it worked. My cmake version is 3.5.1
Related
This question already has answers here:
CMake link to external library
(6 answers)
Closed 1 year ago.
I am trying to compile a small project that uses a library (a header file and a .so file) for reading in images from a camera (on a RPI). The vendor (Arducam) provided a makefile example file, but not a CMake example file. The project is composed of:
test.cpp(main file),
arducam_mipicamera.h, and
libarducam_mipicamera.so.
The makefile that compiles the project successfully is:
CROSS_PREFIX ?=
CC := $(CROSS_COMPILE)gcc
CXX := $(CROSS_COMPILE)g++
CFLAGS ?= -I. -g -O0 -std=gnu11
OPENCV_LIB = $(shell pkg-config --cflags --libs opencv)
ifeq ($(OPENCV_LIB), )
OPENCV_LIB = $(shell pkg-config --cflags --libs opencv4)
endif
CXXFLAGS?= -I. -g -std=gnu++11 ${OPENCV_LIB}
LDFLAGS ?=
LIBS := -larducam_mipicamera -lpthread
OLIB := lib
examples:= test
all: $(examples)
test : test.cpp
$(CXX) $(CXXFLAGS) -o $# $^ $(LIBS)
clean:
-rm -f *.o
-rm -f $(examples)
.PHONY: install
install:
sudo install -m 644 $(OLIB)/libarducam_mipicamera.so /usr/lib/
And the CMakefile I have so far is:
cmake_minimum_required(VERSION 3.11)
project( DisplayImage )
set(CMAKE_CXX_STANDARD 11)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage test.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
I am confused on how to add the arducam library to the CMakefile. The header file is in the same directory as the main file and the .so file is in a subdirectory under.
How do I go about adding this simple library to the CMakefile, so that it compiles successfully (like the makefile)? This is not meant to be a dumb question, I just finished reading the CMake documentation. I am just confused about how to go about adding this library to the CMakefile. Does it involve using calls like link_directories() and target_link_libraries()?
The CMakefile should work if you add two more lines.
If the library is called arducam_mipicamera (which it looks like in this case), then you can use find_library(). And if the .so library file is in a subdirectory, the command should simply come out to:
find_library(ARDUCAM_LIBRARY arducam_mipicamera HINTS /*)
Where the first parameter is the name of your library (within the context of the CMakefile, you can rename this to whatever you want) and the last parameter gives the command a hint where the library is located (in this case a subdirectory).
Don't forget to link the library to target!
target_link_libraries( DisplayImage ${ARDUCAM_LIBRARY} )
The final CMakefile should come out to:
cmake_minimum_required(VERSION 3.11)
project( DisplayImage )
set(CMAKE_CXX_STANDARD 11)
find_library(ARDUCAM_LIBRARY arducam_mipicamera HINTS /*)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable( DisplayImage test.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
target_link_libraries( DisplayImage ${ARDUCAM_LIBRARY} )
I am new to cmake though not to make. This question is different from Could not build OpenCV Android sample project since that other question is about a single project and this one is looking at the overall CMakeLists.txt.
Speaking of which: consider the CMakeLists.txt in ${OPENCVDIR}/samples :
I followed basic process for cmake:
cd "${OPENCVDIR}/samples"
mkdir build
cd build
cmake ..
But at the last step I have:
$ cmake ..
CMake Error at CMakeLists.txt:72 (find_package):
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/git/opencv/samples/CMakeFiles/CMakeOutput.log".
Line 72 has this: find_package(OpenCV REQUIRED PATHS "..")
I looked at the error log and it was not informative.
Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"
The CXX compiler identification is GNU, found in "/git/opencv/samples/CMakeFiles/3.13.4/CompilerIdCXX/a.out"
Determining if the C compiler works passed with the following output:
Change Dir: /git/opencv/samples/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_26f76/fast"
/usr/bin/make -f CMakeFiles/cmTC_26f76.dir/build.make CMakeFiles/cmTC_26f76.dir/build
make[1]: Entering directory '/git/opencv/samples/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_26f76.dir/testCCompiler.c.o
/usr/bin/cc -o CMakeFiles/cmTC_26f76.dir/testCCompiler.c.o -c /git/opencv/samples/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_26f76
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_26f76.dir/link.txt --verbose=1
/usr/bin/cc -rdynamic CMakeFiles/cmTC_26f76.dir/testCCompiler.c.o -o cmTC_26f76
make[1]: Leaving directory '/git/opencv/samples/CMakeFiles/CMakeTmp'
Detecting C compiler ABI info compiled with the following output:
"/git/opencv/samples/CMakeFiles/CMakeOutput.log" 706 lines, 48095 characters
Feature record: CXX_FEATURE:0cxx_defaulted_move_initializers
Feature record: CXX_FEATURE:0cxx_delegating_constructors
Feature record: CXX_FEATURE:0cxx_deleted_functions
Feature record: CXX_FEATURE:0cxx_digit_separators
Feature record: CXX_FEATURE:0cxx_enum_forward_declarations
Feature record: CXX_FEATURE:0cxx_explicit_conversions
Feature record: CXX_FEATURE:0cxx_extended_friend_declar
etc ..
What is the correct way to build these examples - hopefully using the CMakeLists.txt already provided?
It seems the installation directory of OpenCV couldn't be found by cmake. Try to provide the value through the argument:
cmake -DCMAKE_PREFIX_PATH=/home/someone/src/opencv/install ..
Ff it works, you could define this in the top-level CMakeLitst.txt:
list(APPEND CMAKE_PREFIX_PATH /home/someone/src/opencv/install)
This should provide CMake the place where it should look to.
$ opencv_version
3.4.16
$ cd OpenCV/samples/
$ cmake -B build
$ cmake --build build
JPEG display
$ build/cpp/example_cpp_image data/lena.jpg
USB camera capture
$ build/cpp/example_cpp_videocapture_basic
$ build/cpp/example_cpp_videocapture_camera
Recognition by AI
$ build/tapi/example_tapi_hog
I am trying to create the script to compile and run as mentioned by emscirpten.
This is the command I wish to create a cmake file for.
./emcc -std=c++11 -O3 -I.. ~/DLIB/dlib-19.4/dlib/all/source.cpp -I/home/akshay/DLIB/dlib-19.4 -I/usr/include/X11/ -lpthread -lX11 -lopencv_imgcodecs -o webca.js ~/DLIB/dlib-19.4/examples/webcam_face_pose_ex.cpp -ldlib `pkg-config opencv --cflags --libs`
So far I have come up with this. This is my CMAKELists.txt file.
cmake_minimum_required(VERSION 3.5.1)
project(DLIB)
SET(CMAKE_BUILD_TYPE_INIT "Release")
set(CMAKE_CXX_STANDARD 11)
if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
set(CMAKE_C_COMPILER "emcc")
endif ()
if(NOT DEFINED OpenCV_PREFIX)
set(OpenCV_PREFIX ${CMAKE_INSTALL_PREFIX})
endif()
set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build.emscripten)
set(DLIB_SRC "/home/akshay/DLIB/dlib-19.4/examples/webcam_face_pose_ex.cpp")
add_library(DLIB_static ${DLIB_SRC})
set(OpenCV_PREFIX /usr/share/OpenCV/OpenCVConfig.cmake)
include_directories(/usr/include/X11 /home/akshay/DLIB/dlib-19.4 /home/akshay/DLIB/dlib-19.4/dlib/all/source.cpp)
set_target_properties(DLIB_static PROPERTIES LINK_FLAGS "-s DEMANGLE_SUPPORT=1 --preload-file assets --bind")
find_package(PkgConfig REQUIRED)
find_package(OpenCV REQUIRED
PATHS ${OpenCV_PREFIX}/lib/cmake/
${OpenCV_PREFIX}/share/OpenCV/
NO_DEFAULT_PATH)
find_library(OpenCV REQUIRED PATHS ${OpenCV_PREFIX}/lib/cmake/
${OpenCV_PREFIX}/share/OpenCV/
NO_DEFAULT_PATH)
set(CMAKE_REQUIRED_FLAGS "-std=c++11 -O3 -lpthread -lX11 -lopencv_imgcodecs -ldlib `pkg-config opencv --cflags --libs`")
#file(GLOB_RECURSE CORE_HDR src/.h)
#file(GLOB_RECURSE CORE_SRC src/.cpp)
add_definitions("-s DEMANGLE_SUPPORT=1 --preload-file ${CMAKE_SOURCE_DIR}/assets --bind")
add_executable(DLIB /home/akshay/DLIB/dlib-19.4/examples/webcam_face_pose_ex.cpp)
When I run this command :cmake -DCMAKE_PREFIX_PATH=/usr/share/OpenCV/OpenCVConfig.cmake -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=/home/akshay/Downloads/emsdk-portable/emscripten/1.37.16/cmake/Modules/Platform/Emscripten.cmake . && make
It gives me an error like so :
CMake Error at CMakeLists.txt:25 (find_package):
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
It seems to not be able to find the CMAKE_PREFIX_PATH or that I am not setting it correctly.
I have just started fiddling around with CMAKE since yesterday. I may have very little clue about what I have done. Have tried some of the other SO answers as well.
Any help will be appreciated
You simply need to set the OpenCV_DIR to the path where OpenCV is installed, for example:
cmake -DOpenCV_DIR=/usr/local/share/OpenCV ..
I am at a loss to solve a particular issue I have: I cannot pinpoint the culprit.
System: Jetson TX1, arm64 kernel, 32b userspace, opencv4tegra
Situation: Have been building projects using:
find_package( OpenCV )
And this has worked fine and compiled.
Fault: I built from source and installed CMake 3.5.2. Now I can no-longer build any projects that depend on OpenCV. I get linker errors that point cannot find:
opencv_dep_cudart
I am assuming the issues are caused in OpenCVCConfig.cmake, around this point:
# Import target "opencv_core" for configuration "Release"
set_property(TARGET opencv_core APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(opencv_core PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE "opencv_dep_cudart;opencv_dep_nppc;opencv_dep_nppi;opencv_dep_npps;dl;m;pthread;rt;tbb"
IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/libopencv_core.so.2.4.12"
IMPORTED_SONAME_RELEASE "libopencv_core.so.2.4"
)
Out of the file: /usr/share/OpenCV/OpenCVModules-release.cmake
However, this file doesn't change between CMake versions as it is an OpenCV file. So this must be how it is processed.
Reverting my CMake back to 2.8.12.2 manually allowed me to build again. Here is an example of a make command that uses OpenCV. Note the correct cuda libs:
Linking CXX executable DuoInterfaceTest
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/DuoInterfaceTest.dir/link.txt --verbose=1
/usr/bin/c++ -O2 -g -DNDEBUG -std=gnu++11 CMakeFiles/DuoInterfaceTest.dir/src/mainTest.cpp.o -o DuoInterfaceTest -L/home/ubuntu/catkin_ws/duointerface/lib/linux/arm -rdynamic libDuoInterface.a /usr/lib/libopencv_vstab.so.2.4.12 /usr/lib/libopencv_tegra.so.2.4.12 /usr/lib/libopencv_imuvstab.so.2.4.12 /usr/lib/libopencv_facedetect.so.2.4.12 /usr/lib/libopencv_esm_panorama.so.2.4.12 /usr/lib/libopencv_detection_based_tracker.so.2.4.12 /usr/lib/libopencv_videostab.so.2.4.12 /usr/lib/libopencv_video.so.2.4.12 /usr/lib/libopencv_ts.a /usr/lib/libopencv_superres.so.2.4.12 /usr/lib/libopencv_stitching.so.2.4.12 /usr/lib/libopencv_photo.so.2.4.12 /usr/lib/libopencv_objdetect.so.2.4.12 /usr/lib/libopencv_ml.so.2.4.12 /usr/lib/libopencv_legacy.so.2.4.12 /usr/lib/libopencv_imgproc.so.2.4.12 /usr/lib/libopencv_highgui.so.2.4.12 /usr/lib/libopencv_gpu.so.2.4.12 /usr/lib/libopencv_flann.so.2.4.12 /usr/lib/libopencv_features2d.so.2.4.12 /usr/lib/libopencv_core.so.2.4.12 /usr/lib/libopencv_contrib.so.2.4.12 /usr/lib/libopencv_calib3d.so.2.4.12 /usr/lib/libopencv_tegra.so.2.4.12 /usr/lib/libopencv_stitching.so.2.4.12 /usr/lib/libopencv_gpu.so.2.4.12 /usr/lib/libopencv_photo.so.2.4.12 /usr/lib/libopencv_legacy.so.2.4.12 /usr/local/cuda-7.0/lib/libcufft.so /usr/lib/libopencv_video.so.2.4.12 /usr/lib/libopencv_objdetect.so.2.4.12 /usr/lib/libopencv_ml.so.2.4.12 /usr/lib/libopencv_calib3d.so.2.4.12 /usr/lib/libopencv_features2d.so.2.4.12 /usr/lib/libopencv_highgui.so.2.4.12 /usr/lib/libopencv_imgproc.so.2.4.12 /usr/lib/libopencv_flann.so.2.4.12 /usr/lib/libopencv_core.so.2.4.12 /usr/local/cuda-7.0/lib/libcudart.so /usr/local/cuda-7.0/lib/libnppc.so /usr/local/cuda-7.0/lib/libnppi.so /usr/local/cuda-7.0/lib/libnpps.so -ldl -lm -lpthread -lrt -ltbb -lDUO -Wl,-rpath,/home/ubuntu/catkin_ws/duointerface/lib/linux/arm:/usr/local/cuda-7.0/lib
Thoughts? I would like to be able to keep the newer CMake on my system but don't understand enough to fix the problem. If you think this is too system-unique I will withdraw the question.
As noted by Michael Mairegger, you have to cmake in the build directory by doing
sudo cmake .. -DCUDA_USE_STATIC_CUDA_RUNTIME=false
But one extra thing I noticed is that if I try to make afterwards it won't work unless I do the cmake command twice.
I'm trying to get my own ROS package to work on a Gumstix Overo. The final goal of the project would be to get an image from the Caspa (camera) and stream it with ROS. To do so, I had the most success with the Yocto project: Pocky, which uses the BitBake cross-compile tool chain. To do so, I followed the instructions from the README.md in this GitHub repo: https://github.com/gumstix/Gumstix-YoctoProject-Repo
FYI, the instructions for the actual flashing and installing are clearer on the official Gumstix web site.
I was successful at compiling the BitBake project with all the ROS metadata and extras with the following command:
$ bitbake gumstix-console-image
(takes quite a while and lots and lots of disk space) and later on, flashing and installing.
And here is my package I tried to compile: https://github.com/elikos/groundStationPublic I tried to keep the folder as plain as possible to limit the potential path issues, so everything is at the base dir... (very ugly, I know)
Here is my CMakelist.txt:
cmake_minimum_required(VERSION 2.8.3)
project(groundStationPublic)
## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS cv_bridge image_transport roscpp rospy std_msgs genmsg)
find_package(OpenCV REQUIRED)
## Declare ROS messages and services
#add_message_files(FILES Num.msg)
#add_service_files(FILES AddTwoInts.srv)
## Generate added messages and services
#generate_messages(DEPENDENCIES std_msgs)
## Declare a catkin package
catkin_package()
include_directories(include ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
add_executable(talker talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
#add_dependencies(talker beginner_tutorials_generate_messages_cpp)
add_executable(listener listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
#add_dependencies(listener beginner_tutorials_generate_messages_cpp)
add_executable(cornerDetection main.cpp ConerDetection.cpp LineDetection.cpp ImagePublisher.cpp)
target_link_libraries(cornerDetection ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
add_executable(bonPublisher bonPublisher.cpp)
target_link_libraries(bonPublisher ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
And here is my BitBake recipe for the package:
DESCRIPTION = "Elikos groundstation code."
SECTION = "devel"
LICENSE = "BSD"
LIC_FILES_CHKSUM = "file://package.xml;beginline=8;endline=8;md5=d566ef916e9dedc494f5f793a6690ba5"
DEPENDS = "roscpp rospy catkin std-msgs"
RDEPENDS_${PN} = "roscpp rospy std-msgs"
SRC_URI = "git://github.com/elikos/groundStationPublic.git"
SRCREV = "${AUTOREV}"
PV = "1.0.0+gitr${SRCPV}"
S = "${WORKDIR}/git"
inherit catkin
ROS_SPN = "groundStationPublic"
I have located it in ~/yocto/poky/meta-ros/recipes-ros/groundStationPublic
If I execute the command bitbake groundStationPublic, everything compiles fine. No errors. (you may get an error from x264_git, but the correct sourcerev is: SRCREV = "ffc3ad4945da69f3caa2b40e4eed715a9a8d9526")
Finally, my questions are:
Where is my package located at in the image?
It's not in the /usr/share/ like I would expect it to be...
How do I run my package if rosrun can't find it? (probably because its simply not there)
I would expect it to be somthing like rosrun groundStationPublic talker
Well, finally found the answer to my own question:
I had to add my package in the image like so in ~/yocto/poky/meta-gumstix-extras/recipies-images/gumstix/gumstix-consol-image.bb:
UTILITIES_INSTALL = " \
[...]
packagegroup-ros-comm \
python-wstool \
python-email \
python-distutils \
git \
git-perltools \
python-rosinstall \
rospy-tutorials \
roscpp-tutorials \
groundStationPublic \
[...]
"
and make sure to have the UTILITIES_INSTALL added to:
IMAGE_INSTALL += " \
[...]
${UTILITIES_INSTALL} \
[...]
"
I also had to change the CMakelist.txt to explicitly tell it where to install the targets, so here is the new CMakelist.txt (note the diff in the last few lines):
cmake_minimum_required(VERSION 2.8.3)
project(groundStationPublic)
## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS cv_bridge image_transport roscpp rospy std_msgs genmsg)
find_package(OpenCV REQUIRED)
## Declare ROS messages and services
#add_message_files(FILES Num.msg)
#add_service_files(FILES AddTwoInts.srv)
## Generate added messages and services
#generate_messages(DEPENDENCIES std_msgs)
## Declare a catkin package
catkin_package()
include_directories(include ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
#add_dependencies(talker beginner_tutorials_generate_messages_cpp)
add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
#add_dependencies(listener beginner_tutorials_generate_messages_cpp)
add_executable(cornerDetection src/main.cpp src/ConerDetection.cpp src/LineDetection.cpp src/ImagePublisher.cpp)
target_link_libraries(cornerDetection ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
add_executable(bonPublisher src/bonPublisher.cpp)
target_link_libraries(bonPublisher ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
add_executable(exempleSubscriber src/exempleSubscriber.cpp)
target_link_libraries(exempleSubscriber ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
install(TARGETS talker listener cornerDetection bonPublisher exempleSubscriber
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
Unfortunatly, I'm currently experiencing problems with opencv that's not able to read the image from the caspa (from /dev/video6)... But that's a whole other problem!