Shared code in subdirs template?
-
Currently I'm making a project which will finally generate two executables, (and of course) with qmake.
They share some code, so I put the shared part to a directory called "common", just under the root directory.
Code for these two executables are also put into separate directories under the root dir; one called "game", the other one called "editor".I don't know how to use code in the "common" directory; I want to compile the shared code directly into these executables, so setting its template to "lib" and generate shared objects may not be a good solution for me.
-
"Static libraries":http://en.wikipedia.org/wiki/Static_library are libraries that are linked into your program. You won't be needing a dll or so in that case.
-
Well, I successfully generated libcommon.a in common/; but I don't know how to make the final executables use it.
I tried to insert these lines into the .pri files, but it seems not working.
DEPENDPATH += ../common/
INCLUDEPATH += ../
POST_TARGETDEPS += ../common/libcommon.aHere is the error log:
g++ -Wl,-O1 -Wl,-rpath,/usr/lib64/qt4 -o ../saye build/main.o build/Saye.o build/GameWindow.o build/SayeMainWindow.o build/moc_Saye.o build/moc_GameWindow.o build/moc_SayeMainWindow.o -L/usr/lib64/qt4 -L/usr/X11R6/lib -lSimpleAV_SDL -lSimpleAVsdl-config --libs
-lSDL_mixer -L/usr/local/lib -pthread -lavformat -lavcodec -ldl -lasound -lbz2 -lz -lswscale -lavutil -lm -lQtXml -L/usr/lib64 -L/usr/lib64/qt4 -lQtOpenGL -L/usr/X11R6/lib -lQtGui -lQtCore -lgthread-2.0 -lrt -lglib-2.0 -lGLU -lGL -lpthread
build/Saye.o: In functionSaye::openProject()': Saye.cpp:(.text+0x730): undefined reference to
SayaMap::SayaMap(QString)'
Saye.cpp:(.text+0x7b8): undefined reference to `SayaMap::dump()'
collect2: ld returned 1 exit status
make: *** [../saye] Error 1The SayaMap class is defined in common/. Almost everything works well; this issue happens when linking the object files.
-
Nmmm... In fact I tried
@LIBS += ../common/libcommon.a@
Very ugly, but works.But here comes another question: what if we later updated common? Code used it should be recompiled, but make will not think it needs to do so.
Maybe I should switch back to shared libraries.
-
[quote author="wecing" date="1319138207"]So it will be different on Windows?[/quote]
For MinGW this should work too, as it's a gnu toolchain. It should work for the visual studio toolchain together with Qt Creator as IDE too.
I don't know if it works with full Visual Studio usage (including the IDE/GUI).