-1

I want to use this library https://github.com/troldal/OpenXLSX on my linux machine. How do I install or use libraries found on Gitub?

Also how do I know what compiler flags to use?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
GTA.sprx
  • 817
  • 1
  • 8
  • 24
  • 1
    Note the `CMakeLists.txt` file. It means that the library should be built with CMake. See: https://stackoverflow.com/a/7859663/2752075 – HolyBlackCat Dec 01 '19 at 21:07
  • GitHub is just a place to put things. Installation instructions differ wildly by project (some aren't even code!) and are _usually_ included with the project. This one apparently the author decided it was simple enough that most people could work it out for themselves – Lightness Races in Orbit Dec 01 '19 at 21:08

2 Answers2

3

The library you linked to is built using CMake (can be seen by the existence of a CMakeLists.txt file).

So you'd have to

  1. download the source code (git clone https://github.com/troldal/OpenXLSX.git on Linux/Mac or using git bash on Windows)

  2. generate the build system for your compiler (mkdir build; cd build; cmake .. on Linux/Mac)

  3. build the library (make on Linux/Mac)

Once you have built the library, generally there is an include directory and a lib directory (sometimes also named bin). If you are compiling directly using g++ or clang++, you'll have to add the include directory with the -I flag and the built library file in lib or bin with the -l flag:

g++ -Ipath/to/include -l/path/to/lib/libOpenXLSX.so your_sources.cpp

If you are using CMake or an IDE with its own build system, you'll have to add those two paths according to the documentation of that build system (see target_link_libraries for CMake for example).

CMake sometimes also generates "install" commands for built library. When you install the libraries, the headers and library will be copied to your global include path, so you won't need to specify the paths in your compile command anymore: g++ -lOpenXLSX your_sources.cpp.

eike
  • 1,314
  • 7
  • 18
  • For bonus points add _how_ you know it's designed to be built with CMake (i.e. the presence of CMakeLists.txt) – Lightness Races in Orbit Dec 01 '19 at 21:09
  • Was just about to edit the answer because of that :D – eike Dec 01 '19 at 21:09
  • Perfect thank you! This is where the spoonfeeding gets real. How do I "link it and include its headers?" I know how to include headers I made and standard ones but this my first time using a library like this. – GTA.sprx Dec 01 '19 at 21:17
  • @GTA.sprx What tools are you using to develop? Most IDEs have project files to specify which paths are included and which libraries are linked. – eike Dec 01 '19 at 21:19
  • @GTA.sprx I have tried to add some general information on how to use the built library. Hope that helps. – eike Dec 01 '19 at 21:45
0

Use the git clone command to download the library these two questions already answered would probably help you the most: And in regards to flags you would use the -I flag.

How to use Libraries C++ Link external libraries

GuardGoose
  • 57
  • 7