PDA

View Full Version : Problem with link of external Library



navratill
3rd May 2011, 13:56
Hello there,

first, i have to tell, that i really tried to solve my problem by google and this forum, but I failed...

What i found: http://kernelcoder.wordpress.com/2010/07/01/creating-using-library-in-qt/ and i tried to do that.

I would like to use my external library libmathlib.a, which is located in Libs folder of project folder. Also i take a mathlib.h(which is h file of cpp file...these two files made libmathlib.a) so i take the mathlib.h and I placed it to Incs folder(like the tutorial says).

In pro file of my project in qt are these extra lines:
INCLUDEPATH += Incs
LIBS += -L"Libs" -mathlib

I was tried many of variants like:
LIBS += /Libs/libmathlib.a
LIBS += /Libs/libmathlib.a -mathlib
and many of other which i found on google

In cpp file in qt after that i have:
#include "mathlib.h"
and also this works:
Mathlib m;(or Mathlib *m = new Mathlib())
but when i was trying:
m.add(1, 2);

make says:
undefined reference to `Mathlib::add(double, double)'

Thanks for your help and really sorry for my english, I did my best :)

qlands
3rd May 2011, 14:06
Try

LIBS += -L/path/to/library -lLibrary_name_without_the_first_lib

I am assuming that the library is libmathlib.so.

Carlos.

navratill
3rd May 2011, 20:42
Hi,

thanks for your help, but this still doesnt work:

I tried it like:
LIBS += -L/Libs -mathlib

is this ok by your idea?

Thank you very much for your help

qlands
4th May 2011, 08:06
hummm...

Does the add function is :add(double, double) ? Because if it its parameters are integers or floats your compiler are sending 1 and 2 as double. So try to store 1 and 2 into integer or float variables A and B. And call add(A,B); to see if it works.

Can you paste mathlib.h? I cannot find any copy on the web to check the add() function.

Best.

mcosta
4th May 2011, 08:18
The correct syntax is



LIBS += -L/Libs -lmathlib


not the l (lowercase el) before the library name

I think you need to improve your knowledge about building and linking executables