Reputation: 3086
I am new to pangolin and trying to compile a 'hello world' code of pangolin on Qt Creator. I have run into this "undefined reference" issue while compiling it. My code is simple :
#include <iostream>
#include <pangolin/pangolin.h>
using namespace std;
int main()
{
pangolin::CreateWindowAndBind("Main",640,480);
return 0;
}
My .pro file looks as following :
QT += core
QT -= gui
TARGET = hellopangolin
CONFIG += c++11
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /home/mavbot/Pangolin/include /home/mavbot/Pangolin/build/src/include
LIBS += -L "/home/mavbot/Pangolin/build/src"
-lpangolin \
LIBS += -lGLEW \
-lGL \
-lEGL
I have successfully compiled and build the pangolin library as the example programs run smoothly on my system.I ran a ldd on the executable of the examples and found the dependent libraries and tried to link them in QT Creator. I am new to OpenGL too. The error I run into is :
error: undefined reference to `pangolin::CreateWindowAndBind(std::__cxx11::basic_string, std::allocator >, int, int, pangolin::Params const&)'
I build pangolin as follows :
git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake ..
make -j8
EDIT 2: After Botje's suggestion, inserting the / after the library path helped it to compile. However now I have a run time error :
/home/mavbot/Documents/qtcodes/build-hellopangolin-Desktop-Debug/hellopangolin: error while loading shared libraries: libpangolin.so: cannot open shared object file: No such file or directory
EDIT 3: -rwxrwxr-x 1 mavbot mavbot 2333648 Mar 10 23:55 /home/mavbot/Pangolin/build/src/libpangolin.so
linux-vdso.so.1 => (0x00007ffedc5b8000)
libGL.so.1 => /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 (0x00007f05e3401000)
libGLEW.so.1.13 => /usr/lib/x86_64-linux-gnu/libGLEW.so.1.13 (0x00007f05e317e000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f05e2e44000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f05e2c3c000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f05e2a1f000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f05e269d000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f05e2394000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f05e217e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f05e1db4000)
/lib64/ld-linux-x86-64.so.2 (0x00007f05e3a5a000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f05e1b9a000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f05e1971000)
libxcb-dri3.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri3.so.0 (0x00007f05e176e000)
libxcb-present.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-present.so.0 (0x00007f05e156b000)
libxcb-sync.so.1 => /usr/lib/x86_64-linux-gnu/libxcb-sync.so.1 (0x00007f05e1364000)
libxshmfence.so.1 => /usr/lib/x86_64-linux-gnu/libxshmfence.so.1 (0x00007f05e1161000)
libglapi.so.0 => /usr/lib/x86_64-linux-gnu/libglapi.so.0 (0x00007f05e0f30000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f05e0d1e000)
libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007f05e0b1b000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f05e0915000)
libX11-xcb.so.1 => /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007f05e0713000)
libxcb-glx.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-glx.so.0 (0x00007f05e04fa000)
libxcb-dri2.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri2.so.0 (0x00007f05e02f5000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f05e00d3000)
libXxf86vm.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007f05dfecd000)
libdrm.so.2 => /usr/lib/x86_64-linux-gnu/libdrm.so.2 (0x00007f05dfcbb000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f05dfab7000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f05df8b3000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f05df6ad000)
Upvotes: 1
Views: 931
Reputation: 31020
As /home/mavbot/Pangolin/build/src
is not a default place to look for libraries, you have to inform the dynamic linker (ld.so) to look there.
You can do this by:
LD_LIBRARY_PATH=/home/mavbot/Pangolin/build/src
every time you run your program, orld.so
to look there first. The flag is as follows:-Wl,-rpath=/home/mavbot/Pangolin/build/src
/etc/ld.so.conf
and/or /etc/ld.so.conf.d/*
for the default paths.Upvotes: 1