How do I get xlnt library / cMake to work - c++

I previously built a programme in C#, now I wanted to write it in C++ to learn this language a bit. I need access to an xlsx file and I want to use XLNT library. The problem is I have absolutely no idea how to get it to work. I read some other topics on SO but nothing makes sense to me at all. First of all, isn't there a simple way to use this library? Like, when I wanted to add a library in C# I just installed the NuGet package and that was all, it simply worked. Isn't it that simple in C++ as well?
From what I read so far in the other topics, it seems that I have to use a tool called CMake (again, isn't there a simpler way?). But I have no idea how to do that. What I did so far was:
I downloaded CMake installer and installed CMake
I downloaded xlnt zip file from GitHub and extracted it
I opened CMake GUI and:
a) as the source code folder I put this: C:/Users/Admin/Downloads/xlnt-master (this is the folder to wchich I extracted the zip file)
b) as the build folder I put this: C:/Users/Admin/Downloads/xlnt-master/build (I created the build folder after extracting the zip)
c) I clicked configure and left everything as default, except I changed the Visual Studio Version to 2019
d) I clicked generate and then I get an error message 'Error in generation process, project files may be invalid'. And it says this in the CMake Window:
'CMake Error at third-party/libstudxml.build/CMakeLists.txt:52 (add_library):
Cannot find source file:
C:/Users/Admin/Downloads/xlnt-master/third-party/libstudxml/libstudxml/parser.cxx
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
.hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc
CMake Error at third-party/libstudxml.build/CMakeLists.txt:52 (add_library):
No SOURCES given to target: libstudxml '
Another solution that I tried was finding the NuGet package called xltn and install it. After trying to compile the programme, though, I get two errors:
cannot open file 'xlntd.lib'
"link.exe" exited with code 1104

Related

Problems building XLNT library for Visual Studio 2017

