[英]How do I go about adding a third party library to QtCreator?
I'm trying to add OpenXLSX to my QtCreator project but following this guide I can't seem to get QtCreator to find the header file. 我正在尝试将OpenXLSX添加到我的QtCreator项目中,但是按照本指南的操作,我似乎无法让QtCreator找到头文件。
The QtCreator manual mentions .lib files which this library doesn't use so I'm kinda lost with that guide. QtCreator手册中提到了该库未使用的.lib文件,因此我对该指南有些迷惑。 I googled around and tried adding all the headers and sources from
OpenXLSX/@library/@openxlsx/interfaces/c++/
to my headers and sources directories in the project tree. 我四处
OpenXLSX/@library/@openxlsx/interfaces/c++/
,尝试将来自OpenXLSX/@library/@openxlsx/interfaces/c++/
标头和源添加到项目树中的标头和源目录中。 Yet I still get 但是我仍然得到
exceltest.cpp:3: error: 'OpenXLSX.h' file not found
Line 3 is 第3行是
#include "OpenXLSX.h"
I've also tried 我也尝试过
#include "3rdparty/OpenXLSX/@library/@openxlsx/interfaces/c++/headers/OpenXLSX.h"
The 3rdparty directory being in the same location as exceltest.pro 3rdparty目录与exceltest.pro位于同一位置
I've also tried both with angle brackets. 我也尝试过使用尖括号。
I don't need any advanced functionality from OpenXLSX, just reading and writing values to cells I specify to either .xlsx or .xls. 我不需要OpenXLSX的任何高级功能,只需在我为.xlsx或.xls指定的单元格中读取和写入值即可。 I'm also not married to the idea of using OpenXLSX so if anyone knows excel any libraries that would work better I'm open to the idea.
我也不喜欢使用OpenXLSX的想法,因此,如果有人知道excel,那么任何可以更好地工作的库都可以接受。
EDIT: So after I added my headers and sources to the project tree, my exceltest.pro looks like this . 编辑:因此,在我将标题和源添加到项目树之后,我的exceltest.pro看起来像这样 。 I tried putting this line
我试图把这条线
#include "3rdparty/OpenXLSX/@library/@openxlsx/interfaces/c++/headers/OpenXLSX.h"
into exceltest.h instead of exceltest.cpp and I'm getting different errors. 进入exceltest.h而不是exceltest.cpp,我得到了不同的错误。 QtCreator seems to find the library files but is something wrong with the library?
QtCreator似乎找到了库文件,但是库有问题吗? These are the errors:
这些是错误:
In file included from J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/@library/@openxlsx/interfaces/c++/headers/XLCell.h:49:0,
from ..\exceltest\3rdparty\OpenXLSX\@library\@openxlsx\interfaces\c++\sources\XLCell.cpp:5:
J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/@library/@openxlsx/interfaces/c++/headers/XLDefinitions.h:57:35: warning: multi-character character constant [-Wmultichar]
constexpr uint32_t maxRows = 1'048'576;
^~~~~
J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/@library/@openxlsx/interfaces/c++/headers/XLDefinitions.h:59:36: warning: missing terminating ' character
constexpr uint16_t maxCols = 16'384;
^
J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/@library/@openxlsx/interfaces/c++/headers/XLDefinitions.h:59:36: error: missing terminating ' character
constexpr uint16_t maxCols = 16'384;
^~~~~
..\exceltest\3rdparty\OpenXLSX\@library\@openxlsx\interfaces\c++\sources\XLCellRange.cpp:5:10: fatal error: XLCellRange.h: No such file or directory
#include <XLCellRange.h>
^~~~~~~~~~~~~~~
compilation terminated.
..\exceltest\3rdparty\OpenXLSX\@library\@openxlsx\interfaces\c++\sources\XLCellReference.cpp:5:10: fatal error: XLCellReference.h: No such file or directory
#include <XLCellReference.h>
^~~~~~~~~~~~~~~~~~~
First, you have to build the OpenXLSX project to get the library. 首先,您必须构建OpenXLSX项目才能获取该库。 The project uses cmake for generation.
该项目使用cmake进行生成。 You need to generate the worksapce, first:
您需要首先生成工作区:
List all the available generators with 列出所有可用的发电机
cmake --help
Chose the one you want to use, then: 选择您要使用的那个,然后:
cmake . -G "Your generator"
Build your project according to your generator. 根据生成器构建项目。 The libraries and headers will be copied in the install directory.
库和头文件将复制到安装目录中。
In your .pro file, add the following lines: 在您的.pro文件中,添加以下行:
INCLUDEPATH += /path/to/OpenXLSX/include
LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.lib
The first one allows you to include the OpenXLXS headers. 第一个允许您包括OpenXLXS标头。 The second line will be used by the linker to link the library to your app.
链接器将使用第二行将库链接到您的应用程序。
You may need to use a different version of your library if you want to build your project on Windows or Linux. 如果要在Windows或Linux上构建项目,则可能需要使用其他版本的库。 You can use this syntax:
您可以使用以下语法:
# On Windows in release mode
win32:CONFIG(release, debug|release): LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.dll
#On Windows debug mode
else:win32:CONFIG(debug, debug|release): LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx_debug.dll
#On Linux debug and release
else:unix: LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.so
In Qt Creator, if you right-click on your project, you can use the dedicated wizard to add a library ( Add Library
option in the context menu). 在Qt Creator中,如果右键单击项目,则可以使用专用向导添加库(上下文菜单中的“
Add Library
选项)。 It will add everything you need in your *.pro 它将在* .pro中添加您需要的所有内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.