Adding Arpack/Armadillo in Cmakelist - c++

I'm struggling with adding the ARPACK in myCMakeLists (see below) file of which i construct my Qt-project under Mac-OSX.
Note that i installed the Armadillo library via 'Macport' and it's recognized automatically by Qt without adding it in the CMakeList file. But since i'm using the Sparse-Decomposition function of Armadillo, Qt asks me to link the ARPACK library to the project. I installed the ARPACK library but i didn't find how to add in my CMakeList file. How could i add it please ?

I fixed this problems by adding thses lines to my CMakeList:
SET(ARMADILLO_INCLUDE_DIR "/Users/Anass/Downloads/armadillo-
6.600.4/include/")
SET(ARMADILLO_LIBRARIES "/Users/Anass/Downloads/armadillo-
6.600.4/libarmadillo.6.60.4.dylib")
SET(ARPACK_LIBRARIES "/opt/local/lib/libarpack.dylib")
...
IF(LAPACK_FOUND)
SET(LINK_LIBRARIES
${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}
${ARMADILLO_LIBRARIES} ${ARPACK_LIBRARIES})
ELSE()
SET(LINK_LIBRARIES ${ARMADILLO_LIBRARIES} ${ARPACK_LIBRARIES})
ENDIF()
MESSAGE("")
MESSAGE("STEP 3 : GENERATE COMPILATION PROCESS")
MESSAGE("")
include_directories(
${ARMADILLO_INCLUDE_DIR}
)
if(CMAKE_COMPILER_IS_GNUCXX)
message("adding c++11 support")
list(APPEND CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
endif(CMAKE_COMPILER_IS_GNUCXX)
########################################################
SET(EXECUTABLE_OUTPUT_PATH ./bin)
MESSAGE("Add test cmake")
SET(test_cmake_SRCS
${CMAKE_SOURCE_DIR}/src/test_cmake.cpp
)
add_executable(test_cmake ${test_cmake_SRCS})
target_link_libraries(test_cmake ${LINK_LIBRARIES})

Related

Symbol not found error for matplotlibcpp, building with CMake

I am trying to use CMake for including Matplotlibcpp in my C++ project (I am new to both CMake and C++). I am following https://github.com/lava/matplotlib-cpp/issues/236#issuecomment-716510547 for setting up a CMake file. The project builds fine, but when I try to run the executable, here is the error I get:
dyld[73245]: symbol not found in flat namespace
'_PyCapsule_GetPointer'
zsh: abort ./data_measure_img_seq
I'm not sure how to resolve this. Any suggestions? For reference, I am putting my CMakeLists file below:
# set the minimum version
cmake_minimum_required(VERSION "3.13")
# set project
project(image-data-cv)
set(OpenCV_DIR /Users/anshgodha/Developer/opencv/install/lib/cmake/opencv4)
set(CMAKE_CXX_STANDARD 14)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
# for matplotlibcpp
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
find_package(PythonLibs 3.0 REQUIRED)
include_directories(${PYTHON3_INCLUDE_DIRS} ${NumPy_INCLUDE_DIRS})
include(FetchContent)
FetchContent_Declare(
matplotlib
GIT_REPOSITORY https://github.com/lava/matplotlib-cpp.git
GIT_TAG f23347fca25219d1c42cbb91608b5556814bf572
)
FetchContent_GetProperties(matplotlib)
if(NOT matplotlib_POPULATED)
FetchContent_Populate(matplotlib)
endif()
include_directories(SYSTEM ${matplotlib_SOURCE_DIR})
set(PROJECTS basic_data_measures;data_measure_img_seq)
foreach(PROJECT ${PROJECTS})
add_executable(${PROJECT} ${PROJECT}/main.cpp)
target_link_libraries(${PROJECT} PUBLIC ${OpenCV_LIBS})
set_target_properties(${PROJECT} PROPERTIES OUTPUT_NAME "${PROJECT}")
endforeach(PROJECT ${PROJECTS})
# link python and numpy
target_link_libraries(data_measure_img_seq
PRIVATE
${PYTHON_LIBRARIES}
Python3::NumPy
)
I was having the same issue compiling using cmake. Perhaps the included cmake doesn't link everything properly. I got around it using e.g.
g++ fill.cpp -o fill -std=c++11 -I/usr/include/python2.7 -lpython2.7

Use CGAL and PCL in same project

I am trying to use CGAL and PCL in the same project. Both PCL and CGAL should be installed correctly on my computer, since the examples work.
I created a CMakeList.txt file which references both PCL and CGAL I am able to configure it without the CMake GUI showing any problems, but when I open the project .sln the CGAL includes have errors
for example: Cannot open include file: 'CGAL/Simple_cartesian.h': No such file or directory
All the PCL includes work fine.
If I delete all the PCL references from the CMakeList.txt then the CGAL includes work. I am suspecting that I am doing something wrong in my CMakeList.txt.
Does anyone know what I am doing wrong?
Thank you!
Below is my CMakeList.txt
cmake_minimum_required(VERSION 3.1...3.15)
project(PC_Svr2)
find_package(CGAL QUIET)
if ( CGAL_FOUND )
# create a target per cppfile
file(GLOB cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
foreach(cppfile ${cppfiles})
create_single_source_cgal_program( "${cppfile}" )
endforeach()
else()
message(STATUS "This program requires the CGAL library, and will not be compiled.")
endif()
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (PC_Svr2 cloud_viewer.cpp)
target_link_libraries (PC_Svr2 ${PCL_LIBRARIES})
message("PCL_IO_LIBRARIES - ${PCL_IO_LIBRARIES}")
file(GLOB cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
foreach(cppfile ${cppfiles})
create_single_source_cgal_program( "${cppfile}" )
endforeach()
That is creating a single target from each of the cpp files in CMAKE_CURRENT_SOURCE_DIR. I don't think that is what you want.
If I understand things correctly, your code is in cloud_viewer.cpp, then you should remove the loop and just link with cgal with your target_link_libraries:
target_link_libraries(PCS_Svr2 CGAL::CGAL ${PCL_LIBRARIES})
You can have a look at that page for details.

Creation of a cmake module for using a library

I am new to C++ and have just started to use Cmake for linking the libraries to my project. I need to use a library:
https://github.com/Gnimuc/FastPD
Fortunately, I managed to build the library using Cmake (in my build there is no *.lib file at all), but I don't know how to link it to my project. I mean that I don't know how to add it to my cmakelists.txt :
(PS. I'm also using two other libraries ITK and VTK; but I can't link the above mentioned library to my project or main.cpp.)
################################################
cmake_minimum_required(VERSION 2.8)
project(My_project)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
else()
find_package(ItkVtkGlue REQUIRED)
include(${ItkVtkGlue_USE_FILE})
set(Glue ItkVtkGlue)
endif()
add_executable(My_project MACOSX_BUNDLE main.cpp)
target_link_libraries(My_project
${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES})
################################################
Thanks in advance for your helps,
Assuming you installed the library and its header files, you can then search for the header files using find_path, and add the found path to the include directories. Then you can search for the library by using find_library, and add the library with the target_link_libraries command.
I tried both shared and static types for creation of the library. In the case of shared, no *.lib file was created, and in the case of static, my project couldn't link to the library. Therefore, in my project's CmakeLists.txt, I decided to add all the *.cpp and headers as libraries and then link them together (as I didn't know the dependency among them!!!), and finally, I linked them to my project. Perhaps it does not make sense but it works; hope it helps you:
CmakeLists.txt
##############################################
cmake_minimum_required(VERSION 2.6)
set(PROJ_NAME PROJECT46)
PROJECT(${PROJ_NAME})
# Prevent compilation in-source
if( ${CMAKE_BINARY_DIR} STREQUAL ${PROJECT_SOURCE_DIR} )
Message( " " )
Message( FATAL_ERROR "Source and build directories are the same.
Create an empty build directory,
change into it and re-invoke cmake")
endif()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.
Please use a different C++ compiler.")
endif()
##############################################
## External libraries
##############################################
list( APPEND CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake
)
# Blitz
find_package( Blitz++ REQUIRED )
list( APPEND PROJ_INCLUDE_DIRS
${Blitz++_INCLUDE_DIR}
)
list( APPEND
PROJ_LIB
${Blitz++_LIBRARIES}
)
# ITK and VTK
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
else()
find_package(ItkVtkGlue REQUIRED)
include(${ItkVtkGlue_USE_FILE})
set(Glue ItkVtkGlue)
endif()
##############################################
# FASTPD
add_library(FASTPD Fast_PD.cpp Fast_PD.h common.h block.h)
add_library(GRAPH graph.h graph.cpp)
add_library(linked LinkedBlockList.h LinkedBlockList.cpp)
add_library(MAXFLOW maxflow.cpp)
include_directories(${PROJ_INCLUDE_DIRS})
add_executable(${PROJ_NAME} main.cpp)
target_link_libraries(linked MAXFLOW)
target_link_libraries(GRAPH linked)
target_link_libraries(FASTPD GRAPH)
target_link_libraries(${PROJ_NAME} FASTPD)
target_link_libraries(${PROJ_NAME}
${PROJ_LIB} ${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES}
)

OpenCV 3.2 file compilation?

How to compile c++ file (opencv included) using opencv 3.2, mingw and command window in Windows 10. (I do not want to use any softwares like codeblocks/Vbasic/eclipse/netbeans).
Try using cmake for generating the makefile and then use the same for make and build.
Following is a minimalisitic example of cmake wherein I was using opencv for clustering of pixels.
You need to create a CMakeLists.txt file and add the following things. for more information on building you can check my github repo:
https://github.com/anubhavrohatgi/ImageProcessing.git
#Cmake for Clustering Project
PROJECT(clustering)
#Minimum version of Cmake required
cmake_minimum_required(VERSION 3.1)
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Release)
ENDIF(NOT CMAKE_BUILD_TYPE)
#Find and add opencv libraries
find_package(OpenCV REQUIRED core imgproc highgui imgcodecs)
IF(${OpenCV_VERSION} VERSION_LESS 2.4.12)
MESSAGE(FATAL_ERROR "OpenCV version is not compatible : ${OpenCV_VERSION}")
ENDIF()
#Check for C++ Compiler version. I am using C++14.
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
IF(COMPILER_SUPPORTS_CXX14)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
ELSEIF(COMPILER_SUPPORTS_CXX0X)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
ELSE()
MESSAGE(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.")
ENDIF()
#include the header files located in the include folder
INCLUDE_DIRECTORIES(include)
#Set the variables for Headers and Sources. Manually add the filenames. This
#is useful if the files are changed, removed or name modified.
#Better than GLOB version
SET( HEADERS
include/clustering.h
)
set( SOURCES
src/main.cpp
)
add_executable(clustering ${SOURCES} ${HEADERS})
target_link_libraries(clustering
${OpenCV_LIBS}
)

Want to make standalone program with cmake

My program uses giblib and Imlib2 library and it is built with cmake.
It works perfectly in my computer but not in other's.
I guess the reason is I installed every library what my program needs but other's doesn't.
My goal is making standalone program. (don't need to install any other library addtionally)
What should I add in cmake file?
projectDef.cmake source code
file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
X11/[^.]*.cpp
X11/[^.]*.h
X11/[^.]*.cmake
)
SOURCE_GROUP(X11 FILES ${PLATFORM})
add_definitions(
)
set (SOURCES
${SOURCES}
${PLATFORM}
)
add_x11_plugin(${PROJECT_NAME} SOURCES)
target_link_libraries(${PROJECT_NAME}
${PLUGIN_INTERNAL_DEPS}
)
include_directories(/usr/include/giblib)
include_directories(/usr/include/X11)
target_link_libraries(MyProject X11)
target_link_libraries(MyProject Imlib2)
target_link_libraries(MyProject giblib)
CMakeList.txt source code
cmake_minimum_required (VERSION 2.6)
set (CMAKE_BACKWARDS_COMPATIBILITY 2.6)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_EXE_LINKER_FLAGS "-static")
Project(${PLUGIN_NAME})
file (GLOB GENERAL RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
[^.]*.cpp
[^.]*.h
[^.]*.cmake
)
include_directories(${PLUGIN_INCLUDE_DIRS})
SET_SOURCE_FILES_PROPERTIES(
${GENERATED}
PROPERTIES
GENERATED 1
)
SOURCE_GROUP(Generated FILES
${GENERATED}
)
SET( SOURCES
${GENERAL}
${GENERATED}
)
include_platform()
Try starting with this options in your root CMakeLists.txt:
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
BUILD_SHARED_LIBS is only needed if your project has its own libraries (add_library).
With the -static linker flag, you need static libs for ALL your additional libraries too! One common problem when static linking is to avoid circular dependencies.