Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 17/08/2015, à 14:19

riwa

compile and run basic opencv program in C in ubuntu

I have installed opencv in ubuntu 14.04 embedded version for ARM Soc. platforme Parallella. I tried OpenCV with gcc and CMake documentation to run a basic C program.

Iniatialy I need CmakeLists.txt and DiplayImage.cpp and I type cmake I received this error make: * No targets specified and no makefile found. Stop. So I added the makefile

   

 > linaro@linaro.nano:~/displayImage$ ls -l 
    >  w-rw-r-- l linaro linaro   1040 Jun 11 17:01 CmakeLists.txt 
    >  w-rw-r-- l linaro linaro     479 Jun 11 21:51 DisplayImage.cpp
    >  w-rw-r-- l linaro  linaro    171 Jun 11 21:39 DisplayImage.cpp~ 
    >  w-rw-r-- l linaro linaro     281 Jun 11 17:01 Makefile
    >  w-rw-r-- l linaro linaro 40274 Jun   3 10:36 p.png
    > 
    > linaro@linaro.nano:~/displayImage$ cmake 
    > cmake version 2.8.12.2
Usage

  cmake [options] <path-to-source>
  cmake [options] <path-to-existing-build>

Options
  -C <initial-cache>          = Pre-load a script to populate the cache.
  -D <var>:<type>=<value>     = Create a cmake cache entry.
  -U <globbing_expr>          = Remove matching entries from CMake cache.
  -G <generator-name>         = Specify a build system generator.
  -T <toolset-name>           = Specify toolset name if supported by
                                generator.
  -Wno-dev                    = Suppress developer warnings.
  -Wdev                       = Enable developer warnings.
  -E                          = CMake command mode.
  -i                          = Run in wizard mode.
  -L[A][h]                    = List non-advanced cached variables.
  --build <dir>               = Build a CMake-generated project binary tree.
  -N                          = View mode only.
  -P <file>                   = Process script mode.
  --find-package              = Run in pkg-config like mode.
  --graphviz=[file]           = Generate graphviz of dependencies, see
                                CMakeGraphVizOptions.cmake for more.
  --system-information [file] = Dump information about this system.
  --debug-trycompile          = Do not delete the try_compile build tree.
                                Only useful on one try_compile at a time.
  --debug-output              = Put cmake in a debug mode.
  --trace                     = Put cmake in trace mode.
  --warn-uninitialized        = Warn about uninitialized values.
  --warn-unused-vars          = Warn about unused variables.
  --no-warn-unused-cli        = Don't warn about command line options.
  --check-system-vars         = Find problems with variable usage in system
                                files.
  --help-command cmd [file]   = Print help for a single command and exit.
  --help-command-list [file]  = List available listfile commands and exit.
  --help-commands [file]      = Print help for all commands and exit.
  --help-compatcommands [file]= Print help for compatibility commands.
  --help-module module [file] = Print help for a single module and exit.
  --help-module-list [file]   = List available modules and exit.
  --help-modules [file]       = Print help for all modules and exit.
  --help-custom-modules [file]= Print help for all custom modules and exit.
  --help-policy cmp [file]    = Print help for a single policy and exit.
  --help-policies [file]      = Print help for all policies and exit.
  --help-property prop [file] = Print help for a single property and exit.
  --help-property-list [file] = List available properties and exit.
  --help-properties [file]    = Print help for all properties and exit.
  --help-variable var [file]  = Print help for a single variable and exit.
  --help-variable-list [file] = List documented variables and exit.
  --help-variables [file]     = Print help for all variables and exit.
  --copyright [file]          = Print the CMake copyright and exit.
  --help,-help,-usage,-h,-H,/?= Print usage information and exit.
  --help-full [file]          = Print full help and exit.
  --help-html [file]          = Print full help in HTML format.
  --help-man [file]           = Print full help as a UNIX man page and exit.
  --version,-version,/V [file]= Show program name/version banner and exit.

Generators

The following generators are available on this platform:
  Unix Makefiles              = Generates standard UNIX makefiles.
  Ninja                       = Generates build.ninja files (experimental).
  CodeBlocks - Ninja          = Generates CodeBlocks project files.
  CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
  Eclipse CDT4 - Ninja        = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Unix Makefiles
                              = Generates Eclipse CDT 4.0 project files.
  KDevelop3                   = Generates KDevelop 3 project files.
  KDevelop3 - Unix Makefiles  = Generates KDevelop 3 project files.
  Sublime Text 2 - Ninja      = Generates Sublime Text 2 project files.
  Sublime Text 2 - Unix Makefiles
                              = Generates Sublime Text 2 project files.

    > linaro@linaro.nano:~/displayImage$ make 
    > make: *** No rule to make target `example.o`, needed by `opencv_example`. Stop.
    > 
    > So I added example.o file that I found in old Cmake example folder that comes  when I install opencv library
    > 
    >  linaro@linaro.nano:~/displayImage$ make  
    >g++ example.o -o opencv_example -L/usr/local/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core -lopencv_hal -lpng -lz -ltiff -ljasper -ljpeg -lgthread-2.0 -lglib-2.0 -ldc1394 -ldl -lm -lpthread -lrt

I don't understand what is generated by make and why cmake needs example.o to work? How can I run simply my code?

Makefile contains:

CXX ?= g++

CXXFLAGS += -c -Wall $(shell pkg-config --cflags opencv)
LDFLAGS += $(shell pkg-config --libs --static opencv)

all: opencv_example

opencv_example: example.o; $(CXX) $< -o $@ $(LDFLAGS)

%.o: %.cpp; $(CXX) $< -o $@ $(CXXFLAGS)

clean: ; rm -f example.o opencv_example

CmakeLists.txt contain

# cmake needs this line
cmake_minimum_required(VERSION 2.8)

# Define project name
project(opencv_example_project)

# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")

if(CMAKE_VERSION VERSION_LESS "2.8.11")
  # Add OpenCV headers location to your include paths
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()

# Declare the executable target built from your sources
add_executable(opencv_example example.cpp)

# Link your application with OpenCV libraries
target_link_libraries(opencv_example ${OpenCV_LIBS})

Hors ligne

#2 Le 17/08/2015, à 14:37

louis94

Re : compile and run basic opencv program in C in ubuntu

Hello,

First, notice this is a French forum, and you should'nt post questions in English here (go to http://ubuntuforums.org/ or http://askubuntu.com/).

As for CMake, instead of running

cmake

run (notice the dot)

cmake .

This will generate the Makefile.

Even better, you can make an out-of-source build. Create a "build" directory:

mkdir build

Then cd to it:

cd build

And run cmake from there (two dots):

cmake ..

Louis

Hors ligne