I've worked with opencv on linux in the past, but not with cuda. I've struggled with the following compilation error for months. And after trying many solutions i gave up and worked with windows. However, i really want to work on linux. This is the command i'm using to compile the threshold example given on the opencv_gpu website.
nvcc `pkg-config --libs opencv` -L. -L/usr/local/cuda/lib -lcuda -lcudart `pkg-config --cflags opencv` -I. -I/usr/local/cuda/include threshold.cpp -o threshold
here is the error:
/tmp/tmpxft_0000171b_00000000-1_threshold.o: In function `main':
threshold.cpp:(.text+0x124): undefined reference to `cv::gpu::Stream::Null()'
threshold.cpp:(.text+0x156): undefined reference to `cv::gpu::threshold(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, int, cv::gpu::Stream&)'
threshold.cpp:(.text+0x16d): undefined reference to `cv::gpu::GpuMat::download(cv::Mat&) const'
/tmp/tmpxft_0000171b_00000000-1_threshold.o: In function `cv::gpu::GpuMat::GpuMat(cv::Mat const&)':
threshold.cpp:(.text._ZN2cv3gpu6GpuMatC1ERKNS_3MatE[cv::gpu::GpuMat::GpuMat(cv::Mat const&)]+0x63): undefined reference to `cv::gpu::GpuMat::upload(cv::Mat const&)'
/tmp/tmpxft_0000171b_00000000-1_threshold.o: In function `cv::gpu::GpuMat::~GpuMat()':
threshold.cpp:(.text._ZN2cv3gpu6GpuMatD1Ev[cv::gpu::GpuMat::~GpuMat()]+0xd): undefined reference to `cv::gpu::GpuMat::release()'
collect2: ld returned 1 exit status
make: *** [all] Error 1
In order to help you I had to download and install CUDA 4.0 (with driver 4.0.21) and then download and compiled OpenCV 2.3 for my Macbook Pro, on Mac OS X 10.6.8.
The sample code from OpenCV_GPU was successfully compiled on my machine through:
g++ threshold.cpp -o threshold `pkg-config --cflags --libs opencv` -lopencv_gpu
You were missing the flag -lopencv_gpu , which is not included by pkg-config.
This looks like a linker problem. I don't know, if nvcc follows the same conventions as gcc, but I would try:
nvcc `pkg-config --cflags opencv` -L. -L/usr/local/cuda/lib -I. -I/usr/local/cuda/include -o threshold threshold.cpp `pkg-config --libs opencv` -lcuda -lcudart
More in general: If you write
gcc t.cpp -lB -lA
it means that libB depends on symbols from libA; t.cpp can depend on symbols from libA and libB.
Instead of using pkg-config in the nvcc line I would suggest just manually pointing the compiler at the opencv library and include files. Perhaps you could just run pkg-config --libs opencv on the command line and copy the necessary libs into your nvcc command. It seems nvcc is only choking on the opencv libs (it can't find them for sure!).
Related
I can include items from xcb/xcb.h, but not items that are outlined in /usr/include/xcb/randr.h.
My preference is to use C++, but to help debug I also tried C which produced variations of the same error.
I am certain I am doing something incorrectly, but I am not sure where to start looking to resolve this. Thank you very much for reading, any suggestions?
Example
main.cpp
#include <xcb/xcb.h>
#include <xcb/randr.h>
int main()
{
const xcb_setup_t * xsetup;
xcb_connection_t * conn;
xcb_screen_t * screen;
xcb_window_t root_win;
xcb_screen_iterator_t screen_iterator;
xcb_randr_get_screen_resources_cookie_t resources;
// connect to Xserver
conn = xcb_connect(NULL, NULL);
xsetup = xcb_get_setup(conn);
// get the root window
screen_iterator = xcb_setup_roots_iterator(xsetup);
screen = screen_iterator.data;
root_win = screen->root;
// any function from xcb/randr.h fails with undefined reference.
resources = xcb_randr_get_screen_resources(conn, root_win);
}
Compile
# gcc tries
gcc -Wall main.cpp -o main `pkg-config --cflags --libs xcb`
g++ -Wall main.cpp -o main `pkg-config --cflags --libs xcb`
# clang tries
clang++ main.cpp -o main `pkg-config --cflags --libs xcb`
clang main.cpp -o main `pkg-config --cflags --libs xcb`
Result
gcc
/usr/bin/ld: /tmp/ccWR2GQL.o: in function `main':
main.cpp:(.text+0x6c): undefined reference to `xcb_randr_get_screen_resources'
collect2: error: ld returned 1 exit status
clang
/usr/bin/ld: /tmp/main-d114b5.o: in function `main':
main.cpp:(.text+0x67): undefined reference to `xcb_randr_get_screen_resources'
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
xcb libraries are split up in several different packages; so it goes that you need to pull in both xcb and xcb-randr libraries, explicitly:
... `pkg-config --cflags --libs xcb xcb-randr`
It's possible that your Linux distribution packages the randr library separately. Checking Fedora, it packages both xcb and xcb-rand in the libxcb-devel subpackage; but it's possible that your Linux distribution has a separate libxcb-randr-devel subpackage that you need to install.
Thank you very much n.m. and G.M. .
I was not linking the xcb-randr .
Solution:
clang++ main.cpp -o main `pkg-config --cflags --libs xcb` -lxcb-randr
When I compile my code that uses OpenCV and caffe, I get the following linker errors:
../libs/libopencv_highgui.so: undefined reference to `g_mutex_lock'
../libs/libgstbase-0.10.so.0: undefined reference to `g_cond_init'
../libs/libopencv_highgui.so: undefined reference to `g_mutex_unlock'
../libs/libopencv_highgui.so: undefined reference to `g_cond_broadcast'
../libs/libgstreamer-0.10.so.0: undefined reference to `g_cond_wait_until'
../libs/libopencv_highgui.so: undefined reference to `g_mutex_new'
...
collect2: ld returned 1 exit status
This my g+ commmand:
g++ -DCPU_ONLY=1 test.cpp -o test -I../include -I../include/openblas -L../libs
-Wl,-rpath=../libs -lcaffe -lglog -lboost_system -lopencv_core -lopencv_highgui
-lopencv_imgproc
What am I missing?
Yep, this is a simple case of not linking against glib.
In general, to fix this kind of thing, google one of the symbol names(g_mutex_lock, for example) to figure out what library it comes from. In this case, it is glib. Then, look in their documentation for help compiling applications that use their library(if you can't figure it out on your own). In this case, you end up here.
Once you have made sure you have all required packages installed, you augment your compiler options as needed.
In your case, try g++ -DCPU_ONLY=1 test.cpp -o test `pkg-config --cflags glib-2.0` -I../include -I../include/openblas `pkconfig --libs glib-2.0` -L../libs -Wl,-rpath=../libs -lcaffe -lglog -lboost_system -lopencv_core -lopencv_highgui -lopencv_imgproc
Note the use of pkg-config. For reference, compiling a sample application that uses only glib might look like this: gcc hello.c `pkg-config --cflags --libs glib-2.0`
I have a problem with compiling the example form LenMuse - this is the example.
I used flags from the provided tutorial and I added a few more to get rid of some other problems, but I can't solve all of them. This is my output from gcc:
/usr/lib/liblomse.so: undefined reference to `boost::thread::start_thread()'
/usr/lib/liblomse.so: undefined reference to `boost::thread::timed_join(boost::posix_time::ptime const&)'
/usr/lib/liblomse.so: undefined reference to `boost::this_thread::sleep(boost::posix_time::ptime const&)'
/usr/lib/liblomse.so: undefined reference to `boost::thread::~thread()'
This is the command I used:
gcc interface.cpp -o interface `pkg-config --cflags x11` `pkg-config --cflags liblomse` `pkg-config --libs liblomse` `pkg-config --libs x11` -lstdc++ -lboost_system -I/usr/include/boost/ -lboost_filesystem -lboost_thread
I tried to compile with the flag -lboost_thread-mt but gcc cannot find this flag.
I have boost 1.53.0, on the page author says that is required boost 1.43 or higher. My system is ArchLinux.
I solved this problem by downgrade boost library to version 1.49.0.
I tried to compile my c++/opengl-project with the g++ command.
(I need this since I want to recompile it on every target system with a second self-written program.)
But when I execute:
g++ -Iinclude -Isrc $(pkg-config --cflags freetype2) -L/usr/X11R6/lib -L/usr/lib $(pkg-config --libs glew) -lglut $(pkg-config --libs glu) $(pkg-config --libs freetype2) main.cpp (some more source files) src/Vec4.cpp
I get lots of 'undefined references' for gl/glu/glut/glew-functions, so I guess something fails with the libs:
/tmp/ccUm2dEl.o: In function `Box::render()':
Box.cpp:(.text+0x6e8): undefined reference to `glEnable'
Box.cpp:(.text+0x72c): undefined reference to `glBindTexture'
Box.cpp:(.text+0x736): undefined reference to `glBegin'
...
TextureManager.cpp:(.text+0x23b): undefined reference to `glTexParameteri'
TextureManager.cpp:(.text+0x295): undefined reference to `glTexImage2D'
collect2: ld gab 1 als Ende-Status zurück
I did some research, but according to what I found out the above command should be correct.
I checked the pkg-config-calls as well and they seem to work.
Before I tried the g++ command I used the Codeblocks IDE to compile it and it worked. Here are my settings:
In Compiler settings|Other options:
`pkg-config --cflags freetype2`
In Linker settings|Link libraries:
glut
In Linker settings|Other linker options:
`pkg-config --libs glu`
`pkg-config --libs glew`
`pkg-config --libs freetype2`
In Search directories|Compiler:
include
src
My system (Ubuntu Precise):
$ uname -a
Linux andromeda 3.2.0-32-generic #51-Ubuntu SMP Wed Sep 26 21:33:09 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
$ g++ -dumpversion
4.6
glxinfo
GLX version: 1.4
OpenGL version string: 4.2.0 NVIDIA 304.43
Codeblocks-version: 10.04
Thanks in advice
The problem is most likely that you link in the wrong order. The GNU linker wants its libraries in kind of reverse order, so if you place the linker libraries last on the command line it should go better.
I am using eclipse CDT for a massive C++ project that has been compiling beautifully for 2 years now. I started having some weird segfaults that made no sense about 2 weeks ago and it appeared that somehow gtk had been corrupted. So since it was about time for a distro upgrade anyways I decided to upgrade from 11.04 to 12.04. Now, nothing will link. Every dependency I have throws an undefined reference error at link time. Everything compiles fine and all of the pkg-config commands are returning what they should.
Any ideas?
Here is the command:
Invoking: GCC C++ Linker g++ `pkg-config libv4l2 --libs` `pkg-config --libs alsa` -lmysqlcppconn -lboost_regex `pkg-config sigc++-2.0 --libs` `pkg-config gstreamer-0.10 --libs` `pkg-config gstreamer-app-0.10 --libs` `pkg-config gstreamer-interfaces-0.10 --libs` `pkg-config gstreamer-rtp-0.10 --libs` `pkg-config glib-2.0 --libs` `pkg-config gtk+-2.0 --libs` -lX11 -ldl -lXext `pkg-config gdkmm-2.4 --libs` `pkg-config glib-2.0 --libs` `pkg-config gtkmm-2.4 --libs` `pkg-config ptlib --libs` `pkg-config opal --libs` -fexceptions -o"HHPVideoServer" ./HHPVideoCodec.o ./engine.o ./opal/GstEndPoint.o ./opal/Linux_GstEndPoint.o ./opal/opal-call-manager.o ./logging/log.o ./gui/HHPVideoCodecGui.o ./gui/misc.o ./framework/services.o ./StreamEngine/GSTMediaStream.o ./StreamEngine/HHPStreamingEndPoint.o ./StreamEngine/HHPStreamingProtocol.o ./StreamEngine/Linux_GstMediaStream.o ./SDKEngine/AudioSettings.o ./SDKEngine/CallSettings.o ./SDKEngine/ClientSocket.o ./SDKEngine/Communications.o ./SDKEngine/DeviceInfo.o ./SDKEngine/FileActions.o ./SDKEngine/MediaCodecs.o ./SDKEngine/NetworkSettings.o ./SDKEngine/OSDSettings.o ./SDKEngine/SDKEngine.o ./SDKEngine/SDKEngineCore.o ./SDKEngine/SIPAccount.o ./SDKEngine/ServerSocket.o ./SDKEngine/SessionScheduleDisplay.o ./SDKEngine/Socket.o ./SDKEngine/VideoInput.o ./DigitalIO/DigitalIOCore.o ./DigitalIO/DigitalInputEngine.o
./HHPVideoCodec.o: In function `HHPVideoCodec':
/home/jonathan/workspace/HHPVideoServer/Debug/../HHPVideoCodec.cc:9: undefined reference to `PProcess::PProcess(char const*, char const*, unsigned short, unsigned short, PProcess::CodeStatus, unsigned short, bool)'
/home/jonathan/workspace/HHPVideoServer/Debug/../HHPVideoCodec.cc:9: undefined reference to `PTimedMutex::PTimedMutex()'
/home/jonathan/workspace/HHPVideoServer/Debug/../HHPVideoCodec.cc:9: undefined reference to `PTimedMutex::PTimedMutex()'
/home/jonathan/workspace/HHPVideoServer/Debug/../HHPVideoCodec.cc:9: undefined reference to `PTimedMutex::~PTimedMutex()'
/home/jonathan/workspace/HHPVideoServer/Debug/../HHPVideoCodec.cc:9: undefined reference to `PProcess::~PProcess()'....
It goes on for thousands of lines, with an undefined reference for every lib.
The libraries (as output by pkg-config) should be listed after the .o files. The order of arguments to the linker matters.