【问题标题】:How to add OpenXLSX to my project in c++?如何在 C++ 中将 OpenXLSX 添加到我的项目中?
【发布时间】:2021-03-29 10:51:32
【问题描述】:

我有一个项目,我想使用 OpenXLSX 作为 excel 库。但是,我无法将其添加到我的项目中。 我将所有 OpenXLSX 文件移动到我的项目文件夹中,但它不起作用。也将它们移到我的桌面,它也不起作用。

这是我的 CMakeList.txt 文件:

#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)

每次我尝试 cmake .. 和 make 时,我都会收到此错误。

 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.

【问题讨论】:

  • 您必须先构建 OpenXLSX。看看构建说明:github.com/troldal/OpenXLSX#build-instructions 这应该会给你一个库来包含在你的项目中
  • @M.Kotzjan 我已经构建了它但是找不到我必须包含的库。我是 cmake tbh 的新手。
  • 头文件使用INCLUDE_DIRECTORIES,编译库所在目录使用LINK_DIRECTORIESTARGET_LINK_LIBRARIESstackoverflow.com/a/24571137/7473793
  • 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)
  • @M.Kotzjan 我也添加了这些但同样的错误。

标签: c++ openxlsx


【解决方案1】:

我只是将这些命令添加到我的 CMakeList.txt 并部分解决了问题。

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)

但是,现在我得到了不同类型的错误。

/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

编辑:我也解决了这个问题。如果有人收到这样的错误,我将 target_link_library 注释更改为:

target_link_libraries(${PROJECT_NAME} /home/fatih/Desktop/OpenXLSX-master/build/output/libOpenXLSX-shared.so)

【讨论】:

    猜你喜欢
    • 2011-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多