I hope you can help me.
I have a simple CMakeLists.txt in order to build my project on Leopard 10.5.8.
I'm using CMake 2.8.1 and at the moment this is the code:
cmake_minimum_required(VERSION 2.8)
MESSAGE(STATUS "./src: Going into utils folder")
ADD_SUBDIRECTORY(utils)
MESSAGE(STATUS "./src: utils folder processed")
include_directories(${DIR}/headers)
link_directories (${DIR}/src/utils)
ADD_EXECUTABLE(sample sample.cpp)
TARGET_LINK_LIBRARIES(sample libSample ${EXTERNAL_LIBS})
INSTALL(TARGETS sample DESTINATION "./src")
MESSAGE(STATUS "./src: exiting src folder")
I need to add OpenCV libraries on my project.
When I use Eclipse I set the include path to /opt/local/include
and the libraries path to: /opt/local/lib and then I specify the libraries name such as_ opencv_core, opencv_imgproc, opencv_video.
Can you tell me how to add these information in the CMakeLists.txt file, please?
I've read some information in the official cmake FAQ but i wasn't able to solve my problem.
Please, help me.
Thanks a lot.
You need to add the library names in the TARGET_LINK_LIBRARIES command, but you need to add them without the lib prefix. For example:
include_directories(${DIR}/headers /opt/local/include)
link_directories (${DIR}/src/utils /opt/local/lib)
ADD_EXECUTABLE(sample sample.cpp)
TARGET_LINK_LIBRARIES(sample opencv_core opencv_imgproc opencv_video ${EXTERNAL_LIBS})
Related
Setting up swift-corelibs-xctest for Swift - Windows 10. When file CMakeLists.txt is called find_package is ran to look for FoundationConfig.cmake file
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
find_package(dispatch CONFIG REQUIRED)
find_package(Foundation CONFIG REQUIRED)
endif()
FoundationConfig.cmake is found but error "include could not find load file: #Foundation_EXPORTS_FILE#"
I'm pretty sure this is due to fact that Foundation file is in a different directory. I only need clarification as to what # Foundation_EXPORTS_FILE# means. I have been unable to find any reference to _EXPORTS_FILE.
Believe I found part of what I was lookin for here.
https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/ExportInterface
The other half of the problem was found here -
default search paths for CMake include() vs. find_package()
"include(#Foundation_EXPORTS_FILE#)" Was in reference to the two config files, which are not in the same location, also include() searches for files in CMAKE_MODULE_PATH --- message("Path- ${CMAKE_MODULE_PATH}")
I'm trying to load OpenCV Libraries in CMakeFile.txt but it always ends with this error:
CMake Error at CMakeLists.txt:21 (target_link_libraries):
Cannot specify link libraries for target "HelloWorld" which is not built by
this project.
I've searched on the Internet but have got no solution.
cmake_minimum_required(VERSION 3.8)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/KotlinCMakeModule)
project(untitled1 Kotlin)
find_package(OpenCV REQUIRED)
IF (OpenCV_FOUND)
include_directories(/usr/local/Cellar/opencv/3.4.0_1/include)
link_libraries(/usr/local/Cellar/opencv/3.4.0_1/lib)
ENDIF(OpenCV_FOUND)
konanc_executable(
NAME HelloWorld
SOURCES hello.kt
)
target_link_libraries(HelloWorld
/usr/local/Cellar/opencv/3.4.0_1/lib
)
Someone can help me? I think it's not working because on the use of konanc_executable instead of add_executable but I need to use Kotlin so I cannot use the add_executable command.
I have installed Opencv-3.2 and I can see the bin and lib files
$ ls /share/apps/computer/opencv-3.2.0/built/bin/opencv_
opencv_annotation opencv_createsamples opencv_traincascade opencv_version opencv_visualisation
$ ls /share/apps/computer/opencv-3.2.0/built/lib/
libopencv_calib3d.so libopencv_imgcodecs.so.3.2.0 libopencv_stitching.so.3.2
libopencv_calib3d.so.3.2 libopencv_imgproc.so libopencv_stitching.so.3.2.0
libopencv_calib3d.so.3.2.0 libopencv_imgproc.so.3.2 libopencv_superres.so
libopencv_core.so libopencv_imgproc.so.3.2.0 libopencv_superres.so.3.2
libopencv_core.so.3.2 libopencv_ml.so libopencv_superres.so.3.2.0
libopencv_core.so.3.2.0 libopencv_ml.so.3.2 libopencv_videoio.so
libopencv_features2d.so libopencv_ml.so.3.2.0 libopencv_videoio.so.3.2
libopencv_features2d.so.3.2 libopencv_objdetect.so libopencv_videoio.so.3.2.0
libopencv_features2d.so.3.2.0 libopencv_objdetect.so.3.2 libopencv_video.so
libopencv_flann.so libopencv_objdetect.so.3.2.0 libopencv_video.so.3.2
libopencv_flann.so.3.2 libopencv_photo.so libopencv_video.so.3.2.0
libopencv_flann.so.3.2.0 libopencv_photo.so.3.2 libopencv_videostab.so
libopencv_highgui.so libopencv_photo.so.3.2.0 libopencv_videostab.so.3.2
libopencv_highgui.so.3.2 libopencv_shape.so libopencv_videostab.so.3.2.0
libopencv_highgui.so.3.2.0 libopencv_shape.so.3.2 pkgconfig/
libopencv_imgcodecs.so libopencv_shape.so.3.2.0
libopencv_imgcodecs.so.3.2 libopencv_stitching.so
Now, according to the tutorial, I wrote a simple program. Problem is that, cmake gets some errors and seems that it is not able to find the library.
CMake Error at CMakeLists.txt:3 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
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.
I don't know how to set CMAKE_PREFIX_PATH or OpenCV_DIR. How can I fix that?
The content of CMakeLists.txt is
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
It depends whether you have OpenCVConfig.cmake script, which comes with your installation of OpenCV (that is, under install directory /share/apps/computer/opencv-3.2.0/built/).
If your installation of OpenCV lacks of OpenCVConfig.cmake script, you need to ship your project with script FindOpenCV.cmake (find and copy it from the net, almost any of them is suitable), and add directory with this script to CMAKE_MODULE_PATH variable:
list(APPEND CMAKE_MODULE_PATH <directory-with-find-script>)
Possible ways to hint CMake about your installation of OpenCV:
If you have OpenCVConfig.cmake script, set OpenCV_DIR variable to directory contained this script:
cmake -DOpenCV_DIR=/share/apps/computer/opencv-3.2.0/built/<...>
Set CMAKE_PREFIX_PATH variable to installation prefix of OpenCV:
cmake -DCMAKE_PREFIX_PATH=/share/apps/computer/opencv-3.2.0/built
This works both with OpenCVConfig.cmake and with FindOpenCV.cmake scripts. See also that question: Hinting Find<name>.cmake Files with a custom directory.
I'm trying to compile a ROS project involving catkin_make. The project involves - amongst others- a tool to convert opencv matrices to ros matrices called cv_bridge. However, when trying to compile my catkin_ws I'm getting the following error:
CMake Error at cv_bridge/test/CMakeLists.txt:7 (target_link_libraries):
Cannot specify link libraries for target "cv_bridge-utest" which is not
built by this project.
Does anyone know this error? I'm quite new to ROS, so I'm not sure how to tell ROS to compile the entire catkin_ws/src directory. In that latter folder all necessary folders should be present. There is also catkin_ws/src/cv_bridge but maybe it tries to compile the folder in the wrong order ...
I don't know what you have written in your CMakeLists. Supposing that the error lays there, you can use a CMakeLists.txt like this:
cmake_minimum_required(VERSION 2.8.3)
project(your_project)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
cv_bridge
)
find_package(OpenCV REQUIRED)
###########
## Build ##
###########
catkin_package()
include_directories(
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
include
)
add_executable(executable src/your_file.cpp)
target_link_libraries(executable ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
In your package.xml add these lines:
<build_depend>opencv2</build_depend>
<build_depend>cv_bridge</build_depend>
<run_depend>opencv2</run_depend>
<run_depend>cv_bridge</run_depend>
To compile the folder you just have to go to your catkin directory and type: catkin_make
If you have built your workspace in the right way, it should compile without error.
My problem is similar with this: http://www.eclipse.org/forums/index.php/m/649323/
I created a cmake project, and used
cmake .. -G "Eclipse CDT4 - Unix Makefiles"
to create a Eclipse CDT4 project.
But in the CDT IDE, the standard include paths are not listed, and all STL or system build-in header files include directives are marked as "cannot be resolved", so the "Open Declaration" or other a lot of operation cannot be done.
However, I could compile it without any problems.
My co-worker also has a cmake project, but it's very complicated. The CDT project generated from his cmake project DOES have the system includes. But his cmake is way too complicated, and he told me that he didn't do anything special to include the system paths.
Can anyone help me out? Thanks.
My Main CMakeLists.txt:
CMake_Minimum_Required(VERSION 2.8)
# Some settings
Set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
CMake_Policy(SET CMP0015 NEW)
#Include(CMakeProcedures.cmake)
#CheckEnvironment()
# Set the compiler and its version if needed
# Create the project
Project(MyProjectName CXX)
# Set the compiler
Set(CMAKE_CXX_COMPILER /usr/bin/g++)
# Detect whether we are in-source
If (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
Message(FATAL_ERROR "In-source building is not allowed! Please create a 'build' folder and then do 'cd build; cmake ..'")
EndIf()
# Set the output dirs
Set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
Set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
# Add source subdirs to the build
Add_Subdirectory(src)
# Add_Subdirectory(test EXCLUDE_FROM_ALL)
Peter
One workaround is to manually add these to the CDT IDE:
/usr/include/c++/4.5
/usr/include/c++/4.5/backward
/usr/include/c++/4.5/i686-linux-gnu
/usr/include/i386-linux-gnu
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/include
/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/include-fixed
/usr/local/include
But it's not the solution.
I finally figured out that this line is causing the problem:
Project(MyProjectName CXX)
If we remove the optional paramter CXX, life is good.
Can anyone tell me why?
Peter