1

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.

The QtCreator manual mentions .lib files which this library doesn't use so I'm kinda lost with that guide. 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. Yet I still get

exceltest.cpp:3: error: 'OpenXLSX.h' file not found

Line 3 is

#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

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. 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.

EDIT: So after I added my headers and sources to the project tree, my exceltest.pro looks like this. 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. QtCreator seems to find the library files but is something wrong with the library? 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>
          ^~~~~~~~~~~~~~~~~~~
  • Have you checked the .pro file if "OpenXLSX.h" is inside the HEADERS part ? – Daniel B Jun 18 '19 at 07:11
  • Good first question. Welcome. – Marc.2377 Jun 18 '19 at 07:11
  • @DanielB Edited. Could you take a look? :) – George Paul Jun 18 '19 at 08:33
  • I'm not sure but the fact that you use subdirectories in your project could cause the problem, see this thread: https://stackoverflow.com/questions/1176666/how-to-create-a-subdirectory-for-a-project-qtcreator You could try to load directly all your libraries inside the "Source" and "Headers" Folders without any Subdirectories(Located in the top left corner of the IDE where you can manage your project's folders.) – Daniel B Jun 18 '19 at 09:44
  • @DanielB I'll try that. – George Paul Jun 18 '19 at 12:17

1 Answers1

0

First, you have to build the OpenXLSX project to get the library. The project uses cmake for generation. 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:

INCLUDEPATH += /path/to/OpenXLSX/include
LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.lib

The first one allows you to include the OpenXLXS headers. 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. 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). It will add everything you need in your *.pro

Dimitry Ernot
  • 6,256
  • 2
  • 25
  • 37
  • Oh dude. This is basically what the guide I said didn't really help says except for the last bit on building on windows. Problem is... there aren't any .lib or .dll files in /OpenXLSX/@library or anywhere in the files. I edited the question with some new deets take a look would ya. – George Paul Jun 18 '19 at 08:37
  • If you downloaded the sources of Openxlsx, you have to build it yourself. Including the headers will not be enough – Dimitry Ernot Jun 18 '19 at 09:00
  • Could you expand on how to do that? Maybe a link? – George Paul Jun 18 '19 at 12:15
  • Niceeee. Thanks for the answer. I'm putting the project on hold for a while so I'll try it out only after a while. Thanks again! – George Paul Jun 18 '19 at 15:03