2

I want to make use of two libraries QCustomPlot and Eigen with Qt Creator on OS X. Both do not need to be installed and work fine if I just put them into my project folder and add them to the project. They do not have to be installed, "you can use the header files right away".

However I want them to be more independet than that, located outside the project to be used by other projects as well and I don't want their headers and source files to appear with my project files. But I do not know how to link them statically.

  • INCLUDEPATH += /../../Eigen/Eigen \ and
  • Add Library... -> External Library

apperently does not work, second one because their is no library file to open. I have no experience with libraries and tend to find this topic highly complicated.

Sharky Bamboozle
  • 1,066
  • 16
  • 28

1 Answers1

1

For the template only include library INCLUDEPATH should be sufficient as noted in comments. Generally, you can do it by manually modifying YourProject.pro file like:

LIBS += -L$$PWD/path_relative_to_pro_file/lib -lmylibfile1 -lmyflibfile2
INCLUDEPATH += $$PWD/path_relative_to_pro_file/lib/include

And your library file names end with .lib. In case if you want your project to be recompiled because of external library change:

DEPENDPATH += $$PWD/path_relative_to_pro_file/lib
DEPENDPATH += $$PWD/path_relative_to_pro_file/lib/include
Alexander V
  • 8,351
  • 4
  • 38
  • 47
  • But neither QCustomPlot nor Eigen have files ending with .lib in their folders? – Sharky Bamboozle May 18 '15 at 18:20
  • Huh, TheMindWithin, you said static linking. That usually implies having .lib. But of course template header include libraries are possible as well. – Alexander V May 18 '15 at 18:30
  • QCustomPlot for example does have a .cpp file and Eigen does have files like 'Core' without extension. I put them both at usr but INCLUDEPATH += $$PWD/../../QCustomPlot only like advised before does't work. (ld: symbol(s) not found for architecture x86_64) – Sharky Bamboozle May 18 '15 at 18:45
  • Oh, I see, there cases when the library binary files don't have .lib extension as default. Please check with the library docs. Then you can still reference those files in LIBS but you cannot omit an extension as in case with .lib. – Alexander V May 18 '15 at 18:49
  • Allright, this works fine for Eigen but not for QCustomPlot, since it is just a normal .h / .cpp file. What do I do here? – Sharky Bamboozle May 18 '15 at 21:08
  • TheMindWithin, if the library distributed as collection of header .h and implementation .cpp files, you have no way around but need to explicitly reference individual .cpp files as you do for your own. After you provided that INCLUDEPATH you can just find all the .cpp files with Qt creator and add them to compilation. Or do it by hand with SOURCES += myFile.cpp. I frankly am surprised by such library that requires you to reference its source code directly. My suspicion is that that library should have own makefile to produce lib files. – Alexander V May 18 '15 at 21:26