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 [en.wikipedia.org] 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.a
Here 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 -lSimpleAV `sdl-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 function `Saye::openProject()’:
Saye.cpp:(.text+0×730): undefined reference to `SayaMap::SayaMap(QString)’
Saye.cpp:(.text+0×7b8): undefined reference to `SayaMap::dump()’
collect2: ld returned 1 exit status
make: *** [../saye] Error 1
The SayaMap class is defined in common/. Almost everything works well; this issue happens when linking the object files.