Working environment:
Kubuntu 14.04 LTS 64bit
ROS Indigo (up-to-date, full desktop install)
OpenCV 2.4.8
For some unknown reason I decided to install the ros-indigo-opencv3 package which I regretted almost immediately due to the fact I also have the default version that comes with Ubuntu 14.04 - OpenCV 2.4.8.
At first I noticed that QtCreator was warning me of possible incompatibility between 2.4.8 and 3.0.0 when I was building my CMake project (you can see the CMakeLists.txt at the end of this post) using only
find_package(OpenCV REQUIRED)
Then the errors started flowing about some missing reference around the cv::stereoSGBM module. There seems to be some change in the namespaces or whatever and the library I am using uses the 2.x branch of OpenCV (found that the hard way obviously :D) hence I told myself - I guess I will remove the above mentioned ROS package for OpenCV 3.0.0 and stick with the 2.4.8.
After uninstalling that package it all went bananas. Even though in CMakeLists.txt of my project I explicitly pointed version 2.4.8. to be used
find_package(OpenCV 2.4.8 REQUIRED)
upon launching my node with roslaunch died immediately with the following error:
.../pmd_nano_node: error while loading shared libraries: libopencv_highgui.so.3.0: cannot open shared object file: No such file or directory
Huh...Okay...I checked if something has been left on my system (bad package maybe, which was unable to install and accordingly install properly?). For my surprise upon calling locate and piping the result with grep
user:~$ locate libopencv | grep 3.0
I got
/opt/ros/indigo/lib/libopencv_calib3d.so.3.0
/opt/ros/indigo/lib/libopencv_calib3d.so.3.0.0
/opt/ros/indigo/lib/libopencv_core.so.3.0
/opt/ros/indigo/lib/libopencv_core.so.3.0.0
...
(basically all opencv libs)
So something was left there after all (with something I mean everything :D). However imagine my surprise when I cd-ed to the /opt/ros/indigo/lib/ and found NOT A SINGLE file even remotely related to OpenCV let alone OpenCV 3.0.0.
Using pkg-config returns what I am expecting at least:
user:~$ pkg-config --cflags opencv
-I/usr/include/opencv
user:~$ pkg-config --libs opencv
/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so ...
-lopencv_calib3d ...
Note: I still don't know why --cflags never shows the opencv2 include folder (opencv2 as argument is not recognized by pkg-config)
Further investigation made me re-run my CMakeLists.txt for my project with the 3.0.0 version as requirement and indeed CMake now complains that only 2.4.8 is found. For what reason though the application tries to get the 3.0.0 version of OpenCV's shared libs remains to be seen.
Any advice or someone who has encountered such problem before?
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(pmd_nano)
SET(CMAKE_CXX_FLAGS "-std=c++0x -fpermissive -Wno-deprecated -Wno-sign-compare")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wall")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_CXX_LINK_FLAGS_DEBUG "-pg")
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
pcl_conversions
pcl_msgs
pcl_ros
roscpp
sensor_msgs
std_msgs
)
## System dependencies are found with CMake's conventions
find_package(Boost REQUIRED COMPONENTS system)
find_package(PCL REQUIRED)
find_package(OpenCV 2.4.8 REQUIRED COMPONENTS highgui imgproc)
# Do NOT use OpenCV 3.0.0 or all hell will break loose. Package incompatilibity will be a fascinating thing to deal with...
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS include
# LIBRARIES pmd_nano
CATKIN_DEPENDS cv_bridge image_transport pcl_conversions pcl_msgs pcl_ros roscpp sensor_msgs std_msgs uvc_camera
DEPENDS
system_lib # Boost PCL OpenCV
boost_system
PCL
opencv_highgui opencv_imgproc
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
## Declare a cpp library
# add_library(pmd_nano
# src/${PROJECT_NAME}/pmd_nano_node.cpp
# )
## Declare a cpp executable
add_executable(pmd_nano_node
src/pmd_nano_node.cpp
src/ColorCamera.cpp
src/DepthCamera.cpp
src/PMDNano.cpp
)
## Add cmake target dependencies of the executable/library
## as an example, message headers may need to be generated before nodes
# add_dependencies(pmd_nano_node pmd_nano_generate_messages_cpp)
## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES})
#link_directories(${PROJECT_NAME}_node ${Boost_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME}_node boost_system)
link_directories(${PROJECT_NAME}_node ${PCL_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME}_node opencv_highgui opencv_imgproc)
target_link_libraries(${PROJECT_NAME}_node pthread)
target_link_libraries(pmd_nano_node ${PROJECT_SOURCE_DIR}/lib/libpmdaccess2.so)
#############
## Testing ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_pmd_nano.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
EDIT:
Running sudo updatedb at least resolved the locate issue. The error during runtime is still present though.
Found the solution. It seemed that my workspace was a mess because of the removal of the package. So after I deleted devel and build followed by a quick catkin_make it runs fine now.
Related
I am encountering a namespace issue when using ROS, OpenCV's dnn module, and CLion. The issue seems to be exclusive to the DNN module, as the other ROS and OpenCV functions work fine. While my code seems to compile and build fine, I am getting the lint error: No member named readNetFromDarknet in namespace 'cv::dnn'. The error happens everywhere I am accessing anything in the DNN module.
Defined in my header file:
cv::dnn::Net net;
yields the error No type named Net in namespace 'cv::dnn'.
Defined in my class file:
void HumanDetector::setupNetwork() {
net = cv::dnn::readNetFromDarknet(MODEL_CONFIG, MODEL_WEIGHTS);
net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
}
yields a similar problem.
In CLion, however, I can Ctrl+Click any of the alleged undefined members or types and see the source code for them. I suspect that it might have something to do with my CMakeLists config or IDE setup. Here is my cmake file:
cmake_minimum_required(VERSION 2.8.3)
project(followbot)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
set(CATKIN_ENABLE_TESTING OFF)
set(OpenCV_LIBRARY_DIR /usr/local/lib)
set(OpenCV_DIR "/usr/local/lib")
## Find catkin macros and libraries
find_package(OpenCV 4.1.2 REQUIRED PATHS /usr/local NO_DEFAULT_PATH)
find_package(catkin REQUIRED COMPONENTS
roscpp
geometry_msgs
std_msgs
message_generation
teb_local_planner
)
add_message_files(
FILES
Point2.msg
)
generate_messages(
DEPENDENCIES
)
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS
roscpp
message_generation
message_runtime
std_msgs
geometry_msgs
teb_local_planner
DEPENDS OpenCV
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
include
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
add_executable(${PROJECT_NAME} src/node.cpp src/cloud.cpp src/human.cpp)
## Link the executable to the OpenCV libraries
link_directories(${OpenCV_LIBRARY_DIR})
target_link_libraries(followbot ${OpenCV_LIBRARIES} ${catkin_LIBRARIES})
I am currently using CMake to create a static library which utilizes a few of the static libraries from OpenCV 4 ( core imgcodecs video highgui imgproc ). My intention is to be able to bundle all of the required OpenCV static libraries into my own library so that I can distribute it as one library. Additionally, I want for the user of my library to not have to install OpenCV 4 on their system (but do not mind if the user has to do simple installs using apt-get install). I know there are tools for bundling static libraries (such as using ar for linux).
However, where I really am having the issue is with all the dependencies of OpenCV (such as libjpeg, libpng, etc). I don't necessarily mind if these libraries are bundled with mine or linked dynamically as they are relatively easy to install (can be installed with sudo apt-get install, whereas opencv4 needs to be built from source).
What is the best way to go about doing this?
This is my current CMakeLists.txt
It is currently working, but that is because I am using find_package(OpenCV REQUIRED) (which defeats the purpose of what I am trying to do). When I remove that line, the linker complains about not being able to find the OpenCV dependencies.
cmake_minimum_required(VERSION 2.8)
project(myproject)
set(CMAKE_CXX_STANDARD 14)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
link_directories(${CMAKE_CURRENT_LIST_DIR}/lib)
find_package(OpenMP REQUIRED)
find_package(OpenCV REQUIRED)
set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(nlohmann_json)
list(APPEND LINKER_LIBS opencv_core opencv_highgui opencv_video opencv_imgcodecs libmxnet.so libncnn.a nlohmann_json::nlohmann_json)
file(GLOB SRC${CMAKE_CURRENT_LIST_DIR}/src/*.cpp${CMAKE_CURRENT_LIST_DIR}/main.cpp)
add_library(myproject ${SRC})
target_link_libraries(myproject ${LINKER_LIBS} ${OpenMP_CXX_FLAGS})
To elaborate on my question. I build my project which generates libmyproject.a. I then take this library and will eventually extract the symbols from the OpenCV libs (libopencv_core.a libopencv_highgui.a libopencv_imgcodecs.a libopencv_video.a) and add them to my lib (for the time being, I have not yet done this step, which is why in the below example I am linking libopencv_*). I then use my library in a new project, for which the CMakeLists.txt is shown below:
cmake_minimum_required(VERSION 2.8)
project(myproject-driver)
set(CMAKE_CXX_STANDARD 14)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
link_directories(${CMAKE_CURRENT_LIST_DIR}/lib)
find_package(OpenMP REQUIRED)
add_executable(myproject-driver main.cpp)
target_link_libraries(myproject-driver myproject libncnn.a ${OpenMP_CXX_FLAGS} libmxnet.so libopencv_core.a libopencv_highgui.a libopencv_imgcodecs.a libopencv_video.a)
Building this generates the following errors:
Linking CXX executable myproject-driver
/usr/bin/ld: /home/nchafni/Cyrus/myproject/lib/libopencv_imgcodecs.a(grfmt_jpeg.cpp.o): undefined reference to symbol 'jpeg_default_qtables##LIBJPEG_8.0'
//usr/lib/x86_64-linux-gnu/libjpeg.so.8: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
How can I fix this. Is there some CMake command which will link all these dependencies for me? Do I need to manually track down each dependency of those libopencv_* libs and link those manually? Once again, this is assuming that the person using libmyproject.a can't use find_package(OpenCV REQUIRED) as it won't be defined as they have not installed OpenCV on their machine.
First of all, don't use the super old and outdated version 2.8 of CMake. CMake 3.x is so much more powerful and pretty straightforward to use.
Some tips for modern CMake.
Don't use file(GLOB), see here why that is.
Don't use directory wide instructions, rather use target instructions, e.g. target_include_directories vs. include_directories.
Don't use string variables like ${<PACKAGE_NAME>_LIBRARIES}, rather use targets, e.g. <Package_NAME>::lib
When using targets instead of string variables, all the properties (including LINK_INTERFACE) of that target will be populated to the library/executable when calling target_link_libraries, so no more include_directories,link_directories, etc.
myproject
cmake_minimum_required(VERSION 3.14)
project(myproject)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenMP REQUIRED)
find_package(OpenCV REQUIRED)
set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(nlohmann_json)
set(SOURCES ...) # list all the source files here
add_library(myproject ${SOURCES})
target_include_directories(myproject PUBLIC # give it a scope
${CMAKE_CURRENT_LIST_DIR}/include
)
target_link_libraries(myproject PUBLIC # give it a scope
opencv_core # using the target, you will get all LINK_LIBRARIES
opencv_highgui
opencv_video
opencv_imgcodecs
libmxnet.so # where is this coming from?
libncnn.a # where is this coming from?
nlohmann_json::nlohmann_json
OpenMP::OpenMP_CXX ## linking against a target, CXX_FLAGS will be populated automatically
)
myprojec-driver
cmake_minimum_required(VERSION 3.14)
project(myproject-driver)
set(CMAKE_CXX_STANDARD 14)
add_executable(myproject-driver main.cpp)
target_link_libraries(myproject-driver PUBLIC # give it a scope
myproject # gets all dependencies through the LINK_INTERFACE
)
I am trying to catkin build this ROS package https://github.com/toddhester/rl-texplore-ros-pkg but it fails to build 'rl_experiment' with the following error:
/usr/bin/ld: cannot find -lagentlib
/usr/bin/ld: cannot find -lenvlib
collect2: error: ld returned 1 exit status
I am using ROS Kinetic. The shared libraries does exist in the folders /texplore/devel/.private/rl_env/lib/ and /texplore/devel/.private/rl_agent/lib/ with symlinks at /texplore/devel/lib/
I tried the following:
(1) export /texplore/devel/lib/ to LD_LIBRARY_PATH
(2) adding symlinks to the libraries in /texplore/src/rl_experiment/src
(3) adding the library paths to target_link_libraries
target_link_libraries(experiment agentlib envlib ${catkin_LIBRARIES}
"/media/usr/texplore/devel/lib/libagentlib.so"
"/media/usr/texplore/devel/lib/libenvlib.so")
(4) set the search path for linker
SET(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,/media/usr/texplore/devel/lib/")
It didn't work. Lastly, I added the symlinks to /usr/local/lib and it worked. But I do not want the symlinks in this folder.
So the linker is simply not searching the build tree. My question is, why did catkin not add the linker path in catkin_LIBRARIES? I have built ROS packages before but can't wrap my head around why this particular package is not working.
I ran into the same issue. I made the following changes based on this post on ROS Answers and the below comment in the generic CMakeLists.txt file for the catkin_packages macro:
## LIBRARIES: libraries you create in this project that dependent projects also need
I did a few things to fix this...
Added
LIBRARIES agentlib to the catkin_packages macro in the rl_agent/CMakeLists.txt file. This makes the agentlib library available later to rl_experiment.
Added LIBRARIES envlib to the catkin_packages macro in the rl_env/CMakeLists.txt file. This makes the envlib library available later to rl_experiment.
Removed agentlib and envlib from the target_link_libraries macro in the rl_experiment/CMakeLists.txt file. These are not necessary.
Verified rl_agent and rl_env packages are listed in the find_package macro of the rl_experiment/CMakeLists.txt.
...then everything successfully compiled.
Adding snippets for further clarification...
rl_agent CMakeLists.TXT Changes (item 1 above):
...
## Declare a cpp library
# add_library(rgbd_tools
# src/${PROJECT_NAME}/
# )
add_library(agentlib
src/Agent/DiscretizationAgent.cc
src/Agent/QLearner.cc
...
src/newmat/newmatrm.cc
src/newmat/newmat9.cc
)
## Declare a cpp executable
# add_executable(rgbd_tools_node src/rgbd_tools_node.cpp)
...
rl_env CMakeLists.txt Changes (item 2 above):
...
###################################
## catkin specific configuration ##
###################################
...
catkin_package(
INCLUDE_DIRS include
LIBRARIES envlib
# CATKIN_DEPENDS roscpp rospy std_msgs
CATKIN_DEPENDS message_runtime
# DEPENDS system_lib
)
...
rl_experiment CMakeLists.txt Changes (items 3 & 4 above):
...
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
rl_common
rl_env
rl_agent
)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
...
## Declare a cpp executable
# add_executable(rgbd_tools_node src/rgbd_tools_node.cpp)
add_executable(experiment src/rl.cc)
# target_link_libraries(experiment agentlib envlib ${catkin_LIBRARIES})
target_link_libraries(experiment ${catkin_LIBRARIES})
#add_executable(image_converter src/image_converter.cpp)
...
I was able to compile Freetype2 library for arm, arm64, x86, x86_64 architectures. These are steps I done to compile it.
Created standalone toolchains for architectures mentioned above.
make_standalone_toolchain.py \
--arch arm64 \
--api 26 \
--stl=libc++ \
--install-dir=my-arm64-toolchain
Set some envirement variables
export PATH=$PATH:`pwd`/my-toolchain/bin
target_host=aarch64-linux-android
export AR=$target_host-ar
export AS=$target_host-as
export CC=$target_host-gcc
export CXX=$target_host-g++
export LD=$target_host-ld
export STRIP=$target_host-strip
export CFLAGS="-fPIE -fPIC"
export LDFLAGS="-pie"
Configure freetype for compilation
./configure --host=aarch64-linux-android --prefix=/home/freetype-arm64 --without-zlib --without-harfbuzz --with-png=no
And finally make && install
Compilation was successfull and I was able to get Static freetype library.
I added library to my android studio libs folder.
This is folder structure for library:
libs---freetype
|---${ANDROID_ABI}
|---include
|---freetype2
|---freetype
---|Bunch of header files
|---ftbuild.h
|---lib
|---libfreetype.a
This is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.4.1)
add_definitions("-DGLM_FORCE_SIZE_T_LENGTH -DGLM_FORCE_RADIANS")
add_subdirectory(src/main/cpp/glm)
add_library(freetype STATIC IMPORTED)
set_target_properties(freetype PROPERTIES IMPORTED_LOCATION${PROJECT_SOURCE_DIR}/libs/freetype/${ANDROID_ABI}/lib/libfreetype.a)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Wall")
add_library(native-lib SHARED
src/main/cpp/native-lib.cpp
src/main/cpp/graph.cpp
src/main/cpp/text.cpp
src/main/cpp/graphDataWorker.cpp
)
target_include_directories(native-lib PRIVATE ${PROJECT_SOURCE_DIR}/libs/freetype/${ANDROID_ABI}/include/freetype2)
target_link_libraries(native-lib
android
freetype
GLESv2
EGL
glm
atomic
log
OpenSLES
)
The problem is that I can use library inside my code and android studio is not giving me any errors, but then i try to run application it gives me this error:
linker command failed with exit code 1 (use -v to see invocation)
PS: I Can't see freetype headers in android studio file tree aswell, but can see other libraries.
Question: Am I importing library in a wrong way or this is cross-compilation issue and if so how to do it properly?
I done a lot of research on this issue and was unable to find a solution
Any help will be appreciated.
Unless you mixed paths when installing your build of FreeType2, it seems that the compilation of the library is incorrect, since the linker complains about the library being for x86_64 architecture.
On Linux, usually you can check the architecture the library is built for with command file. Another way to check the architecture is to use the objdump tool that is shipped with Android NDK (if I remember correctly it is generated with a toolchain as well). Its name follows the same pattern than the compiler/linker/... tools, $target_host-objdump.
I would recommend to compile FreeType2 using CMake instead of autotools, at least in my case I successfully did it that way.
Here is a sample of CMake configuration I wrote to cross-compile FreeType2 for Android. It is a little complex because it is part of a project where I build several libraries.
The idea is that my CMake configuration uses ExternalProject to download and compile Freetype. My top-level CMakeLists.txt contains:
# CMakeLists.txt
set(DEVENV_CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_C_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_C_FLAGS_${BUILD_TYPE}=${CMAKE_C_FLAGS_${BUILD_TYPE}}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_CXX_FLAGS_${BUILD_TYPE}=${CMAKE_CXX_FLAGS_${BUILD_TYPE}}
-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
-DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}
)
if(BUILD_SHARED_LIBS)
list(APPEND DEVENV_CMAKE_ARGS -DBUILD_STATIC_LIBS=OFF -DLIBTYPE=SHARED)
else()
list(APPEND DEVENV_CMAKE_ARGS -DBUILD_STATIC_LIBS=ON -DLIBTYPE=STATIC)
endif()
if(DEFINED ANDROID_TOOLCHAIN_DIR)
get_filename_component(_toolchain_dir ${ANDROID_TOOLCHAIN_DIR} ABSOLUTE)
list(APPEND DEVENV_CMAKE_ARGS -DANDROID_TOOLCHAIN_DIR=${_toolchain_dir})
endif()
if(DEFINED CMAKE_ANDROID_ARCH_ABI)
list(APPEND DEVENV_CMAKE_ARGS -DCMAKE_ANDROID_ARCH_ABI=${CMAKE_ANDROID_ARCH_ABI})
endif()
if(CMAKE_TOOLCHAIN_FILE)
get_filename_component(_toolchain_file ${CMAKE_TOOLCHAIN_FILE} ABSOLUTE)
list(APPEND DEVENV_CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${_toolchain_file})
endif()
add_subdirectory(freetype)
So the variable DEVENV_CMAKE_ARGS contains appropriate CMake arguments for cross-compiling that reflect my current CMake configuration. Under directory freetype, the CMakeLists.txt contains:
# freetype/CMakeLists.txt
project(freetype)
include(ExternalProject)
if(NOT FREETYPE_GIT_REPOSITORY)
set(FREETYPE_GIT_REPOSITORY "https://git.savannah.gnu.org/git/freetype/freetype2.git")
endif()
set(FREETYPE_GIT_REPOSITORY "${FREETYPE_GIT_REPOSITORY}"
CACHE STRING "Git repository for library Freetype."
)
if(NOT FREETYPE_GIT_TAG)
set(FREETYPE_GIT_TAG "VER-2-9")
endif()
set(FREETYPE_GIT_TAG "${FREETYPE_GIT_TAG}"
CACHE STRING "Tag or branch of Git repository to build."
)
message(STATUS "Freetype Git repository: ${FREETYPE_GIT_REPOSITORY}")
message(STATUS "Freetype Git tag: ${FREETYPE_GIT_TAG}")
externalproject_add(freetype
GIT_REPOSITORY "${FREETYPE_GIT_REPOSITORY}"
GIT_TAG "${FREETYPE_GIT_TAG}"
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/freetype/src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/freetype/build"
CMAKE_ARGS ${DEVENV_CMAKE_ARGS}
)
Basically this CMakeLists.txt uses ExternalProject to download and compile FreeType2 in the build directory.
And I use a toolchain file for Android:
# android.cmake
set(CMAKE_SYSTEM_NAME "Android")
set(CMAKE_ANDROID_STANDALONE_TOOLCHAIN ${ANDROID_TOOLCHAIN_DIR})
Sorry if it is overly complex; it comes from a project where I was playing with cross-compiling for Android. I hope it helps anyway.
I have installed opencv2.4.9(With No CUDA) by unzip opencv2.4.9.zip in home.
Many successful codes are using this library.
Now I wanna rebuild opencv2.4.9(with CUDA) in another folder.
I don't wanna delete the previous folder because I don't wanna face any problem later on and make my older code can't function.
So, the question is how to change the name of the directory? Seems like we link the package with library in CMake like below:
include_directories( ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} )
find_package( OpenCV REQUIRED )
find_package(catkin REQUIRED COMPONENTS cv_bridge image_transport
OpenCV roscpp rospy std_msgs )
the name of directory is just OpenCV.
So if I got more than one OpenCV library in home, how could I link them separately?
And how to make c++ link to the library if we could change the name?
add_executable(xxx src/xxx.cpp)
target_link_libraries(xxx ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
Libraries can be included and linked with include_directories() and link_directories(), like this:
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
...
include_directories(${PROJECT_SOURCE_DIR})
include_directories(/path/to/opencv/OpenCV-2.4.1/include)
link_directories(/path/to/opencv/OpenCV-2.4.1/lib)
...
# Set the build type. Options are:
# Coverage : w/ debug symbols, w/o op ...
So you should not forget the linking in the CMakeLists.txt and maybe remove the standard linking to your current OpenCV libs.