Context: I'm using Qt for c++. External libraries include opencv, opengl, pthread, among others. I left on vacation, and didn't use my computer for a month, though others used the computer while I was gone. As far as I know, my code, .pro file, everything has remain untouched.
Problem: When I returned to work yesterday, my code compiles, but segfaults almost immediately after execution begins. Because it compiled, but failed at runtime, I suspected a problem with shared libraries.
Things I discovered as I searched for a solution:
Update: I uncommented out the code that used opencv, and the program still executes correctly. Thus, the problem was solely with the missing libraries.
Problem: When I returned to work yesterday, my code compiles, but segfaults almost immediately after execution begins. Because it compiled, but failed at runtime, I suspected a problem with shared libraries.
Things I discovered as I searched for a solution:
- Definitions
- DSO - Dymanic Shared Object. These are libraries that a program uses during run time.
- ldd - a linux command that tells you what DSOs are required for a program.
- example execution: user@comp:~/directory$ ldd <Name-Of-Executable>
- example output: libopencv_core.so.2.3 => /usr/local/lib/libopencv_core.so.2.3 (0x00007f33f28d0000)
- if a library cannot be found, it will say so (like libpng12.so.0 => not found)
- http://www.cyberciti.biz/tips/linux-shared-library-management.html - helpful for learning more about debugging shared library issues
Solution:
- The segfault was occurring in an opencv file. I commented out the code that uses opencv, which I am not currently using anyway. Having done this, I now got linking errors from a colleague's code, which uses libjpeg, libpng, and libtiff. I had recently added sections of his code into my project.
- To solve the linking errors, I added explicit links to these libraries in the .pro file. Specifically,
-
LIBS += /usr/lib/x86_64-linux-gnu/libpng12.so \
/usr/lib/x86_64-linux-gnu/libjpeg.so \
/usr/lib/x86_64-linux-gnu/libtiff.so
I'll admit that linker errors and runtime libraries trip me up way too often. My best guess is that the location of the libraries changed while I was gone.
No comments:
Post a Comment