How to add OpenXLSX to my project in c++? - c++

I have a project and I want to use OpenXLSX as excel library. However, I can't add this to my project.
I move all OpenXLSX files into my project folder, it didn't work. Also moved them to my Desktop, it didn't work either.
Here is my CMakeList.txt file:
#cmake_minimum_required(VERSION 3.5)
#project(PCL_Visualizer LANGUAGES CXX)
#set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
#add_executable(PCL_Visualizer main.cpp)
cmake_minimum_required(VERSION 3.5)
project(mainwindow)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# init_qt: Let's do the CMake job for us
set(CMAKE_AUTOMOC ON) # For meta object compiler
set(CMAKE_AUTORCC ON) # Resource files
set(CMAKE_AUTOUIC ON) # UI files
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/home/fatih/Desktop")
# Find the QtWidgets library
find_package(Qt5 REQUIRED Widgets)
find_package(VTK REQUIRED)
find_package(PCL 1.7.1 REQUIRED)
find_package(OpenXLSX REQUIRED)
# Fix a compilation bug under ubuntu 16.04 (Xenial)
#list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
include_directories(${PCL_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/OpenXLSX-master)
#include_directories(OpenXLSX-master/library/headers)
#include_directories(OpenXLSX-master/library/external/pugixml)
#include_directories(OpenXLSX-master/library/external/nowide/nowide)
#include_directories(OpenXLSX-master/library/external/zippy)
add_definitions(${PCL_DEFINITIONS})
set(project_SOURCES main.cpp mainwindow.cpp)
add_executable(${PROJECT_NAME} ${project_SOURCES} icons.qrc)
target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES} Qt5::Widgets)
Everytime I try to cmake .. and make, i get this error.
Could not find a package configuration file provided by "OpenXLSX" with any
of the following names:
OpenXLSXConfig.cmake
openxlsx-config.cmake
Add the installation prefix of "OpenXLSX" to CMAKE_PREFIX_PATH or set
"OpenXLSX_DIR" to a directory containing one of the above files. If
"OpenXLSX" provides a separate development package or SDK, be sure it has
been installed.

I just add these commands to my CMakeList.txt and problem solved partially.
include_directories(/home/fatih/Desktop/OpenXLSX-master/library)
include_directories(/home/fatih/Desktop/OpenXLSX-master/build/library)
include_directories(/home/fatih/Desktop/OpenXLSX-master/library/headers)
link_directories(/home/fatih/Desktop/OpenXLSX-master/build/library)
link_directories(/home/fatih/Desktop/OpenXLSX-master/build/library/headers)
link_directories(/home/fatih/Desktop/OpenXLSX-master/library/headers)
target_link_libraries(${PROJECT_NAME} OpenXLSX VERSION 0.2.0 LANGUAGES CXX)
However, now I get different type of error.
/usr/bin/ld: cannot find -lOpenXLSX
/usr/bin/ld: cannot find -lVERSION
/usr/bin/ld: cannot find -l0.2.0
/usr/bin/ld: cannot find -lLANGUAGES
/usr/bin/ld: cannot find -lCXX
/usr/bin/ld: cannot find -lOpenXLSX
/usr/bin/ld: cannot find -lVERSION
/usr/bin/ld: cannot find -l0.2.0
/usr/bin/ld: cannot find -lLANGUAGES
/usr/bin/ld: cannot find -lCXX
Edit: I solved that problem too. If someone gets an error like this, I changed the target_link_library comment to this:
target_link_libraries(${PROJECT_NAME} /home/fatih/Desktop/OpenXLSX-master/build/output/libOpenXLSX-shared.so)

Related

undefined reference to boost::system::generic_category() cmake

