
Originally Posted by
ChrisW67
In Qt PRO files you add to the search path with -L options in LIBS. You also name the libraries to search for in LIBS with -l (lower case L) options:
Yep. I was typing tooo fast (too much coffee?) in my earlier post and mistyped what I specified for the LIBS variable.
It may have worked on Linux/Mac because the common library directory was on the default search path for the linker (/usr/local/lib perhaps).
While anything is possible, I'm not so sure about that on *nix-based systems. For example, here's my compile and link lines of one of the directories into a shared object library. The code in here references another (not yet built) library. Note I use other 3rd-party packages, which I refer to at compile time with the '-I' compiler option (for the include files). Also note the link only refers to Qt libraries (which are in the default search path of /usr/lib).
I also made sure my system had no files named 'libelement.so' or 'libcore.so' before starting, including the Trash, before I started this compile.
cd src/element/ && make -f Makefile.linux all
make[1]: Entering directory `/home/project/src/element'
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I.. -I/usr/share/xsd-3.3.0/libxsd -Imocs -o ../../build/element/Element.o Element.cpp
. . .
/usr/lib/qt4/bin/moc -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I.. -I/usr/share/xsd-3.3.0/libxsd -Imocs Element.h -o mocs/moc_Element.cpp
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I.. -I/usr/share/xsd-3.3.0/libxsd -Imocs -o ../../build/element/moc_Element.o mocs/moc_Element.cpp
g++ -shared -Wl,-soname,libelement.so.1 -o libelement.so.1.0.0 ../../build/element/Element.o ../../build/element/moc_Element.o -lQtGui -lQtCore -lpthread
mv -f libelement.so.1.0.0 libelement.so libelement.so.1 libelement.so.1.0 ../../lib/
cd src/element/ && make -f Makefile.linux all
make[1]: Entering directory `/home/project/src/element'
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I.. -I/usr/share/xsd-3.3.0/libxsd -Imocs -o ../../build/element/Element.o Element.cpp
. . .
/usr/lib/qt4/bin/moc -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I.. -I/usr/share/xsd-3.3.0/libxsd -Imocs Element.h -o mocs/moc_Element.cpp
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I.. -I/usr/share/xsd-3.3.0/libxsd -Imocs -o ../../build/element/moc_Element.o mocs/moc_Element.cpp
g++ -shared -Wl,-soname,libelement.so.1 -o libelement.so.1.0.0 ../../build/element/Element.o ../../build/element/moc_Element.o -lQtGui -lQtCore -lpthread
mv -f libelement.so.1.0.0 libelement.so libelement.so.1 libelement.so.1.0 ../../lib/
To copy to clipboard, switch view to plain text mode
Then, the 'core' directory includes a class that holds a container of pointers to 'Elements' (map<string, Element *>):
make[1]: Leaving directory `/home/project/src/element'
cd src/core/ && make -f Makefile.linux all
make[1]: Entering directory `/home/project/src/core'
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I.. -I/usr/share/xsd-3.3.0/libxsd -Imocs -o ../../build/core/Engine.o Engine.cpp
. . .
g++ -shared -Wl,-soname,libcore.so.1 -o libcore.so.1.0.0 ../../build/core/Engine.o -lQtGui -lQtCore -lpthread
mv -f libcore.so.1.0.0 libcore.so libcore.so.1 libcore.so.1.0 ../../lib/
make[1]: Leaving directory `/home/project/src/element'
cd src/core/ && make -f Makefile.linux all
make[1]: Entering directory `/home/project/src/core'
g++ -c -pipe -g -Wall -W -D_REENTRANT -fPIC -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I.. -I/usr/share/xsd-3.3.0/libxsd -Imocs -o ../../build/core/Engine.o Engine.cpp
. . .
g++ -shared -Wl,-soname,libcore.so.1 -o libcore.so.1.0.0 ../../build/core/Engine.o -lQtGui -lQtCore -lpthread
mv -f libcore.so.1.0.0 libcore.so libcore.so.1 libcore.so.1.0 ../../lib/
To copy to clipboard, switch view to plain text mode
And the link of the application. Note the 3rd-party libraries are in the normal search path (/usr/lib):
g++ -o ../../bin/instrumentPanel.debug ../../build/main/main.o ../../build/main/qrc_InstrumentPanel.o -llog4cxx -laprutil-1 -lapr-1 -lxerces-c -L../../lib -lelement -ldisplay -lcore -lxsd -lexceptions -lmodel -lQtGui -lQtCore -lpthread
make[1]: Leaving directory `/home/project/src/main'
g++ -o ../../bin/instrumentPanel.debug ../../build/main/main.o ../../build/main/qrc_InstrumentPanel.o -llog4cxx -laprutil-1 -lapr-1 -lxerces-c -L../../lib -lelement -ldisplay -lcore -lxsd -lexceptions -lmodel -lQtGui -lQtCore -lpthread
make[1]: Leaving directory `/home/project/src/main'
To copy to clipboard, switch view to plain text mode
Then to run this application, I set an environment variable to point to the directories that include the shared libraries needed to run the application:
LD_LIBRARY_PATH=lib
./bin/instrumentPanel.debug
LD_LIBRARY_PATH=lib
./bin/instrumentPanel.debug
To copy to clipboard, switch view to plain text mode
There is no facility to automatically break the circular dependencies you have built. One approach is to avoid separating dependent items between libraries. Another is to avoid doing things with B in A that require knowing more than that B exists (i.e. more than storing a pointer to a B instance). Exactly how you fix this is specific to your code and not really Qt specific.
Bummer. Fortunately, there are ways around this. I can think of two:
1) Change the code directory structure (not my first choice but definitely doable)
2) Change the build structure to not build separate DLLs of each directory but maybe just one (e.g., libcore.dll) and have the main application just reference that library.
Anyway, I've got other problems of trying to get the other 3rd-party packages to work on Windows. Gonna be a loooong day..
Thanks for your help.
Bookmarks