Pergunta

I have BeagleBone Black with Ubuntu 12.04 (Precise Pangolin). I downloaded the OpenCV library from apt using the command:

sudo apt-get install -y libopencv-dev

This command installed required headers and libraries. Then I compiled my own program which is just showing a window with the following command:

gcc -I/usr/inlcude/ -I/usr/include/opencv2/ -L/usr/lib/ -lopencv_core -lopencv_highgui -lm opencv_test.c -o test

After some seconds it shows that it is unable to find a reference with 'lrint' and many more and at last showing the linking errors for cvNameWindow, cvShowImage, etc.

I think that this may be the problem of installed libraries. I downloaded the latest OpenCV Source, cross compiled the code provided on the OpenCV wiki with -DUSE_NEON=ON flags on my Ubuntu machine. I copied these headers and libraries into the extra partition which is ext4 formatted. Again I issued the follwing command:

gcc -I/usr/inlcude/ -I/media/misc/opencv/include/opencv/ -I/media/misc/opencv/include/ -L/usr/lib/ -L/media/misc/opencv/lib/ -lopencv_core -lopencv_highgui -lm opencv_test.c -o test

Note: /media/misc/ is the extra partition.

This command gives me the same output as earlier. Now I come to the point. Maybe I am not issuing the correct command.

Also I changed gcc to g++, and it gives me the errors like:

unable to find reference cvNamedWindow
unable to find reference cvShowImage

etc.

Foi útil?

Solução 2

I accidentally compiled the sample code given in the OpenCV tarball, and that code compiled. Then I looked into the build script, and I found the following command:

g++ `pkg-config --cflags opencv` $1 -o $2 `pkg-config --libs opencv`

It is actually a script. $1 is the first argument, that is a .cpp file, and $2 is the second which is the output file. I use this script as follow:

./build_cv.sh opencv_test.cpp test

Note: make sure the script file "build_cv.sh" has execute permission. If not, then change its permission by typing:

chmod +x build_cv.sh

Now the problem. I was giving the location of header file and libraries in the first attempt. I have to give the location of headers before giving the source file, and location of the libraries after the output file. This is my experience; maybe some other guy have another way of compiling the code.

Outras dicas

Your link command has: -lopencv_core -lopencv_highgui -lm opencv_test.c

This is the wrong order of arguments. To understand why, read this.

If I give this command to my existing ubuntu x82 machine, It compiles very nicely...

You mean "it links very nicely".

That's happening by coincidence, not because your link command is correct.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top