I have an undefined reference while trying to compile my Qt5 project.
I am usually pretty confident with using CMake but this time I have a strange error that I can't figure out:
undefined reference to boost::system::generic_category()
/usr/local/include/boost/system/error_code.hpp:223: undefined reference to 'boost::system::generic_category()'
My configurations are:
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Qt5.15
cmake version 3.16.3
After typing whereis boost the outcome wasboost: /usr/include/boost and after applying the great power of dpkg -s libboost-dev | grep 'Version' :) the version is Version: 1.71.0.0ubuntu2
I don't understand what is happening, below an example of how my CMakeLists.txt is structured:
cmake_minimum_required (VERSION 3.1)
project(projectA)
set (OpenCV_DIR /home/to/opencv/build)
find_package( OpenCV REQUIRED )
find_package( Boost COMPONENTS system thread filesystem REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5Widgets)
find_package(Qt5PrintSupport)
#make them into headers
qt5_wrap_ui (UI_HDRS ${UI})
add_executable(projectA main/main.cpp ui/qdarkstyle/style.qrc ${SRCS} ${UI_HDRS} ${UI_SRCS})
target_link_libraries (projectA Qt5::Widgets ${Boost_LIBRARIES} ${OpenCV_LIBS} Qt5::PrintSupport)
add_library(projectA_lib SHARED ${SRCS} ${UI_HDRS})
target_include_directories (projectA_lib PUBLIC "src/" "ui/")
link_directories(${Boost_LIBRARY_DIRS})
target_link_libraries (projectA_lib Qt5::Widgets ${Boost_LIBRARIES} ${OpenCV_LIBS})
I have searched and applied solutions I saw on all possible sources I was able to find such as:
This source but that didn't work.
Also from here it seems that this solution shall be applied:
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED COMPONENTS system)
# the call to include_directories is now useless:
# the Boost::system imported target used below
# embeds the include directories
project(APP C CXX)
add_executable(APP src.cpp)
target_link_libraries(APP Boost::system)
However that also didn't do any specific benefits to finding the solution.
Other posts I consulted were this, this one but no answer was provided.
This post was useful but that also didn't provide any advice that didn't already know.
Thanks for pointing to the right direction and trying to find a solution.

Installing libzippp library with cmake not working

Trying to install libzippp library in this project is not working for some reason, here is my project's CMakeLists.txt:
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(startProject)
set(Leptonica_DIR /Users/alejandrocamba/Documents/leptonica/build)
find_package(OpenCV REQUIRED)
find_package(Leptonica REQUIRED)
find_package(Tesseract REQUIRED)
find_package(libzippp 3.0 REQUIRED)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${Leptonica_INCLUDE_DIRS})
include_directories(${Tesseract_INCLUDE_DIRS})
add_executable(startProject main.cpp)
target_link_libraries(startProject libzipp::libzipp)
target_link_libraries(startProject ${OpenCV_LIBS})
target_link_libraries(startProject ${Tesseract_LIBRARIES})
I'm getting the error:
ld: library not found for -llibzipp::libzipp
I have followed the instructions and i cloned the repository and successfully installed it, so if i do make install i get:
But i can't seem to find a way to use it on my project, i need help to make get it working on my project!
Need more p: the proper target name for link with is libzippp::libzippp.
The project's README wrongly suggests to use libzipp::libzipp.

CMake is unable to find SDL2_ttf, I'm trying to link it the same way I would with SDL2 and both are properly installed on Ubuntu 18.04

