Building error in ROS environment (catkin) - c++

I want to build my project in catkin workspace. After executing catkin_make i got these errors:
6:11: error: ‘vector’ is not a member of ‘cv’
cv::vector<cv::Point> points;
6:31: error: expected primary-expression before ‘>’ token
cv::vector<cv::Point> points;
9:77: error: no matching function for call to ‘std::vector<Eigen::Matrix<double, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<double, 3, 1> > >::push_back(cv::Point)’
/catkin_ws/src/rgbd_calibration/src/rgbd_calibration/calibration_test.cpp:1123:113: error: no matching function for call to ‘fillConvexPoly(cv::Mat&, std::vector<Eigen::Matrix<double, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<double, 3, 1> > >&, cv::Scalar)’
cv::fillConvexPoly(tmp_image, points, cv::Scalar(c == 0 ? 128 : 0, c == 1 ? 128 : 0, c == 2 ? 128 : 0));
^
In file included from /opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/imgproc/imgproc.hpp:48:0,
from /opt/ros/kinetic/include/image_geometry/pinhole_camera_model.h:6,
I have build opencv 3.3.0, and also it finds `/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/imgproc/imgproc.hpp:48:0,
I suspect that somthing has to do with opencv library but cant find out. Its my first try with ROS so any help would be welcomed
Makefile below:
cmake_minimum_required(VERSION 2.8.3)
project(rgbd_calibration)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
## 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 cmake_modules roscpp calibration_common geometry_msgs kinect
eigen_conversions camera_info_manager cv_bridge pcl_ros
image_transport)# swissranger_camera)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
find_package(Boost REQUIRED)
find_package(Eigen REQUIRED)
find_package(PCL 1.7 REQUIRED)
find_package(OpenCV REQUIRED)
find_package(OpenMP REQUIRED)
find_package(Ceres REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
## Uncomment this if the package has a setup.py. This macro ensures
## modules and scripts declared therein get installed
# catkin_python_setup()
#######################################
## Declare ROS messages and services ##
#######################################
## Generate messages in the 'msg' folder
add_message_files(
FILES
Acquisition.msg
)
## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )
## Generate added messages and services with any dependencies listed here
generate_messages(
DEPENDENCIES
std_msgs
)
###################################################
## Declare things to be passed to other projects ##
###################################################
## 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 interactive_checkerboard_finder rgbd_calibration
CATKIN_DEPENDS roscpp calibration_common geometry_msgs kinect
eigen_conversions camera_info_manager cv_bridge pcl_ros image_transport
DEPENDS eigen3 pcl opencv2
)
###########
## Build ##
###########
## Specify additional locations of header files
include_directories(include
${catkin_INCLUDE_DIRS}
${EIGEN_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
${CERES_INCLUDE_DIRS}
)
## Declare a cpp library
add_library(rgbd_calibration
src/rgbd_calibration/calibration.cpp include/rgbd_calibration/calibration.h
include/rgbd_calibration/globals.h
src/rgbd_calibration/depth_undistortion_estimation.cpp include/rgbd_calibration/depth_undistortion_estimation.h
src/rgbd_calibration/checkerboard_views.cpp include/rgbd_calibration/checkerboard_views.h
src/rgbd_calibration/checkerboard_views_extractor.cpp include/rgbd_calibration/checkerboard_views_extractor.h
src/rgbd_calibration/publisher.cpp include/rgbd_calibration/publisher.h
)
add_executable(rgbd_offline_calibration
src/rgbd_calibration/calibration_node.cpp include/rgbd_calibration/calibration_node.h
src/rgbd_calibration/offline_calibration_node.cpp include/rgbd_calibration/offline_calibration_node.h
)
#add_executable(simulation
# src/rgbd_calibration/simulation_node.cpp include/rgbd_calibration/simulation_node.h
#)
add_executable(test_calibration
src/rgbd_calibration/test_node.cpp include/rgbd_calibration/test_node.h
src/rgbd_calibration/calibration_test.cpp include/rgbd_calibration/calibration_test.h
)
add_executable(data_collection
src/rgbd_calibration/data_collection_node.cpp
)
## Add dependencies to the executable
# add_dependencies(calibration_node ${PROJECT_NAME})
## Specify libraries to link a library or executable target against
target_link_libraries(rgbd_calibration
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${OpenCV_LIBS}
${CERES_LIBRARIES}
)
target_link_libraries(rgbd_offline_calibration
rgbd_calibration
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${OpenCV_LIBS}
${CERES_LIBRARIES}
)
#target_link_libraries(simulation
# rgbd_calibration
# ${catkin_LIBRARIES}
# ${PCL_LIBRARIES}
# ${OpenCV_LIBS}
# ${CERES_LIBRARIES}
#)
target_link_libraries(test_calibration
rgbd_calibration
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${OpenCV_LIBS}
${CERES_LIBRARIES}
)
target_link_libraries(data_collection
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${OpenCV_LIBS}
)
#############
## Install ##
#############
## Mark executable scripts (Python etc.) for installation
## not required for python when using catkin_python_setup()
# install(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark executables and/or libraries for installation
# install(TARGETS calibration calibration_node
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# )
## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )
#############
## Testing ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/polynomial_undistortion_matrix_multifit_test.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test
# ${catkin_LIBRARIES}
# ${PCL_LIBRARIES}
# ${OpenCV_LIBS}
# ${CERES_LIBRARIES})
# endif()
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)

You need to use STL's std::vector<>, CV does not have a vector implementation:
#include <vector>
...
std::vector<cv::Point> points;
...

Related

undefined reference to 'QVTKWidget::QVTKWidget'

The env is VTK-8.0 ITK-5.2 QT-5.12
This error occurs when I compile this cmake file:
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(QtDICOMViewer)
find_package(VTK REQUIRED)
#find_package(VTK COMPONENTS
# vtkCommonCore
# vtkFiltersSources
# vtkGUISupportQt
# vtkIOImage
# vtkInteractionImage
# vtkFiltersCore
# vtkInfovisCore
# vtkInteractionStyle
# vtkViewsQt
# vtkCommonDataModel
# vtkCommonExecutionModel
# vtkRenderingCore
# vtkRenderingFreeType
# vtkRenderingOpenGL2
# )
include(${VTK_USE_FILE})
if("${VTK_QT_VERSION}" STREQUAL "")
message(FATAL_ERROR "VTK was not built with Qt")
endif()
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
# Set your files and resources here
set( Srcs main.cpp mainwindow.cpp)
set( Hdrs mainwindow.h )
set( MOC_Hdrs mainwindow.h )
set( UIs mainwindow.ui )
set( QRCs images.qrc )
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 COMPONENTS Widgets REQUIRED QUIET)
qt5_wrap_ui(UI_Srcs ${UIs})
qt5_add_resources(QRC_Srcs ${QRCs} )
source_group("Resources" FILES
${UIs}
${QRCs}
${EXE_ICON} # Not present
)
source_group("Generated" FILES
${UI_Srcs}
${MOC_Srcs}
${QRC_Srcs}
)
include_directories(/usr/include/gdcm-2.6)
# CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.
add_executable(QtDICOMViewer MACOSX_BUNDLE ${Srcs} ${Hdrs} ${UI_Srcs} ${MOC_Hdrs} ${QRC_Srcs})
qt5_use_modules(QtDICOMViewer Core Gui Widgets)
target_link_libraries(QtDICOMViewer ${VTK_LIBRARIES} ${ITK_LIBRARIES})
And the error is:
undefined reference to 'QVTKWidget::QVTKWidget' in ui.mainwindow.h:xxx
There is no LINK errors and any include fault, just can't detect this variable. I'm struggling in it all day:( But when I compile the example in VTK/Examples, nothing fails. The example CMakeLists is:
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(QtVTKRenderWindows)
find_package(VTK COMPONENTS
vtkCommonCore
vtkFiltersSources
vtkGUISupportQt
vtkIOImage
vtkInteractionImage
vtkFiltersCore
vtkInfovisCore
vtkInteractionStyle
vtkViewsQt
)
include(${VTK_USE_FILE})
if("${VTK_QT_VERSION}" STREQUAL "")
message(FATAL_ERROR "VTK was not built with Qt")
endif()
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
# Set your files and resources here
set( Srcs QtVTKRenderWindowsApp.cxx QtVTKRenderWindows.cxx)
set( Hdrs QtVTKRenderWindows.h)
set( MOC_Hdrs QtVTKRenderWindows.h)
#set( UIs QtVTKRenderWindows.ui )
set( QRCs Icons/icons.qrc )
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 COMPONENTS Widgets REQUIRED QUIET)
#qt5_wrap_ui(UI_Srcs ${UIs})
qt5_add_resources(QRC_Srcs ${QRCs} )
source_group("Resources" FILES
${UIs}
${QRCs}
${EXE_ICON} # Not present
)
source_group("Generated" FILES
${UI_Srcs}
${MOC_Srcs}
${QRC_Srcs}
)
# CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.
add_executable(QtVTKRenderWindows MACOSX_BUNDLE ${Srcs} ${Hdrs} ${UI_Srcs} ${MOC_Hdrs} ${QRC_Srcs})
qt5_use_modules(QtVTKRenderWindows Core Gui Widgets)
target_link_libraries(QtVTKRenderWindows ${VTK_LIBRARIES})
I can't find there is any difference between them. So is there any probability that the code resulting in this error?
You have to link your program to the library vtkGUISupportQt-7.1
In my case, I am in ubuntu 20.04 and that library is located in /usr/lib/x86_64-linux-gnu/libvtkGUISupportQt-7.1.so
you can get it installing the apt package: libvtk7-qt-dev
apt-get install libvtk7-qt-dev

OpenCV library not found - cmake with conan

I have a conanfile describing what I want to include (in this case, mainly the OpenCV part), and a corresponding cmakelists going with it. When running conan install and then cmake, it works, but during compilation the OpenCV libraries could not be included. The same code works on windows, so I wonder if I forgot some setting or so.
The include files appear to be found, but when it comes to linking:
`undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)''
Conanfile.py:
from conans import ConanFile, CMake
from conans import tools
from conans.tools import os_info, SystemPackageTool
import os, sys
import sysconfig
from io import StringIO
class PadConan(ConanFile):
name = "AmbuScan"
version = "0.1.0"
description = "AmbuScan for pad localization"
url = ""
license = "GPL"
short_paths = True
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
ubitrack_version = "1.3.0"
requires = (
"opencv/4.3.0#conan/stable",
"kinect-azure-sensor-sdk/1.4.1#camposs/stable",
"zlib/1.2.11#camposs/stable",
)
# all sources are deployed with the package
exports_sources = "include/*", "src/*", "CMakeLists.txt"
def system_requirements(self):
pass
def configure(self):
self.options['opencv'].contrib = False
self.options['opencv'].cuda = False
def imports(self):
self.copy(src="bin", pattern="*.dll", dst="./bin") # Copies all dll files from packages bin folder to my "bin" folder
self.copy(src="", pattern="**.dll", dst="./bin", keep_path=False) # Copies all dll files from packages bin folder to my "bin" folder
self.copy(src="lib", pattern="*.lib", dst="./lib") # Copies all lib files from packages lib folder to my "lib" folder
self.copy(src="bin", pattern="*", dst="./bin") # Copies all applications
self.copy(src="bin", pattern="*.dll", dst="./bin") # Copies all dll files from packages bin folder to my "bin" folder
self.copy(src="lib", pattern="*.dylib*", dst="./lib") # Copies all dylib files from packages lib folder to my "lib" folder
self.copy(src="lib", pattern="*.so*", dst="./lib") # Copies all so files from packages lib folder to my "lib" folder
self.copy(src="lib", pattern="*.a", dst="./lib") # Copies all static libraries from packages lib folder to my "lib" folder
def _configure_cmake(self):
cmake = CMake(self)
cmake.verbose = True
def add_cmake_option(option, value):
var_name = "{}".format(option).upper()
value_str = "{}".format(value)
var_value = "ON" if value_str == 'True' else "OFF" if value_str == 'False' else value_str
cmake.definitions[var_name] = var_value
for option, value in self.options.items():
add_cmake_option(option, value)
cmake.configure()
return cmake
def build(self):
cmake = self._configure_cmake()
cmake.build()
def package(self):
cmake = self._configure_cmake()
cmake.install()
CMakelists.txt:
cmake_minimum_required(VERSION 3.18)
project(PadLocalizer C CXX)
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo_multi.cmake)
include(${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo_multi.cmake)
conan_set_find_paths()
elseif(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake)
else()
message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
endif()
conan_basic_setup(TARGETS)
include(GNUInstallDirs)
if(UNIX)
if(APPLE)
MESSAGE(STATUS "Building for Macos.")
set(PAD_TARGET_APPLE 1)
endif()
MESSAGE(STATUS "Building for Unix.")
set(PAD_TARGET_UNIX 1)
elseif(WIN32)
MESSAGE(STATUS "Building for Windows.")
set(PAD_TARGET_WINDOWS 1)
endif()
if (MSVC)
# per default disable extended aligned storage for now on msvc
add_definitions(-D_DISABLE_EXTENDED_ALIGNED_STORAGE -DHAVE_SNPRINTF)
endif()
set(PAD_HEADERS
"include/runtime.h"
)
set(PAD_HEADERS_CAPTURE
"include/azure_camera.h"
)
set(PAD_SOURCES
src/main.cpp
)
set(PAD_SOURCES_CAPTURE
src/azure_camera.cpp
)
source_group(pad\\include FILES ${PAD_HEADERS})
source_group(pad\\include\\capture FILES ${PAD_HEADERS_CAPTURE})
source_group(pad\\src FILES ${PAD_SOURCES})
source_group(pad\\src\\capture FILES ${PAD_SOURCES_CAPTURE})
add_executable(pad
${PAD_SOURCES}
${PAD_HEADERS}
${PAD_SOURCES_CAPTURE}
${PAD_HEADERS_CAPTURE}
)
set_target_properties(pad PROPERTIES CXX_STANDARD 17)
set_target_properties(pad PROPERTIES LINKER_LANGUAGE CXX)
set_property(TARGET pad PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(pad PUBLIC
CONAN_PKG::opencv
CONAN_PKG::eigen
CONAN_PKG::kinect-azure-sensor-sdk
)
target_include_directories(pad PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>/include
$<INSTALL_INTERFACE:include>
PRIVATE
${PROJECT_BINARY_DIR}/include
${PROJECT_BINARY_DIR}/src
${PROJECT_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/include
)
# need to review these settings if they are still appropriate
MESSAGE(STATUS "Building for ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
if(WIN32)
set_target_properties(pad PROPERTIES COMPILE_FLAGS "/EHsc /c /W3 /GR /wd4355 /wd4996 /wd4251 /wd4275 /wd4819 /wd4290")
set_target_properties(pad PROPERTIES LINK_FLAGS "/SUBSYSTEM:CONSOLE")
set_target_properties(pad PROPERTIES COMPILE_DEFINITIONS "WIN32" "_MBCS" "BOOST_SPIRIT_USE_OLD_NAMESPACE")
set_target_properties(pad PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib")
## Check for Windows Version ##
if( ${CMAKE_SYSTEM_VERSION} EQUAL 6.1 ) # Windows 7
MESSAGE(STATUS "Setting minimum Windows version to Win7 WINVER=0x0601")
set_target_properties(pad PROPERTIES COMPILE_DEFINITIONS WINVER=0x0601)
elseif( ${CMAKE_SYSTEM_VERSION} EQUAL 6.2 ) # Windows 8
MESSAGE(STATUS "Setting minimum Windows version to Win8 WINVER=0x0602")
set_target_properties(pad PROPERTIES COMPILE_DEFINITIONS WINVER=0x0602)
elseif( ${CMAKE_SYSTEM_VERSION} EQUAL 6.3 ) # Windows 8.1
MESSAGE(STATUS "Setting minimum Windows version to Win8.1 WINVER=0x0603")
set_target_properties(pad PROPERTIES COMPILE_DEFINITIONS WINVER=0x0603)
elseif( ${CMAKE_SYSTEM_VERSION} EQUAL 10.0 ) # Windows 10
MESSAGE(STATUS "Setting minimum Windows version to Win8.1 WINVER=0x0603")
set_target_properties(pad PROPERTIES COMPILE_DEFINITIONS WINVER=0x0603)
else() # Some other Windows
MESSAGE(STATUS "Setting minimum Windows version to Vista WINVER=0x0600")
set_target_properties(pad PROPERTIES COMPILE_DEFINITIONS WINVER=0x0600)
endif()
endif(WIN32)
install(TARGETS pad EXPORT padConfig
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) # This is for Windows
# This makes the project importable from the install directory
# Put config file in per-project dir (name MUST match), can also
# just go into 'cmake'.
install(EXPORT padConfig DESTINATION share/pad/cmake)
# This makes the project importable from the build directory
export(TARGETS pad FILE padConfig.cmake)
Which OS and compiler do you use? What are your conan settings? Type:
conan profile show default
If "default" is your default profile of course.
If you use compiler gcc > 5, please make sure you use the c++11 ABI:
conan profile update settings.compiler.libcxx=libstdc++11 default
See output of pkg-config opencv --libs to find out what libraries you're missing.
Then add them to your config.

Unable to find headers in a project

I have difficulties with CMakeLists file. I have done pretty much the same in my other project, so i know the paths are correct. But i tried to make it a bit more pretty so I created a new CMakeLists file.
Now my project fails to find the headers.
Anyone see what I have missed?
Here is my CMakeLists file:
project("Test Cell Camera")
set(VERSION_MAJOR 0)
set(VERSION_MINOR 1)
set(VERSION_PATCH 0)
set(CMAKE_CXX_STANDARD 17)
set(lib_TARGET tcc)
set(exec_TARGET tcc_exe)
set(test_TARGET tcc_test)
set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests")
set(LIBS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libs")
set(CONFIG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/config")
set(main_SRC_FILE "${SRC_DIR}/main.cpp")
include_directories(
${SRC_DIR}
${INCLUDE_DIR}
"C:/Program Files/Basler/pylon 5/Development/include" # Basler
)
file(GLOB lib_INCLUDE "${INCLUDE_DIR}/*/*.h")
file(GLOB lib_SRC "${SRC_DIR}/*.cpp")
list(FILTER lib_SRC EXCLUDE REGEX ${main_SRC_FILE})
file(GLOB main_SRC ${main_SRC_FILE})
# Add all test sources
file(GLOB test_SRC "${TESTS_DIR}/*.cpp")
# Documentation doxifile path
set(lib_DOC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/doc/")
link_directories("C:/Program Files/Basler/pylon 5/Development/lib/x64")
set(OpenCV_DIR "C:/OpenCV/3.4.7")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
set(lib_dep_LIBS PylonC.lib ${OpenCV_LIBS})
add_library(${lib_TARGET} ${lib_SRC})
target_link_libraries(${lib_TARGET} ${lib_dep_LIBS})```

How to link to the code that defines the sdl_image.h functions?

I'm trying to add sound and music to my openGL project. I'm using Cmake. I get undefined reference errors and have tried for days using many methods and suggestions I've read about, but I am over my head apparently.
I have installed the libraries that I think are needed, I have configured and make installed, tried, finding the packages, added module code to help facilitate it. I am somewhat aware not all of these methods are likely useful in my case. Or maybe I need to have these libraries in my project folder and on my system ...installed. Ok, not super clear about that. I am using Ubuntu Linux with codeblocks to edit my scripts, but not to compile.
My cmakelists.text
cmake_minimum_required (VERSION 3.0)
project (maficengine LANGUAGES C CXX ASM)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/external/")
find_package(OpenGL REQUIRED)
#FIND_PACKAGE(SDL2_MIXER)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS})
#target_link_libraries(maficengine ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES})
find_file(SDL2_INCLUDE_DIR NAME SDL.h HINTS SDL2)
find_library(SDL2_LIBRARY NAME SDL2)
set(SDL2_INCLUDE_DIR /usr/include/SDL2)
set(SDL2_LIBRARY /usr/lib/x86_64-linux-gnu/libSDL2.so)
#file(GLOB_RECURSE SOURCE_FILES/usr/lib/x86_64-linux-gnu
# ${CMAKE_SOURCE_DIR}/src/*.c
# ${CMAKE_SOURCE_DIR}/src/*.cpp)
INCLUDE(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL REQUIRED sdl)
set(SDL_INCLUDE_DIR "/usr/include/SDL2")
set(SDL_LIBRARY "SDL2")
include(FindSDL)
if(SDL_FOUND)
message(STATUS "SDL FOUND")
elseif(!SDL_FOUND)
message(STATUS "SDL not FOUND")
endif()
find_library(SDL_MIXER_LIBRARY
NAMES SDL2_mixer
HINTS
ENV SDLMIXERDIR
ENV SDLDIR
PATH_SUFFIXES lib
)
if( CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR )
message( FATAL_ERROR "Please select another Build Directory ! (and give it a clever name, like bin_Visual2012_64bits/)" )
endif()
if( CMAKE_SOURCE_DIR MATCHES " " )
message( "Your Source Directory contains spaces. If you experience problems when compiling, this can be the cause." )
endif()
if( CMAKE_BINARY_DIR MATCHES " " )
message( "Your Build Directory contains spaces. If you experience problems when compiling, this can be the cause." )
endif()
file(GLOB SOURCES "external/myCustomHeaders/*.cpp")
add_library(loaders SHARED ${SOURCES}
${SDL2_INCLUDE_DIR}
external/SDL2_image-2.0.4/SDL_image.h
external/myCustomHeaders/include/loadTexture.h
external/myCustomHeaders/loadTexture.cpp
/usr/include/SDL2/SDL.h
/usr/include/SDL/SDL_image.h
external/SDL2_mixer-2.0.4/SDL_mixer.h
)
include_directories( external/myCustomHeaders/include )
include_directories( external/SDL2_mixer-2.0.4/acinclude )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}external/SDL2_mixer-2.0.4 )
include_directories(/usr/include/SDL2)
include_directories(/usr/include/SDL)
include_directories(${SDL2_INCLUDE_DIRS})
include(FindPackageHandleStandardArgs)
find_path(
SDL_MIXER_INCLUDE_DIR
PATHS
/usr/include/SDL
/usr/include/SDL2
/usr/include
/usr/local/include
/sw/include
/opt/local/include
${SDL_MIXER_ROOT_DIR}/include
DOC "The directory where SDL_mixer.h resides")
link_directories(external/myCustomHeaders/include)
link_directories(external/myCustomHeaders)
link_directories(external/SDL2_mixer-2.0.4)
link_directories(/usr/include/SDL2)
link_directories(/usr/include/SDL)
# Compile external dependencies
add_subdirectory (external)
# On Visual 2005 and above, this module can set the debug working directory
cmake_policy(SET CMP0026 OLD)
cmake_policy(SET CMP0079 NEW)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/external/rpavlik-cmake-modules-fe2273")
include(CreateLaunchers)
include(MSVCMultipleProcessCompile) # /MP
if(INCLUDE_DISTRIB)
add_subdirectory(distrib)
endif(INCLUDE_DISTRIB)
include_directories(
external/AntTweakBar-1.16/include/
external/glfw-3.1.2/include/
external/glm-0.9.7.1/
external/glew-1.13.0/include/
external/assimp-3.0.1270/include/
external/bullet-2.81-rev2613/src/
external/myCustomHeaders/include
common/
)
set(ALL_LIBS
${OPENGL_LIBRARY}
glfw
GLEW_1130
loaders
)
add_definitions(
-DTW_STATIC
-DTW_NO_LIB_PRAGMA
-DTW_NO_DIRECT3D
-DGLEW_STATIC
-D_CRT_SECURE_NO_WARNINGS
)
# Tutorial 17
add_executable(mageengine
${SDL2_LIBRARY}
Mafic/mafic.cpp
common/shader.cpp
common/shader.hpp
common/controls.cpp
common/controls.hpp
common/texture.cpp
common/texture.hpp
common/objloader.cpp
common/objloader.hpp
common/vboindexer.cpp
common/vboindexer.hpp
common/quaternion_utils.cpp
common/quaternion_utils.hpp
Mafic/StandardShading.vertexshader
Mafic/StandardShading.fragmentshader
)
set_target_properties(loaders
PROPERTIES LINKER_LANGUAGE CXX)
#target_sources(loaders
# PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/myCustomHeaders/loadTexture.h
# )
target_link_libraries(mageengine
${ALL_LIBS}
ANTTWEAKBAR_116_OGLCORE_GLFW
${SDL2_LIBRARIES}
loaders
)
#target_link_libraries(${maficengine } SDL2::Main SDL2::Image)
# Xcode and Visual working directories
set_target_properties(mageengine PROPERTIES XCODE_ATTRIBUTE_CONFIGURATION_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Mafic/")
create_target_launcher(mageengine WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Mafic/")
SOURCE_GROUP(common REGULAR_EXPRESSION ".*/common/.*" )
SOURCE_GROUP(shaders REGULAR_EXPRESSION ".*/.*shader$" )
if (NOT ${CMAKE_GENERATOR} MATCHES "Xcode" )
add_custom_command(
TARGET mageengine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/mageengine${CMAKE_EXECUTABLE_SUFFIX}" "${CMAKE_CURRENT_SOURCE_DIR}/Mafic/"
)
#target_link_libraries(mageengine LINK_PUBLIC ${mylibrary}
# )
elseif (${CMAKE_GENERATOR} MATCHES "Xcode" )
endif (NOT ${CMAKE_GENERATOR} MATCHES "Xcode" )
this is my module code that I'm using, I assume its possibly being used by cmake
# Locate SDL_image library
#
# This module defines:
#
# ::
#
# SDL2_IMAGE_LIBRARIES, the name of the library to link against
# SDL2_IMAGE_INCLUDE_DIRS, where to find the headers
# SDL2_IMAGE_FOUND, if false, do not try to link against
# SDL2_IMAGE_VERSION_STRING - human-readable string containing the version of SDL_image
#
#
#
# For backward compatibility the following variables are also set:
#
# ::
#
# SDLIMAGE_LIBRARY (same value as SDL2_IMAGE_LIBRARIES)
# SDLIMAGE_INCLUDE_DIR (same value as SDL2_IMAGE_INCLUDE_DIRS)
# SDLIMAGE_FOUND (same value as SDL2_IMAGE_FOUND)
#
#
#
# $SDLDIR is an environment variable that would correspond to the
# ./configure --prefix=$SDLDIR used in building SDL.
#
# Created by Eric Wing. This was influenced by the FindSDL.cmake
# module, but with modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
#=============================================================================
# Copyright 2005-2009 Kitware, Inc.
# Copyright 2012 Benjamin Eikel
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h
HINTS
ENV SDL2IMAGEDIR
ENV SDL2DIR
PATH_SUFFIXES SDL2
# path suffixes to search inside ENV{SDLDIR}
include/SDL2 include
PATHS ${SDL2_IMAGE_PATH}
)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(VC_LIB_PATH_SUFFIX lib/x64)
else()
set(VC_LIB_PATH_SUFFIX lib/x86)
endif()
find_library(SDL2_IMAGE_LIBRARY
NAMES SDL2_image
HINTS
ENV SDL2IMAGEDIR
ENV SDL2DIR
PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
PATHS ${SDL2_IMAGE_PATH}
)
if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h")
file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}")
set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH})
unset(SDL2_IMAGE_VERSION_MAJOR_LINE)
unset(SDL2_IMAGE_VERSION_MINOR_LINE)
unset(SDL2_IMAGE_VERSION_PATCH_LINE)
unset(SDL2_IMAGE_VERSION_MAJOR)
unset(SDL2_IMAGE_VERSION_MINOR)
unset(SDL2_IMAGE_VERSION_PATCH)
endif()
set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY})
set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image
REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS
VERSION_VAR SDL2_IMAGE_VERSION_STRING)
# for backward compatibility
set(SDLIMAGE_LIBRARY ${SDL2_IMAGE_LIBRARIES})
set(SDLIMAGE_INCLUDE_DIR ${SDL2_IMAGE_INCLUDE_DIRS})
set(SDLIMAGE_FOUND ${SDL2_IMAGE_FOUND})
mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR)
My Cmake error output, I am a beginner with cmake btw, so laugh all you will.
CMakeFiles/mageengine.dir/Mafic/mafic.cpp.o: In function `load_image(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
mafic.cpp:(.text+0x2c): undefined reference to `IMG_Load'
mafic.cpp:(.text+0x43): undefined reference to `SDL_DisplayFormat'
CMakeFiles/mageengine.dir/Mafic/mafic.cpp.o: In function `init()':
mafic.cpp:(.text+0x133): undefined reference to `SDL_SetVideoMode'
mafic.cpp:(.text+0x152): undefined reference to `TTF_Init'
mafic.cpp:(.text+0x17c): undefined reference to `Mix_OpenAudio'
mafic.cpp:(.text+0x19e): undefined reference to `SDL_WM_SetCaption'
CMakeFiles/mageengine.dir/Mafic/mafic.cpp.o: In function `load_files()':
mafic.cpp:(.text+0x21c): undefined reference to `TTF_OpenFont'
mafic.cpp:(.text+0x25b): undefined reference to `Mix_LoadMUS'
mafic.cpp:(.text+0x298): undefined reference to `Mix_LoadWAV_RW'
mafic.cpp:(.text+0x2bf): undefined reference to `Mix_LoadWAV_RW'
mafic.cpp:(.text+0x2e6): undefined reference to `Mix_LoadWAV_RW'
mafic.cpp:(.text+0x30d): undefined reference to `Mix_LoadWAV_RW'
CMakeFiles/mageengine.dir/Mafic/mafic.cpp.o: In function `clean_up()':
mafic.cpp:(.text+0x3ba): undefined reference to `Mix_FreeChunk'
mafic.cpp:(.text+0x3c9): undefined reference to `Mix_FreeChunk'
mafic.cpp:(.text+0x3d8): undefined reference to `Mix_FreeChunk'
mafic.cpp:(.text+0x3e7): undefined reference to `Mix_FreeChunk'
mafic.cpp:(.text+0x3f6): undefined reference to `Mix_FreeMusic'
mafic.cpp:(.text+0x405): undefined reference to `TTF_CloseFont'
mafic.cpp:(.text+0x40a): undefined reference to `Mix_CloseAudio'
mafic.cpp:(.text+0x40f): undefined reference to `TTF_Quit'
collect2: error: ld returned 1 exit status
CMakeFiles/mageengine.dir/build.make:197: recipe for target 'mageengine' failed
make[2]: *** [mageengine] Error 1
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/mageengine.dir/all' failed
make[1]: *** [CMakeFiles/mageengine.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
Ok, I seem to have worked out the kinks. A magnitude harder than I led myself and others to believe.. - Probably did it the wrong way, but doesn't seem like many are going about it the way I am. I just went through and linked the libraries in my cmake file by doing this target_link_libraries(loaders -lSDLmain) target_link_libraries(loaders -lSDL) target_link_libraries(loaders -lSDL2_ttf) target_link_libraries(loaders -lSDL2_mixer) and downloading and istalling libs as needed. All this being said, i still have many problems, but i think it's a step closer.

How do I install minizip with zlib?

I have the following cmake file to download, build and install zlib:
cmake_minimum_required ( VERSION 2.8.7 )
include (ExternalProject)
if(UNIX)
# An external project for zlib
SET (GIT_URL https://github.com/madler/zlib.git)
SET (ZLIB_INSTALL ${CMAKE_CURRENT_BINARY_DIR})
SET (ZLIB_INCLUDE ${CMAKE_BINARY_DIR}/include/zlib)
SET (ZLIB_STATIC ${CMAKE_BINARY_DIR}/lib/libz.a )
ExternalProject_Add(zlib
PREFIX zlib
GIT_REPOSITORY ${GIT_URL}
INSTALL_DIR ${ZLIB_INSTALL}
PATCH_COMMAND ${CMAKE_COMMAND} -E remove <SOURCE_DIR>/zconf.h
BUILD_IN_SOURCE 1
PATCH_COMMAND ""
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --includedir=${ZLIB_INCLUDE}
)
SET (ZLIB_INCLUDE_DIR ${ZLIB_INSTALL}/include/zlib)
SET (ZLIB_LIBRARY "${ZLIB_INSTALL}")
ADD_LIBRARY (ZLIB_LIB STATIC IMPORTED DEPENDS zlib)
SET_TARGET_PROPERTIES (ZLIB_LIB PROPERTIES IMPORTED_LOCATION "${ZLIB_STATIC}")
endif(UNIX)
But this cmake file only install zlib. I want also install minizip. Minizip is "part of zlib". In the zlib repository has a directory that has minizip.
How can I also install minizip in the same cmake file? Is it possible?
The minizip is inside zlib repository:
- zlib
- contrib
- minizip
- ....
- ...
- ...
I have cmake file to install minizip:
cmake_minimum_required(VERSION 2.8)
project(minizip)
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(BUILD_SHARED_LIBS OFF)
find_package (ZLIB REQUIRED)
if (ZLIB_FOUND)
set(ZLIB_LIBRARY ${CMAKE_BINARY_DIR}/ZLIB/src/ZLIB/contrib)
SET (minizip ${CMAKE_BINARY_DIR}/lib/minizip)
if(CMAKE_HOST_APPLE)
set(PLATFORM __APPLE__)
elseif(CMAKE_HOST_UNIX)
set(PLATFORM unix)
elseif(CMAKE_HOST_WIN32)
set(PLATFORM _WIN32)
else(CMAKE_HOST_APPLE)
message(FATAL_ERROR "Not supported Platform")
endif(CMAKE_HOST_APPLE)
add_definitions(-D${PLATFORM})
set(SOURCE
${ZLIB_LIBRARY}/minizip/ioapi.c
${ZLIB_LIBRARY}/minizip/miniunz.c
${ZLIB_LIBRARY}/minizip/minizip.c
${ZLIB_LIBRARY}/minizip/unzip.c
${ZLIB_LIBRARY}/minizip/zip.c
)
if(WIN32)
set(SOURCE ${SOURCE} ${ZLIB_LIBRARY}/minizip/iowin32.c)
endif(WIN32)
set(HEADERS
${ZLIB_LIBRARY}/minizip/crypt.h
${ZLIB_LIBRARY}/minizip/ioapi.h
${ZLIB_LIBRARY}/minizip/miniunz.h
${ZLIB_LIBRARY}/minizip/unzip.h
)
if(WIN32)
set(HEADERS ${HEADERS} ${ZLIB_LIBRARY}/minizip/iowin32.h)
endif(WIN32)
add_library(minizip ${SOURCE} ${HEADERS})
target_link_libraries(minizip PUBLIC "-static" ZLIB_STATIC)
add_dependencies ( minizip zlib)
install(
TARGETS minizip EXPORT minizip-exports
INCLUDES DESTINATION "include"
RUNTIME DESTINATION "bin"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
)
install(
FILES ${HEADERS}
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/include/minizip"
)
ADD_LIBRARY (MINIZIP_LIB STATIC IMPORTED DEPENDS minizip)
SET_TARGET_PROPERTIES (MINIZIP_LIB PROPERTIES IMPORTED_LOCATION ${minizip})
endif()
I want before install minizip, install zlib.
But when I run
cmake ..
I have the following error:
Make Error at modules/minizip.cmake:50 (add_library):
Cannot find source file:
/home/lais/Imagens/agent/build/ZLIB/src/ZLIB/contrib/minizip/ioapi.c
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
Call Stack (most recent call first):
CMakeLists.txt:59 (include)
CMake Error: Cannot determine link language for target "minizip".
CMake Error: CMake can not determine linker language for target: minizip
And I have a top level cmake, that call for this two modules:
cmake_minimum_required( VERSION 2.8.7 )
project( project )
# version number
set ( VERSION_MAJOR 0 )
set ( VERSION_MINOR 0 )
# cpr requires c++11
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
# src : main + jsoncpp library
file ( GLOB SOURCES src/project/*.cpp )
# src : collect functions - depend on OS
if ( WIN32 )
file ( GLOB SOURCES ${SOURCES} src/project/windows/*.cpp )
else () # if( UNIX )
file ( GLOB SOURCES ${SOURCES} src/project/linux/*.cpp )
endif ()
# src : curl requests
# options for cpr
# avoid experimental use of openssl
option( CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" OFF )
# avoid building tests
option( BUILD_CPR_TESTS "Set to ON to build cpr tests." OFF )
# options for curl
# avoid building tests
option( BUILD_CURL_TESTS "Set to ON to build cURL tests." OFF )
# avoid running tests - set ON again in download version or if errors occur
option( RUN_CURL_TESTS "Set to ON to run cURL tests." OFF )
add_subdirectory ( lib/cpr )
include_directories ( ${CPR_INCLUDE_DIRS} )
include_directories ( ${CURL_INCLUDE_DIRS} )
# src : DtWinVer - Windows Version/Edition class
if ( WIN32 )
add_subdirectory ( lib/dtwinver )
endif ()
# headers
include_directories ( "include" )
include_directories ( "${CMAKE_BINARY_DIR}/include" )
# scr = libboost
include ( "modules/boost.cmake" )
# src = zlib
include ( "modules/zlib.cmake" )
# src = minizip
include ( "modules/minizip.cmake" )
# compile
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" )
add_executable ( project-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} )
target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR} ${CPR_LIBRARIES} ${CURL_LIBRARIES} ${FILESYSTEM_LIB} ${SYSTEM_LIB} ${REGEX_LIB} ${PROGRAM_OPTIONS_LIB} ${ZLIB_STATIC} ${minizip})
add_dependencies ( project-v${VERSION_MAJOR}.${VERSION_MINOR} Boost)
add_dependencies ( project-v${VERSION_MAJOR}.${VERSION_MINOR} zlib)
add_dependencies ( project-v${VERSION_MAJOR}.${VERSION_MINOR} minizip)
if ( WIN32 )
target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR} dtwinver )
else ()
# libudev
target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR} udev )
endif ()
Looks your source package is not complete.
minizip is just simple a single file minizip.c. Why do you need cmake? Just compile it and link with zlib and everything will be fine.