I am having trouble building the XLNT (https://github.com/tfussell/xlnt) library in Visual Studio 2017, and I'm confused. I downloaded the latest version of the library and the latest version of CMake. When I ran the CMake gui, it couldn't find the libstudxml files. A post said that those needed to be downloaded; so I downloaded that library (https://www.codesynthesis.com/projects/libstudxml/#download) and placed it in third-party/libstudxml.
Then I got errors that it couldn't find some .hxx files in libstudxml. I found this article, https://discourse.cmake.org/t/cmake3-20-cant-generate-xint-package/2987, that said I needed to replace libstudxml in some paths in the libstudxml.build\CMakeLists.txt file with just xml. Then it still couldn't find these three .hxx files (content.hxx, exception.hxx, and forward.hxx). I looked in the libstudxml/xml folder (they were all there but extensionless). I changed the CMakeLists.txt file to not have the .hxx extension and Cmake was able to generate.
When I went to compile it in Visual Studio (hitting Project in the Cmake GUI), I got errors that some files couldn't find the content.hxx file again and the builds failed. I'm kind of running in circles. To get cmake to generate, I had to remove the .hxx extensions, but then some files complain because they are looking for them. I tried leaving the three files witout the extensions and removing the extensions from the CMakeLists.txt file, but then some of the files were looking for the files without the extension. Leaving the files both with and without the extension was also a cluster. I understand that C++ can handle extensionless header files, but the CMake file seems to want extension, but I don't think VS is happy with them.
Additionally, while I needed to change the folder name to be xml instead of libstudxml for CMake, various include files in the source code are still looking for libstudxml; so that doesn't work.
Any thoughts?
Thanks--
Al
I experienced the same problems with the same progress and blockages. Indeed changing the extensions or locations did not solve the problem. Then I tried to find another version of the libstudxml library, the creator of xlnt might have used an other one.
So I found the following archive: https://pkg.cppget.org/1/beta/libstudxml/
and placed the files in \xlnt-master\third-party\libstudxml , without modifying the names of the CMake path. This time I was able to compile the library (mingw32-make, I'm not using VS17 in my case).

Where do I put these header/c files or libraries that I just downloaded? (C++, MinGW)

I haven't used online libraries before this.
I just downloaded libzip from https://libzip.org/ (was looking for c++ file to unzip zip files)
I now have this nice folder that's called libzip-1.5.2.
Where do I put it? I'm using mingw to compile, and just emacs to write.
I've tried copy and pasting it into mingw's various bin folders, lib folders, include folders, etc. A great variety of places within the C://mingw root folder. None of them work.
No matter where I look, every single question glosses over this, just saying "just include zip.h" but never mentioning how to actually set it up.
I guess this could be generalized to: I have a bunch of .c and .h files from a library I downloaded for my compiler. Where do I put them so that I don't get:
"fatal error: header.h No such file or directory"
Again, I use MinGW/G++ to compile, and just Emacs for writing. I'm running Windows 10.
Put it somewhere with an simple pathname. You have to tell g++ where to find the libraries and the headers. Normally this is done with the -L and -I option. Maybe you have to compile the library first. There you have to look at the install instructions.

Generating Qt pro files from sln file

I like to make Qt applications in Visual Studio. But sometimes, there is a need to continue development in Linux space, where Visual Studio is not available. Therefore, there's a need to write down project files manually.
Is it possible to generate .pro files and makefiles from configurated .sln file?
I don't use Microsoft Visual Studio so I never had to deal with .sln files.
But actually, to generate your Qt environment from the command line in linux, you don't need the .sln file.You just have to do as follows:
Create your project directory, let's call it MyQtProject
Copy inside your sources files (.h, .cpp)
Then cd MyQtProject and run qmake -project : It will read your directory and create your .pro file (adding your headers and sources files, ...).
You can edit the generated MyQtProject.pro file to add some specific instructions (for exampleQT += widgets)
Then you just have to run qmake MyQtProject.pro to generate the Makefile.
Finally run make to compile.
Of course, you can create a build directory inside MyQtProject and run qmake ../MyQtProject.pro and make from inside it in order to not pollute your project folder with the moc files and the cmake related files.
I hope it can help you and solve your problem.

How to compile/build/link - the XLNT library?

I downloaded the xlnt library for working with Excel - https://github.com/tfussell/xlnt. Can you please tell me what to do with it further? Honestly, I still can’t understand how among all the files there are in the downloaded archive, and there are 100 of them .hpp and .cpp files, what should I do with them?
1)As far as I understand, they need to be processed by the Cmake program and it seems that the output should appear .lib file, but I absolutely can’t understand how to do it or maybe something else
2)Or how can they be directly processed by Visual Studio 2017?
PS:When I launch Smack, I select the Source folder, the Cmake generates many incomprehensible files, but among them there is not one file with the .lib extension.
Help me please.
With CMake you can obtain the visual studio 2017 project files
and then compile the xlnt library.
Unzip the archive file
Within the xlnt folder, create a new directory and call it build
Launche CMake (GUI)
Browse for the source code folder
Browse for the build folder xlnt/build
With the Configure button select the tool (IDE/compiler) that you want to use
Pressing the Generate button, CMake will generate (inside the build folder)
the visual studio 2017 project files you need to compile the xlnt library
Building the solution, VS 2017 produces the xlnt.lib, xlnt.exp and xlnt.dll files.
The source path you see in the CMake screenshot is incorrect. You must specify the path that contains the "top level" CMakeLists.txt file.
The correct directory is: C:/Users/Zver/source/repos/XLNT Library/xlnt-master.
The CMakeLists.txt file in the above directory tells CMake all necessary subdirectories.
At this point you will see the static compilation option of the library appear.
If you use the MinGW/GCC compiler you must prevent the path from containing empty spaces.
Then you need to rename the directory from "XLNT Library" to "XLNTLibrary". At this point the path would become:
C:/Users/Zver/source/repos/XLNTLibrary/xlnt-master.

How to include a library in my code using cmake?

I have tried to ´make´ the library yaml-cpp, not sure I did it right, but how do I build it?
In the tutorial (https://github.com/jbeder/yaml-cpp/blob/master/README.md) it says to run cmake in the build dir, but cmake could not find the cmakelist file, so I did it in the source dir, but then what? How do I build it?
If someone could make a newbie step by step to get the library (or any library really) so I can include it in my code, that would be awesome.
Im using Windows 7, and compiling using terminal (using Codeblocks MinGW gcc/g++) and sublime text 3 editor.
Edit: I have not "make". How can I get this?
Here is the step by step guide:
For the purpose of this answer I will use cmake gui instead to highlight a few key points.
go to https://github.com/jbeder/yaml-cpp and download the root library.
open cmake gui and select the source directory as <my project>/yaml-cpp-master
select a directory for the build. I would call it <my project>/yaml-cpp-master/codeblocks_build
press configure and then check all the values.
press generate and wait for it to complete.
Find the generated codeblocks project file within <my project>/yaml-cpp-master/codeblocks_build
Compile the project as you normally would.
find the generated DLL files and link them to your project.
The reason why you are getting this error is because cmake is trying to find the source code in the directory build which is newly created as seen in the tutorial:
mkdir build
cd build
This is meant to specify to cmake where to build it in rather than where to build from. If you wish to use it via a command line you will need to tell cmake where to build and where the source is.
To then call the functions from that library you will need to link the header files (files that start with .h or .hpp) and the DLL libraries.
the .cpp .c etc is where the implementation is but .h .hpp is where the definitions are.
So when you are including like this: #include<something.h> you are including definitions which are later filled by the .cpp files however in case of a library they are instead filled from .dll or .o