PDA

View Full Version : Use your own built library?!



ranzani
21st June 2011, 10:05
I built my library "name" -> libname.a

QT -= gui
TARGET = name
TEMPLATE = lib
CONFIG += staticlib

(Also trying with dynamic -> libname.so ... )

This library contains a class

#include <...>
class NAMESHARED_EXPORT ClassName
{

public:
ClassName();
~ClassName();

QString getAttrVal( const int a,
const int b,
const char *data,
QString *description );

...
private:
...
};

NOW IN AN OTHER PROJECT I NEED TO CALL THE FUNCTIONS implemented in this library:

Eg.

.pro
LIBS += -Llib/ -lname

.h
class xxx
{
private:
ClassName *CN;
public:
xxx();
}

.cpp
xxx::xxx(){
CN = new ClassName();
QString test = CN->getAttrVal( 1, 2, "ciao", "bau" );
}


BUT WHEN COMPILE:

/xxx.h:188: error: ISO C++ forbids declaration of ‘ClassName’ with no type

Any suggestion? :confused:

cincirin
21st June 2011, 10:22
Did you include the header of "ClassName" definition in "other project" ?

ranzani
21st June 2011, 10:27
I try to include

ClassName.h

and lib/ClassName.h

But no headers found...

cincirin
21st June 2011, 10:33
Did you set INCLUDEPATH (http://doc.qt.nokia.com/latest/qmake-variable-reference.html#includepath) in project pro file ?

ranzani
21st June 2011, 10:51
ok, thanks! Now it compiles but when trying to run:

error while loading shared libraries: libname.so.1: cannot open shared object file: No such file or directory

cincirin
21st June 2011, 12:02
If your library is dynamic link you should remove "CONFIG += staticlib" from project file. Also if library is static link, remove NAMESHARED_EXPORT from class definition if this define is __declspec(dllexport)