3

I am new with R-pi. I need to use picam. While working with cpp, i came to know there are already different API for this. I am using an API link here: http://www.uco.es/investiga/grupos/ava/node/40 . Has anyone used it before because i am not able to run my program even while using cmake, like:

#

cmake_minimum_required (VERSION 2.8) project (project_name) find_package(path_to_raspicam REQUIRED) add_executable (project project.cpp)
target_link_libraries (project ${raspicam_LIBS})

###############################.

Also if i am going to use gcc command like:

g++ project.cpp -o project -I/usr/local/include -lraspicam -lmmal -lmmal_core -lmmal_util

there is not anything like "-I/usr/local/include -lraspicam -lmmal -lmmal_core -lmmal_util"

Please tell me how to include the library and make executable file. Thanks in advance.

2
  • Did you compile the API/library ? Were there any errors ? What do you mean by there is not anything like "-I/usr/local/include -lraspicam -lmmal -lmmal_core -lmmal_util" ? What output / errors do you get when trying to compile ? Commented Jul 24, 2016 at 10:35
  • sorry for incomplete post. Actually there is no such thing like -lmmal etc in /usr/local. Terminal also showed the error of non-existence.
    – dp01
    Commented Jul 24, 2016 at 14:20

2 Answers 2

3

I downloaded the API, compiled it as per the instructions on this page. I then used the sample app code (on the same page) and tried to compile it as per their instructions with :

g++ simpletest_raspicam.cpp -o simpletest_raspicam -I/usr/local/include -lraspicam -lmmal -lmmal_core -lmmal_util

This gave me errors as follows:

/usr/bin/ld: cannot find -lmmal
/usr/bin/ld: cannot find -lmmal-core
/usr/bin/ld: cannot find -lmmal_util
collect2: error: ld returned 1 exit status

Google found me this page which suggests adding a hint for the linker to where the mmal libraries are, like this:

-L/opt/vc/lib

I added that to my compiling command to make it:

g++ simpletest_raspicam.cpp -o simpletest_raspicam -I/usr/local/include -L/opt/vc/lib -lraspicam -lmmal -lmmal_core -lmmal_util

... and it compiled successfully.

2

there is not anything like "-I/usr/local/include -lraspicam -lmmal -lmmal_core -lmmal_util"

As KennetRunner points out this is because those libraries aren't in the linker's default path. It is worth mentioning that there are two of these to consider, the linker used at compile time and the shared object linker used at runtime if there are shared libraries linked (which there usually are).

The paths searched by the compile time linker are essentially hardcoded into it, so you need to explicitly use -L/opt/vc/lib.

You then need to make sure the runtime linker can find the relevant libraries. To add a path for that:

sudo bash echo /opt/vc/lib/ > /etc/ld.so.conf.d/opt-vc.conf

Then run sudo ldconfig to update the linker cache, and to verify,

sudo ldconfig -p | grep mmal 

(see man ldconfig about -p). You should see a few lines about those libraries.

If the base C includes are useful too (in addition to those of the C++ wrapper library in /usr/local/include), those won't be in the compiler's default path, so you could use -I /opt/vc/include or else add to your environment:

CPLUS_INCLUDE_PATH=/opt/vc/include

If you already have such a path set you can expand it the way you would expand the ordinary path variable (e.g. CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/opt/vc/include).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.