OpenCV on ubuntu 11.10 - c++

I've just updated my system from ubuntu 11.04 to 11.10 and now I can't compile anymore any C program that contain references to OpenCV libraries
I've already tried to reinstall OpenCV (I use the 2.1 version) but I'm stuck with this error:
/tmp/ccArHTZL.o: In function `main':
z.c:(.text+0x59): undefined reference to `cvLoadImage'
z.c:(.text+0xa0): undefined reference to `cvNamedWindow'
z.c:(.text+0xb1): undefined reference to `cvShowImage'
z.c:(.text+0xbb): undefined reference to `cvWaitKey'
z.c:(.text+0xc5): undefined reference to `cvDestroyWindow'
z.c:(.text+0xd1): undefined reference to `cvReleaseImage'
collect2: ld returned 1 exit status
In order to install OpenCV I've always followed this procedure:
$ sudo apt-get install libcv2.1 libcv-dev libcvaux2.1 libcvaux-dev libhighgui2.1
libhighgui-dev opencv-doc python-opencv
$ export LD_LIBRARY_PATH=/home/opencv/lib
$ export PKG_CONFIG_PATH=/home/opencv/lib/pkgconfig
$ pkg-config --cflags opencv
-I/usr/include/opencv
$ pkg-config --libs opencv
-lcxcore -lcv -lhighgui -lcvaux -lml
$ g++ -I/usr/include/opencv -lcxcore -lhighgui -lm hello.c
Anyone can help me?

Why don't you use pkg-config to your favor?
g++ hello.c -o hello `pkg-config --cflags --libs opencv`

I think it is because of some changes from gcc 4.5 to gcc 4.6
Try this command instead (i.e., move the libraries to the end, instead of at the beginning of your command line) -- it works for me:
g++ -I/usr/include/opencv hello.c -lcxcore -lhighgui -lm

I'm still on kubuntu 10.10 so I'm not really familiar how does 11.10 work, but the most common answer to problems with not finding libraries is to use ldconfig with sudo. It'll refresh libraries database. If that doesn't help, look into /usr/lib, /usr/lib64 and /usr/lib32, because its the default place where apt-get throws libraries in. When you find the libraries, change the LD_LIBRARY_PATH so it contains the directory. I don't think that /home/opencv/lib is where they are, but i don't know Your environment

I just upgraded to 11.04 on my laptop and having similar issues. I would try building the latest version of OpenCV (2.3.1) and see if this fixes anything, this seemed to fix quite a few issues for me.

Use the following command, it worked for me:
gcc pkg-config --cflags opencv opencv.c -o open_cv pkg-config --libs opencv

Related

Installing Protobuf Development Libraries in MinGW

I installed Protobuf in MinGW from the sources on github.
When I try to compile my C++ program I get errors:
CMakeFiles/nxcore_interface.dir/main.cpp.o:main.cpp:(.rdata$.refptr._ZN6google8protobuf8internal13empty_string_E[.refptr._ZN6google8protobuf8internal13empty_string_E]+0x0): undefined reference to `google::protobuf::internal::empty_string_'
collect2: error: ld returned 1 exit status
I found something that indicates the development libs are not present:
Program with protocol-buffers don't compile with MinGW-w64: "undefined reference to google::protobuf:: ..."
I have included the -lprotobuf compiler flag.
After some searching I determined I need to use libprotobuf-dev but I am having trouble locating it.
Does anyone know where to get it, or is something else wrong?
You should compile your application with pkg-config.
g++ my_program.cpp `pkg-config --cflags --libs protobuf`
If you don't have pkg-config you should locate libraries path and set them with -L option. Eg:
g++ my_program.cpp -L/usr/local/protobuf/lib -lprotobuf

Compiling OpenGL program with GLFW3

I installed GLFW3 and am trying to compile my OpenGL program with the following:
g++ -std=c++11 main.cpp -lGL -lGLEW -lglfw3
But here's the library error I get:
/usr/bin/ld: cannot find -lglfw3
collect2: error: ld returned 1 exit status
I also tried with pkg-config:
g++ `pkg-config --cflags glfw3 glew` -o myprog main.cpp `pkg-config --static --libs glfw3 glew`
it compiles but when I run myprog it says it can't find libglfw.so.3
But it is located in /usr/local/lib
http://www.brandonfoltz.com/2012/12/compile-glfw-on-ubuntu-and-fix-libglfw-so-cannot-open-error/
Ubuntu installs libglfw.so.3 in /usr/local/lib so you have to add this line to /etc/ld.so.conf
I had the same problem.
In my case was usefull following steps:
Download glfw source code
unzip it
cd glfw_folder
cmake . (with dot)
make
sudo make install
To check, copy and paste following command in your console "whereis libglfw3".
you should have output like this one: "libglfw3: /usr/local/lib/libglfw3.a" (or another path after ":").
My config: VAIO Pro 13/Ubuntu 16.04 LTS/ Intel HD4000.
P.S.: Yes, I'd tryed "sudo apt-get install libglfw3" and all dependenses.

c++ undefined reference errors when trying to compile opengl project

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.

undefined reference to `DES_set_odd_parity'

gcc, Ubuntu.
Have done:
sudo apt-get install libssl-dev
Build with -lssl, but during linkage get error:
undefined reference to `DES_set_odd_parity'
?
EDITED:
g++ linear_des.cpp -lssl
DES_set_odd_parity is part of libcrypto so you should try linking that as well. Something on these lines:
g++ linear_des.cpp -lssl -lcrypto
Hope this helps!
PS: It might be a good idea to make use of pkg-config tool & compile something on these lines:
g++ linear_des.cpp $(pkg-config --cflags --libs openssl)

Linking errors when compiling code with OpenCV Libraries

I'm trying to compile a sample program after installing Opencv with the command:
g++ hello-world.cpp -o hello-world -I /usr/local/include/opencv -L /usr/local/lib -lm -lcv -lhighgui -lcvaux
however, I'm getting an error that says:
/usr/bin/ld: cannot find -lcv
/usr/bin/ld: cannot find -lhighgui
/uer/bin/ld: cannot find -lcvaux
collect2: ld returned 1 exit status
What do I need to do to correct this?? I installed opencv by downloading the latest stable version and using cmake to create the build files, then ran make install from the command line.
Was there anything I may have missed?
UPDATED-
Better use this command:
g++ opencv.cpp -o opencv -L `pkg-config --cflags --libs opencv`
The pkg-config command will locate the correct include and library for your source code.
For better handling with OpenCV programming go with an IDE like code::block.
Maybe this tutorial will help you in OpenCV programming with code::block:
How to Setup OpenCV for code :: block in Linux and Windows?
Recently I started using OpenCV and I got similar problem and for me this works really well:
-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect
Hope it will solve your problem.
You need to add another -L argument specifying the actual location of the OpenCV libraries.