PDA

View Full Version : Some questions about using libs in my project



alexandernst
10th November 2010, 19:43
I have a few questions about using libraries with my project.

First of all, I have a library project (attached here). I can build it fine, but I don't know how to make my project (my main app) use it.

I have that in my main app pro file:



INCLUDEPATH += ./libs/qtsingleapplication/
LIBS += -L./libs/qtsingleapplication/ -lqtsingleapplication


But when I try to do a


#include <QtSingleApplication>

I get an error saying that the file or folder can't be found.
What else should I do.

My second question is how can I make QtCreator build my library and then my main app according to debug or release. Also, should I change something in the pro file of my lib or in the pro file of my app to make them see that they should behave in a different way when debug or release is selected.

Regards!

5444

tbscope
11th November 2010, 06:25
#include <QtSingleApplication>
and

INCLUDEPATH += ./libs/qtsingleapplication/
This means it searches for the QtSingleApplication first in the known include paths like /usr/include etc...
If it doesn't find it, it will look in the paths you defined in the pro file, in your case it will look for:

/home/youraccount/yourproject/builddir/libs/qtsingleapplication/QtSingleApplication
Is this the correct path for the header?

As for building the library in debug or release, you can adjust the project settings. There's a projects button on the left hand side of the Qt Creator window. If you click on that button you'll get a lot of build and run options that you can create or choose from.

alexandernst
11th November 2010, 13:35
But my lib has a few source files that depend on the system that it's built (qtsingleapplication_win.cpp, qtsingleapplication_mac.cpp, qtsingleapplication_x11.cpp)
And I have a pri file that makes 'make' compile only the source file that is needed.

On the other hand, if I add the INCLUDEPATH as you said, I get an "undefined reference to "QtSingleApplication::<methods_go_here>" (I guess that this is happening because of what I already said about the source files)

How can I fix that?

alexandernst
11th November 2010, 23:41
Ok, I figured out how to use my lib with my project. I made a pro file for building my lib. It looks like this:



TEMPLATE = lib

INCLUDEPATH += $$PWD

HEADERS += $$PWD/qtglobal.h \
$$PWD/qtglobalshortcut.h \
$$PWD/qtglobalshortcut_p.h

SOURCES += $$PWD/qtglobal.cpp \
$$PWD/qtglobalshortcut.cpp

macx{
SOURCES += $$PWD/qtglobalshortcut_mac.cpp
}

unix:!mac{
SOURCES += $$PWD/qtglobalshortcut_x11.cpp
}

win32{
SOURCES += $$PWD/qtglobalshortcut_win.cpp
}



Everything works fine when compiling/running my app, and I'm able to use the functions in my lib. The problem is that when I build everything, my lib goes to the same directory that my main app, while in the "source structure" my library is under myproject/libs/my_library/.

How can I make qtcreator build my library in that same folder structure but in the build directory?