Hopefully this is an easy question:
I am building an application with Qt and would like to use Google's Protocol Buffers. I have downloaded and installed the protobuf source, now I want to link against it in my project.
My .pro file contains the line:
LIBS += -L/usr/local/lib -libprotobuf
However, I get the error:
:: error: library not found for -llibprotobuf
when trying to compile.
I am assuming that I am doing something rather basic wrong. Thanks for any help!
Assuming the file is libprotobuf.[so|a], the correct library link command is -lprotobuf (the lib prefix is implied)
Related
I am using Code::Blocks IDE on Debian 8. I have installed the plplot library form synaptic (not from source). When I create new project in C::B and try to run a simple plplot example the compiler do not recognize the includes and the linker do not recognize the plplot library. So how to compile and link with plplot library when I have installed it from Synaptic not from source? Is this possible, or I should remove current packages and install from source only?
In general when I install new library (from synaptic or from source) how to find out what should be the compiler flags and search directories and for the linker too? I think installing from source should be the less problems prone way!
Till now I am doing file search for the included header and add its directory to the search path for the compiler. But this is very cumbersome and naive approach. It will be better if I add compiler flag that does all this job, but how to find it out. Some flags I find in forums but not in the documentation of the libraries. Why there is no file with the third program library to tell what flags should one use? Nevertheless when the o files are done I have linker errors like "undefined reference to...".
For the plplot library the linker flag should be -lplplotd. For the compiler options I have no flags but I did a search for the unknown headers and added their directories to the search directories path. Now the Example 00 works fine. Though I found the -lplplotd flag by shooting! For the x11 examples one should add the flag -lplplotcxxd.
In general I got that to find the linker flag I have to search for the library so file and the name of the file commonly is the flag, e.g. for the library libplplotcxxd.so the flag is -lplplotcxxd.
Anyway, I'd be glad if someone tells me a better clue on finding these linker flags.
I am trying to set up Marble to work with Qt 5.5 on OSX. I'm not very experienced with the details of linking and such and I think that is causing the problem I am having.
Question: Did I screw up the 'marble` install or is this an easily solved linking issue?
Qt 5.5 is installed in my user directory (using Qt's network installer) on a system running OSX 10.9.5. It works fine. I followed the instructions on the Marble site to clone, build and install from source with (I believe) the appropriate Qt flags. That seemed to go without issue. When I try to build the simple test app listed here, the #include <marble/MarbleWidget.h> line gives a "file not found" error.
After the install I've ended up with the following:
A "marble" directory in my root user folder
A "Marble.app" file along with various other marble related files in the bin and include directories. However the Marble.app gives the following error on launch:
Dyld Error Message: Library not loaded:
#rpath/QtCore.framework/Versions/5/QtCore Referenced from:
/usr/local/Marble.app/Contents/MacOS/marble-qt Reason: image not
found
Binary Images:
0x7fff6a1f9000 - 0x7fff6a22c817 dyld (239.4) <7AD43B9B-5CEA-3C7E-9836-A06909F9CA56> /usr/lib/dyld
So a semi-solution: I used the Qt Creator "add Library" function and ended up with the following additions to the .pro file. I had to paste in the link to the lib since the dialog doesn't allow browsing of "usr/local/". Also, although I tried to link to the lib alias ("libmarblewidget-qt5.dylib"), the actual lib name is used.
macx: LIBS += -L$$PWD/../../../../../usr/local/lib/ -lmarblewidget-qt5.0.21.80
INCLUDEPATH += $$PWD/../../../../../usr/local/include
DEPENDPATH += $$PWD/../../../../../usr/local/include
I don't understand what this $$PWD/../../../../../ business is.
But it worked and I am able to run the example code at the link in my question.
I wish this install/build stuff wasn't so damned arcane. I've spent endless hours just trying to get things set up – really sucks the joy out of exploring this stuff and I can't say I really learned much of anything from it.
Update
So I cleaned out the "$$PWD" crap and the literal lib name and it works. Not sure what difference it makes – but there you go.
macx: LIBS += -L/usr/local/lib/ -lmarblewidget-qt5
INCLUDEPATH +=/usr/local/include
DEPENDPATH +=/usr/local/include
Either the build is faulty or you need a different version of Qt installed to run it. Usually the app has the Qt libraries that it needs wrapped up in the app itself. If it's not in there it will search your mac for it. The message says that QtCore can't be found in either place. If you look inside Google's Google Earth, you can see where the libraries are stored. You can also copy a version of QtCore into your Marble to see if it will work.
I created a C++ library project in Qt creator. After building the project I have the libMylib.so, .so.1, .so.1.0, .so.1.0.0, Makefile and mylib.o files. I added the library headers to my other project and added the path to my .pro file like this:
LIBS += "/home/peter/Workspace/build-Libtester-Desktop-Release/libMyLib.so"
When building the application I don't get no such file error, but when running it I get this:
/home/peter/Workspace/build-Libtester-Desktop-Debug/Libtester: error while loading shared libraries: libMyLib.so.1: cannot open shared object file: No such file or directory
which I can't understand, because it's right there next to the .so which it seem to find, because when the path is wrong I get a no such file or directory error when trying to build the project.
Could someone explain what I'm missing here?
Thanks for your time.
Fortunately, your problem has nothing to do with both Qt and Qt Creator. The error simply boils down to how shared libraries are searched by LD for dynamic linking on Unix OS family.
Today, I've answered similar question, have a look, please. This question was asked in regard to Mac OS X. However, Linux and Mac OS X are the same in the context of your problem. I've provided additional explanation for Linux at the bottom, so pay attention to it. "it's right there next to the .so" - you seem to have Windows background if you make this assumption, but it is wrong for Unix OS family altogether (as stated in the answer too). If you have further questions, just ask.
You are adding the library incorrectly. You are doing:
LIBS += "/home/peter/Workspace/build-Libtester-Desktop-Release/libMyLib.so"
instead of:
LIBS += -L"/home/peter/Workspace/build-Libtester-Desktop-Release" -lMyLib
The first version works on windows, but not linux.
Basically, you create a library, which will be named "libMyLib.so", and then you specify the path to its folder, prepended by "-L" and then do "-lMyLib" at the end, note that it's not "-llibMyLib", but just "-lMyLib", despite the fact that the .so name is "libMyLib".
Look here: https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application for more info.
We're developing a quite large Qt-based project on linux, and we reached final RC1 stage.
Now, we encountered something really strange: in order to go into production, we added another .a library in our list of static linking libs.
The library is linked and the application runs, but every .png in the resource file is corrupted, here's the output on startup:
libpng error: IHDR: CRC error
seems like libpng cant handle those invalid png (of course). The files are there and the size is right, they just turned blank after static linking that final library. The library itself is not used anywhere, it is just linked.
Has anyone encountered such a situation before? is there a known workaround? We're using Qt 4.7.4 x64 on QtCreator 2.3.0, we would like not to upgrade for now, but it is the only option that comes into our mind for now.
It could fit a problem with symbols.
The static library and libpng could be at same time linking to other library and when linking or resolving in compile/load time something weird is happening.
You can use objdump command to inspect symbols (objdump -tT /usr/bin)
Have you tried modifying the library order when compiling/linking? I mean, for example,
gcc -lmylibrary -lQt -lOtherLOLibrary
instead of
gcc -lOtherLOLibrary -lQt -lmylibrary
And I think I'm missing something, why do you link against an unused library?
I want to run the example found here: http://doc.qt.nokia.com/qtmobility-1.2/samplephonebook.html
But I have an error in this line:
QContactObserver* m_observer;
The error is:
ISO C++ forbids declaration of 'QContactObserver' with no type
in the contacteditor.h file.
What's wrong ? What should I do for that to run?
This question may well have already been solved for the original OP, but for the sake of other users stumbling onto it:
QContactObserver is part of Qt Mobility. Although Qt Mobility is included with the QtSDK, it must be unpacked and built on the development system to ensure that it is configured properly to be used in a project on that system.
In addition, the .pro file requires additions to prompt it to include the required Qt Mobility headers. For example, QContactObserver is part of the QtContacts module, so the .pro file would require the follwing additional lines:
CONFIG += mobility
MOBILITY += contacts
The error mentioned in the comments above:
MBX: you sure have a #include <QContactObserver>, don't you?
Marwa Shams: when i include it .. I have an error "no such file or directory"
occurs because Qt does not know where to look for the <QContactObserver> headers. Following the steps above will remedy the problem.