I get the error:
CMake Error at CMakeLists.txt:11 (find_package):
By not providing "FindSDL2_ttf.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SDL2_ttf",
but CMake did not find one.
Could not find a package configuration file provided by "SDL2_ttf" with any
of the following names:
SDL2_ttfConfig.cmake
sdl2_ttf-config.cmake
Add the installation prefix of "SDL2_ttf" to CMAKE_PREFIX_PATH or set
"SDL2_ttf_DIR" to a directory containing one of the above files. If
"SDL2_ttf" provides a separate development package or SDK, be sure it has
been installed.
Here is what my cmake file looks like:
cmake_minimum_required(VERSION 3.14)
project(Smithereens)
set(CMAKE_CXX_STANDARD 17)
add_executable(Smithereens main.cpp)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
find_package(SDL2_ttf REQUIRED)
include_directories(${SDL2_ttf_INCLUDE_DIRS})
target_link_libraries(Smithereens ${SDL2_LIBRARIES} ${SDL2_ttf_LIBRARIES})
Both SDL2 and SDL2_ttf are installed on my machine, I'm sure I'm just linking incorrectly, learning CMake has been a huge headache for me.
This works pretty well for me, Ubuntu 18.04.
INCLUDE(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
PKG_SEARCH_MODULE(SDL2TTF REQUIRED SDL2_ttf>=2.0.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SOURCE_FILES main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_include_directories(${PROJECT_NAME} PRIVATE
include ${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS} ${SDL2TTF_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE
${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${SDL2TTF_LIBRARIES})

Cmake did find `A_library`, but when `make` it tells `library not found for A_library`?

I want to build a project which needs FLANN. When executing cmake, it shows
-- Checking for module 'flann'
-- Found flann, version 1.9.1
-- FLANN found (include: /usr/local/Cellar/flann/1.9.1_7/include, lib: flann;flann_cpp)
-- FLANN found (include: /usr/local/Cellar/flann/1.9.1_7/include, lib: flann;flann_cpp)
But I got ld: library not found for -lflann when executing make.
I'm using cmake 3.15.1 on MacOS.
The CMakeLists.txt shows below.
cmake_minimum_required(VERSION 2.8.11)
project(pcl_visualizer)
# init_qt: Let's do the CMake job for us
set(CMAKE_AUTOMOC ON) # For meta object compiler
set(CMAKE_AUTORCC ON) # Resource files
set(CMAKE_AUTOUIC ON) # UI files
set(Qt5_DIR "/usr/local/Cellar/qt/5.13.0/lib/cmake/Qt5")
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Find the QtWidgets library
find_package(Qt5 REQUIRED Widgets)
find_package(VTK REQUIRED)
find_package(PCL 1.7.1 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
add_definitions(${PCL_DEFINITIONS})
set(project_SOURCES main.cpp pclviewer.cpp)
add_executable(${PROJECT_NAME} ${project_SOURCES})
target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES} Qt5::Widgets)

Build Application using libpam0g-dev with cmake

I'm trying to build a C++ application which uses the library libpamg0-dev.
I installed it with the following command on my elementaryOS VM.
apt-get install libpam0g-dev
When I try to compile the application, the compiler spits out the following errors:
undefined reference to `pam_start`
undefined reference to `pam_authenticate`
undefined reference to `pam_end`
My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.10)
project(application)
set(CMAKE_CXX_STANDARD 11)
INCLUDE_DIRECTORIES(/home/dnagl/dev/libs/restbed/distribution/include /usr/include/security)
LINK_DIRECTORIES(/home/dnagl/dev/libs/restbed/distribution/library /usr/lib/x86_64-linux-gnu)
add_executable(application main.cpp Utils/Json/Json.cpp Utils/Json/Json.h Utils/Stringhelper/Stringhelper.cpp Utils/Stringhelper/Stringhelper.h Utils/File/Filehelper.cpp Utils/File/Filehelper.h Utils/System/SystemHelper.cpp Utils/System/SystemHelper.h Controller/Info/InfoController.cpp Controller/Info/InfoController.h Rest/ResourceHandler/ResourceHandler.cpp Rest/ResourceHandler/ResourceHandler.h Controller/System/SystemController.cpp Controller/System/SystemController.h Rest/Log/RequestLogger.cpp Rest/Log/RequestLogger.h Controller/Authentication/AuthenticationController.cpp Controller/Authentication/AuthenticationController.h Controller/Log/LogController.cpp Controller/Log/LogController.h)
target_link_libraries(application restbed)
Maybe one of you knows how to link the library in the right way.
I have found a nice solution with find_package option from CMake. CMake provides a way to find packages/libraries with specified FindModule.cmake file.
A really good news is that there are a lot of existing module files. You can use this version to find PAM package on Linux. Put it to cmake/modules/ in your project folder and update your CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(restbed)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Notify CMake that we have module files to find packages/libs.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
find_package(PAM REQUIRED)
# Check if we found PAM.
if (NOT PAM_FOUND)
message(FATAL_ERROR "PAM library was not found.")
endif ()
# Source configuration.
include_directories(
${PAM_INCLUDE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
set(EXECUTABLE_NAME "application")
# Add sources to this project's executable.
add_executable(${EXECUTABLE_NAME}
"main.cpp"
"Utils/Json/Json.cpp"
"Utils/Json/Json.h"
"Utils/Stringhelper/Stringhelper.cpp"
"Utils/Stringhelper/Stringhelper.h"
"Utils/File/Filehelper.cpp"
"Utils/File/Filehelper.h"
"Utils/System/SystemHelper.cpp"
"Utils/System/SystemHelper.h"
"Controller/Info/InfoController.cpp"
"Controller/Info/InfoController.h"
"Rest/ResourceHandler/ResourceHandler.cpp"
"Rest/ResourceHandler/ResourceHandler.h"
"Controller/System/SystemController.cpp"
"Controller/System/SystemController.h"
"Rest/Log/RequestLogger.cpp"
"Rest/Log/RequestLogger.h"
"Controller/Authentication/AuthenticationController.cpp"
"Controller/Authentication/AuthenticationController.h"
"Controller/Log/LogController.cpp"
"Controller/Log/LogController.h"
)
target_link_libraries(${EXECUTABLE_NAME}
${PAM_LIBRARIES}
)
set_target_properties(${EXECUTABLE_NAME} PROPERTIES LINKER_LANGUAGE CXX)
Hope this helps!