1

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.
themmfa
  • 499
  • 4
  • 15
  • 1
    You have to build OpenXLSX first. Have a look at the build instructions: https://github.com/troldal/OpenXLSX#build-instructions This should give you a library to include in your project – Michael Kotzjan Mar 29 '21 at 10:56
  • @M.Kotzjan I built it already however can't find which library I have to include. I'm new to cmake tbh. – themmfa Mar 29 '21 at 10:58
  • You need to use ```INCLUDE_DIRECTORIES``` for the header files, ```LINK_DIRECTORIES``` for the directory containing the compiled library and ```TARGET_LINK_LIBRARIES``` https://stackoverflow.com/a/24571137/7473793 – Michael Kotzjan Mar 29 '21 at 11:09
  • include_directories(/home/fatih/Desktop/27-03-2021-v2/OpenXLSX-master/library/headers) link_directories(/home/fatih/Desktop/27-03-2021-v2/OpenXLSX-master/library) target_link_libraries(/home/fatih/Desktop/27-03-2021-v2/OpenXLSX-master/library) – themmfa Mar 29 '21 at 11:13
  • @M.Kotzjan I added these too but same error. – themmfa Mar 29 '21 at 11:13
  • Your errors come from the line ```find_package(OpenXLSX REQUIRED)``` This should not be needed if you added the other lines. ```TARGET_LINK_LIBRARIES```need to contain the name of the library. I can only assume it to be OpenXLSX or something like that. You have to look for the file where you build it – Michael Kotzjan Mar 29 '21 at 11:18
  • When I check the project's name in it's CMakeList.txt file , I see project(OpenXLSX VERSION 0.2.0 LANGUAGES CXX) this, however when i use this i get an error like: CMake Error at CMakeLists.txt:41 (target_link_libraries): Cannot specify link libraries for target "OpenXLSX" which is not built by this project. – themmfa Mar 29 '21 at 11:24
  • @M.Kotzjan I used project name and file name but couldnt solve – themmfa Mar 29 '21 at 11:31
  • The first argument of ```TARGET_LINK_LIBRARIES```needs to be your own project https://stackoverflow.com/a/25909986/7473793 – Michael Kotzjan Mar 29 '21 at 11:54
  • Did what you said and it compiled. However when I try to use make command to compile my project, i get an error like this : OpenXLSX/OpenXLSX.hpp: No such file or directory #include "OpenXLSX-Exports.hpp" @M.Kotzjan – themmfa Mar 29 '21 at 12:05

1 Answers1

0

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)
themmfa
  • 499
  • 4
  • 15