As an example, we will create camcv, a soft strongly inspired from raspistill. It will allow us later to modify source code and play with OpenCV.
- create a new folder in your home directory and copy all raspicam apps source code.
cd
mkdir camcv
cd camcv
cp /opt/vc/userland/host_applications/linux/apps/raspicam/* .
mv RaspiStill.c camcv.c
Perhaps a chmod is necessary (sudo chmod 777 camcv.c)
2. remove then content of CMakeLists.txt and replace with :
cmake_minimum_required(VERSION 2.8)
project( camcv )
SET(COMPILE_DEFINITIONS -Werror)
include_directories(/opt/vc/userland/host_applications/linux/libs/bcm_host/include)
include_directories(/opt/vc/userland/interface/vcos)
include_directories(/opt/vc/userland)
include_directories(/opt/vc/userland/interface/vcos/pthreads)
include_directories(/opt/vc/userland/interface/vmcs_host/linux)
add_executable(camcv RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv.c)
target_link_libraries(camcv /opt/vc/lib/libmmal_core.so /opt/vc/lib/libmmal_util.so /opt/vc/lib/libmmal_vc_client.so /opt/vc/lib/libvcos.so /opt/vc/lib/libbcm_host.so )
3. delete CMakeFiles directory if it exits
4. Compile & test
cmake .
make
./camcv -t 1000
5. [optional] Clean file. camcv.c is a long file with a lot of useless lines for us. All these following function could be delete (or commented). Remove of course all call to these functions in the remaining code.
static void dump_status(RASPISTILL_STATE *state)
static int parse_cmdline(int argc, const char **argv, RASPISTILL_STATE *state)
static void display_valid_parameters()
static MMAL_STATUS_T add_exif_tag(RASPISTILL_STATE *state, const char *exif_tag)
static void add_exif_tags(RASPISTILL_STATE *state)
static void store_exif_tag(RASPISTILL_STATE *state, const char *exif_tag)
The existing line default_status(&state); avoid you to parse command line using defaults parameters. Just add a line after this one :
state.filename=”foobar.jpg”;
Recompile and retest. Should work.
At this stage you should watch an old good movie with John Wayne.
Hi, anybody has the solution for this problema??
root@raspberrypi:/home/camcv# make
Scanning dependencies of target camcv
[ 20%] Building C object CMakeFiles/camcv.dir/RaspiCamControl.c.o
[ 40%] Building C object CMakeFiles/camcv.dir/RaspiCLI.c.o
[ 60%] Building C object CMakeFiles/camcv.dir/RaspiPreview.c.o
[ 80%] Building C object CMakeFiles/camcv.dir/camcv.c.o
[100%] Linking C executable camcv
/usr/bin/ld: CMakeFiles/camcv.dir/camcv.c.o: undefined reference to symbol ‘sem_post@@GLIBC_2.4’
//lib/arm-linux-gnueabihf/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/camcv.dir/build.make:177: recipe for target ‘camcv’ failed
make[2]: *** [camcv] Error 1
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/camcv.dir/all’ failed
make[1]: *** [CMakeFiles/camcv.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: *** [all] Error 2
root@raspberrypi:/home/camcv#
I did the next step…
1) I copied this CMakefilelists.txt:
# raspistill/raspivid/raspiyuv
cmake_minimum_required(VERSION 2.8)
project( camcv )
SET(COMPILE_DEFINITIONS -Werror)
include_directories(/opt/vc/userland/host_applications/linux/libs/bcm_host/include)
include_directories(/opt/vc/userland/interface/vcos)
include_directories(/opt/vc/userland)
include_directories(/opt/vc/userland/interface/vcos/pthreads)
include_directories(/opt/vc/userland/interface/vmcs_host/linux)
add_executable(camcv RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv.c)
target_link_libraries(camcv /opt/vc/lib/libmmal_core.so /opt/vc/lib/libmmal_util.so /opt/vc/lib/libmmal_vc_client.so /opt/vc/lib/libvcos.so /opt/vc/lib/libbcm_host.so )
2) I Modified the next lines from the file RaspiTex.h
#include
#include
#include
#include
and still have the problem
Thanks!
the values of the #includes are:
“opt/vc/include/EGL/egl.h”
“opt/vc/include/EGL/eglext.h”
“opt/vc/include/GLES/gl.h”
“opt/vc/include/GLES/glext.h”
add “pthread” to target_link_libraries
how to do ?
Just an FYI, this is my CMakeLists.txt to get things compiling with a fresh install of everything on a Pi 3 B as of the date of this post. Using the PiCam 2 as I go forward with this.
I had to add a bunch of things to the include directories, executables, and link libraries. Oh, and I think I needed to install OpenGL libraries (mesa).
==================================
cmake_minimum_required(VERSION 2.8)
project( mirrorcamcv )
SET(COMPILE_DEFINITIONS -Werror)
include_directories(/opt/vc/userland-master/host_applications/linux/libs/bcm_host/include)
include_directories(/opt/vc/userland-master/host_applications/linux/libs/sm)
include_directories(/opt/vc/userland-master/interface/vcos)
include_directories(/opt/vc/userland-master)
include_directories(/opt/vc/include)
include_directories(/opt/vc/userland-master/interface/vcos/pthreads)
include_directories(/opt/vc/userland-master/interface/vmcs_host/linux)
include_directories(/opt/vc/include/GLES)
include_directories(/opt/vc/include/GLES2)
include_directories(/home/pi/mirrorcamcv)
add_executable(mirrorcamcv RaspiCamControl.c RaspiCLI.c RaspiPreview.c gl_scenes/square.c gl_scenes/mirror.c gl_scenes/models.c gl_scenes/teapot.c gl_scenes/yuv.c gl_scenes/sobel.c gl_scenes/vcsm_square.c tga.c RaspiTexUtil.c RaspiTex.c mirrorcamcv.c)
target_link_libraries(mirrorcamcv /usr/lib/arm-linux-gnueabihf/libm.so /opt/vc/lib/libmmal_core.so /opt/vc/lib/libmmal_util.so /opt/vc/lib/libmmal_vc_client.so /opt/vc/lib/libvcos.so /opt/vc/lib/libbcm_host.so /opt/vc/lib/libvcsm.so /opt/vc/lib/libGLESv2.so /opt/vc/lib/libGLESv1_CM.so /opt/vc/lib/libEGL.so pthread)
Hello, did you complete this step successfully?
I was able to compile using your CMakeLists.txt
I just had to change “mirrocamcv” to “camcv”, as that was the name of my file and project.
Thank you for sharing.
I tried that (changing all occurrences of mirrorcamcv to camcv, but assuming scenes/mirror.c should remain) and I got
No such file or directory
#include “RaspiTexUtil.h”
I can’t help wondering whether modifying the out-of-the-box CMakeLists.txt would be a more robust approach, deleting what’s not needed and renaming what is, where necessary, but I don’t have the necessary familiarity with either cmake or the code structure to attempt it without a lot of research.
@pleriche
RGJ2’s version of CMakeLists worked perfect for me. Please be aware of this line:
include_directories(/home/pi/mirrorcamcv)
RGJ2 has built his project under another directory. Change this line into
include_directories(/opt/vc/userland-master/mirrorcamcv)
And it should work.
Hey there, this is how my CMakeLists.txt looks:
cmake_minimum_required(VERSION 2.8)
project( camcv )
SET(COMPILE_DEFINITIONS -Werror)
include_directories(/opt/vc/userland/host_applications/linux/libs/bcm_host/include)
include_directories(/opt/vc/userland/interface/vcos)
include_directories(/opt/vc/userland)
include_directories(/opt/vc/userland/interface/vcos/pthreads)
include_directories(/opt/vc/userland/interface/vmcs_host/linux)
include_directories(/opt/vc/userland/host_applications/linux/libs/sm)
include_directories(/opt/vc/include/GLES)
include_directories(/opt/vc/include/GLES2)
include_directories(/opt/vc/include)
include_directories(/home/pi/camcv)
add_executable(camcv RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv.c RaspiTexUtil.c RaspiTex.c gl_scenes/square.c gl_scenes/mirror.c gl_scenes/models.c gl_scenes/teapot.c gl_scenes/yuv.c gl_scenes/sobel.c gl_scenes/vcsm_square.c tga.c)
target_link_libraries(camcv /opt/vc/lib/libmmal_core.so /opt/vc/lib/libmmal_util.so /opt/vc/lib/libmmal_vc_client.so /opt/vc/lib/libvcos.so /opt/vc/lib/libbcm_host.so /opt/vc/lib/libGLESv2.so /opt/vc/lib/libGLESv1_CM.so /opt/vc/lib/libEGL.so /opt/vc/userland/build/lib/libvcsm.so pthread m)
This is exactly how my CMakeList.txt looks like. However, when I type in the command line cmake . I get the following error “CMake Erro at CMakeLists.txt:14 (add-executable): Cannot finf source file gl_scenes.quare.c”
Any ideas how to solve this?
Like everyone else round here I’ve been through innumerable versions of CMakeLists.txt and finally decided to cut to the end of the comments and try the latest and greatest, from Javier 26Jan 2017.
I now get:
CMake Warning at CMakeLists.txt:14 (add_executable):
Cannot generate a safe runtime search path for target camcv because there
is a cycle in the constraint graph:
dir 0 is [/opt/vc/lib]
dir 1 must precede it due to runtime library [libvcsm.so]
dir 1 is [/opt/vc/userland/build/lib]
dir 0 must precede it due to runtime library [libmmal_core.so]
Some of these libraries may not be found correctly.
Since it only flagged it as a Warning I went for broke with a make but got:
RaspiTex.h: No such file or directory
I’ve no idea what’s going on. Can anyone help?
By the way, I’m running under Raspbian Jessie. This has been going on so long I’m sure at least some of the earlier folks must have been using Wheezy.
Finally I made it to taking the picture ‘once.’ The foobar.jpg did appear. Then it would not take the same pic again. I recompiled everything … few times. No luck.
Anyone can help?
any idea
CMakeFiles/camcv.dir/camcv.c.o: In function `default_status’:
camcv.c:(.text+0x590): undefined reference to `raspitex_set_defaults’
CMakeFiles/camcv.dir/camcv.c.o: In function `parse_cmdline’:
camcv.c:(.text+0x1598): undefined reference to `raspitex_parse_cmdline’
CMakeFiles/camcv.dir/camcv.c.o: In function `display_valid_parameters’:
camcv.c:(.text+0x17c0): undefined reference to `raspitex_display_help’
CMakeFiles/camcv.dir/camcv.c.o: In function `create_camera_component’:
camcv.c:(.text+0x2428): undefined reference to `raspitex_configure_preview_port’
CMakeFiles/camcv.dir/camcv.c.o: In function `main’:
camcv.c:(.text+0x3938): undefined reference to `raspitex_init’
camcv.c:(.text+0x3c6c): undefined reference to `raspitex_start’
camcv.c:(.text+0x3fec): undefined reference to `raspitex_capture’
camcv.c:(.text+0x449c): undefined reference to `raspitex_stop’
camcv.c:(.text+0x44b4): undefined reference to `raspitex_destroy’
collect2: error: ld returned 1 exit status
CMakeFiles/camcv.dir/build.make:182: recipe for target ‘camcv’ failed
make[2]: *** [camcv] Error 1
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/camcv.dir/all’ failed
make[1]: *** [CMakeFiles/camcv.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: *** [all] Error 2
I finally got it to make (now to test it) When copying the files from userland/host_applications/linux/apps/raspicam/* make sure you use cp -r to include copying the files in gl_scenes as well
why I am getting this error?
pi@raspberrypi:~/camcv $ make
[ 20%] Linking C executable camcv
/usr/bin/ld: CMakeFiles/camcv.dir/camcv.c.o: undefined reference to symbol ‘sem_post@@GLIBC_2.4’
//lib/arm-linux-gnueabihf/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/camcv.dir/build.make:177: recipe for target ‘camcv’ failed
make[2]: *** [camcv] Error 1
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/camcv.dir/all’ failed
make[1]: *** [CMakeFiles/camcv.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: *** [all] Error 2
hi Javier
i tried your code and it showd an error like this:
No rule to make target ‘/opt/vc/userland/build/lib/libvcsm.so’, needed by ‘camcv’. Stop.
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/camcv.dir/all’ failed
make[1]: *** [CMakeFiles/camcv.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
can you please help me out????
I gave up on all this when I discovered that Raspbian Jessie has done it all for you – you can just install OpenCV as a package. With that, I got the Adafruit face-follower working in no time.
I met below error
make[2]: *** No rule to make target ‘/opt/vc/lib/libGLESv2.so’, needed by ‘camcv’. Stop.
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/camcv.dir/all’ failed
make[1]: *** [CMakeFiles/camcv.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: *** [all] Error 2
My OS version is Rasbian STRETCH
I searching file but I can’t
when i do 4 step,I got the error :
pi@raspberrypi:~/camcv $ make
Scanning dependencies of target camcv
[ 20%] Building C object CMakeFiles/camcv.dir/RaspiCamControl.c.o
/home/pi/camcv/RaspiCamControl.c:33:33: fatal error: interface/vcos/vcos.h: No such file or directory
#include “interface/vcos/vcos.h”
^
compilation terminated.
CMakeFiles/camcv.dir/build.make:62: recipe for target ‘CMakeFiles/camcv.dir/RaspiCamControl.c.o’ failed
make[2]: *** [CMakeFiles/camcv.dir/RaspiCamControl.c.o] Error 1
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/camcv.dir/all’ failed
make[1]: *** [CMakeFiles/camcv.dir/all] Error 2
Makefile:83: recipe for target ‘all’ failed
make: *** [all] Error 2
Any ideas how to solve this?
thx.
Hey guys, I am having trouble on the first step. I try to run cp /opt/vc/userland/host_applications/linux/apps/raspicam/* .
mv RaspiStill.c camcv.c and first got cp: target ‘camcv.c’ is not a directory. I tried just camcv, same thing. I left the camcv directory I had already made and tried again and got cp cannot stat cp /opt/vc/userland/host_applications/linux/apps/raspicam/* .no such file or directory
cp cannnot stat .mv no such file or directory
cp cannot stat raspistill no such file or directory, I understrand i dont have RaspiStilll.c, i kept getting no file or directory. I am using an RPI 3, and yes, I followed to the files directory and there is a RaspiStill.c file in the raspicam folder. What is wrong???
Hello,
when I run the “cp / opt / vc / userland / host_applications / linux / apps / raspicam / *” command, I have the following problem:
cp: missing destination file operand after ‘/ opt / vc / userland / host_applications / linux / apps / raspicam / *’
Try ‘cp –help’ for more information.
Help: What is missing?