Sie sind auf Seite 1von 1

Products Customers Use cases Search… Log in Sign up

Home
compiling opencv in c++ Ask Question

PUBLIC Asked 8 years, 3 months ago Active 1 year, 2 months ago Viewed 60k times

Stack Overflow
i have a file with only import:
Tags The Overflow Blog

Users 23 #include <iostream> Introducing Collections on Stack Overflow


#include <stdio.h> for Teams
Jobs
#include "cxcore.hpp"
#include "highgui.hpp" A message from our CEO: The Way
TEAMS What’s this?
19 Forward
Free 30 Day Trial using namespace cv;
using namespace std; Featured on Meta

int main( int argc, char** argv )


{ Introducing the Moderator Council - and
its first, pro-tempore, representatives
}
CEO Blog: The Way Forward
and i try to compile with g++ -I/usr/include/opencv -lopencv -lm m.cpp
Triage needs to be fixed urgently, and
but get whit error: users need to be notified upon…

In file included from /usr/include/opencv/cxcore.hpp:46, from m.cpp:5: Question Close Updates: Phase 1
/usr/include/opencv/cxmisc.h:214: error: expected constructor, destructor, or type conversion
before ‘void’ /usr/include/opencv/cxmisc.h:220: error: expected constructor, destructor, or type
conversion before ‘int’ /usr/include/opencv/cxmisc.h:226: error: ‘CV_INLINE’ does not name a Related
type /usr/include/opencv/cxmisc.h:516: error: ‘CV_DEPTH_MAX’ was not declared in this
scope /usr/include/opencv/cxmisc.h:522: error: ‘CV_DEPTH_MAX’ was not declared in this 3245 What are the differences between a pointer

scope /usr/include/opencv/cxmisc.h:522: error: ‘CV_CN_MAX’ was not declared in this scope variable and a reference variable in C++?
In file included from m.cpp:5: /usr/include/opencv/cxcore.hpp:70: error: template declaration of 538 Why does C++ compilation take so long?
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy
‘cv::CV_EXPORTS cv::Size_’ /usr/include/opencv/cxcore.hpp:71: error: template declaration ofPolicy, and our Terms of Service.
‘cv::CV_EXPORTS cv::Point_’ /usr/include/opencv/cxcore.hpp:72: error: template declaration 1805 How can I profile C++ code running on
of ‘cv::CV_EXPORTS cv::Rect_’ /usr/include/opencv/cxcore.hpp:77: error: expected initializer Linux?
before ‘fromUtf16’ /usr/include/opencv/cxcore.hpp:78: error: expected initializer before ‘toUtf16’
4243 The Definitive C++ Book Guide and List
/usr/include/opencv/cxcore.hpp:80: error: expected initializer before ‘format’
/usr/include/opencv/cxcore.hpp:82: error: expected initializer before ‘:’ token m.cpp:38: error: 1611 What is the effect of extern “C” in C++?
expected ‘}’ at end of input
8873 What is the “-->” operator in C++?
this is my copencv lib content:
1561 Easiest way to convert int to string in C++

alberto@zefiro:~$ ls /usr/include/opencv/ 1823 Why is reading lines from stdin much


cvaux.h cvcompat.h cv.hpp cvtypes.h cvvidsurv.hpp cxcore.h cxerror.h cxmat slower in C++ than Python?
cvaux.hpp cv.h cvinternal.h cvver.h cvwimage.h cxcore.hpp cxflann.h cxmis
2 Error when compiling cv.h: No such file or
directory
i'm on ubuntu 10.10
1450 Compiling an application for use in highly
radioactive environments
c++ opencv image-processing compilation

Hot Network Questions


share improve this question follow edited Dec 19 '14 at 14:45 asked Feb 1 '12 at 11:22
What is the difference between salary and bonus
karlphillip nkint
with respect to taxes?
83.9k 29 211 371 9,561 28 85 154
Is it legal to completely retell a film in text?
add a comment
Reverse characters in alphabet

4 Answers Active Oldest Votes Interesting things you learned while grading?

Mowing the Grass


You need to properly include the headers -I (capital i) and libraries -l (lowercase L). Was there any automated unit testing prior to
1972?
On the newest OpenCV versions you should do:
55 What plane would an aboleth be from for the
purposes of Banishment?
#include <cv.h>
How can a rogue planet get energy for plants to
#include <highgui.h> use?

Why are there so many infantry battles in Star


And then try to compile it with: Wars?

Should LaTeX be taught in high school?


g++ m.cpp -o app `pkg-config --cflags --libs opencv`
A clothing material or other method to slow free-
fall descent down walls
Note: if you execute only pkg-config --cflags --libs opencv in the command line you will see
Parallelize GroupBy
the paths and libraries you need to include in the g++ command line.
How to deal with a GM who favors other players
share improve this answer follow answered Feb 1 '12 at 14:04
Is there a one-liner that allows me to create a
karlphillip directory and move into it at the same time?
83.9k 29 211 371
The connection of the "R" in the ideal gas law and
osmotic pressure
sigh. this do compile but remaind me at this problem stackoverflow.com/q/9088228/433685 – nkint Feb 1 Movie Where Time Until Weekend is Consistently
'12 at 16:45 Announced

I always forget the name of the pkg-config utility. Thanks for the simple solution! – aaronsnoswell Nov 28 '13 How is clear dialogue recorded in noisy scenes?
at 1:07
Find and replace last char '_' with '.' on filenames
Suppose I have an openCV version installed and built in a directory (the global version is different). How recursively
should I change the command you posted to compile and build my project with the new local version of Is there a bacterium that became a virus?
openCV? – Francesco Boi Aug 2 '18 at 12:46
How, and when, should I explain to potential
1 Execute pkg-config --cflags --libs opencv to see the exact parameters the global version passes to employers that I have a severe digestive disorder?
g++. Then, just copy the same flags and use your local paths instead. Simple! – karlphillip Aug 2 '18 at 21:45
Babylon 5 - Earth Alliance Presidential Powers
I installed 4.2 from source and had to do the following steps while building:
Connecting 10AWG wires to PCB
github.com/opencv/opencv/issues/13154#issuecomment-456652297 – stephen Jan 5 at 18:39
Is B♯ to F an impossible interval?
add a comment
SR-71 flew 2193 mph. How can this
mathematically be Mach 3.3?

if your development environment does not have pkg-config and because of this the accepted Question feed
answer by karlphilip is not practical, or, you need to know the minimal set of libraries required to
link your application, then assuming code such as
7
#include <cv.h>
#include <highgui.h>

int main()
{
return 0;
}

you can add library arguments from the following list sequentially from the top until you find the
minimal set of arguments that you need:

-lopencv_core
-lopencv_imgproc
-lopencv_highgui
-lopencv_ml
-lopencv_video
-lopencv_features2d
-lopencv_calib3d
-lopencv_objdetect
-lopencv_contrib
-lopencv_legacy
-lopencv_flann

For example, the C source code listed at the top of this post compiles and links cleanly with only

gcc hello.c -o hello \


-I /usr/include/opencv \
-L /usr/lib \
-lopencv_core \
-lopencv_imgproc

on my old x86_64 Ubuntu 12.04 box.

Assuming C++ code such as

#include "core/core.hpp"
#include "highgui/highgui.hpp"

using namespace cv;


using namespace std;

int main( int argc, char** argv )


{
return 0;
}

then you would compile and link with

g++ hello.cpp -o hello \


-I /usr/include/opencv2 \
-L /usr/lib \
-lopencv_core \
-lopencv_imgproc

share improve this answer follow edited May 23 '17 at 12:10 answered Aug 16 '16 at 11:49
Community ♦ Jonathan Ben-Avraham
1 1 3,404 1 25 31

I tried compiling the g++ version from this guy's video youtube.com/watch?v=cgo0UitHfp8 on the command
line because I wanted to try it without VS. It compiles, but when I run the program nothing happens. –
luckyging3r Feb 21 '17 at 4:00

Nevermind, It's a missing windows dll file problem. Thank you for your above answer though. – luckyging3r
Feb 21 '17 at 4:20

I need to add opencv_contrib but it is not in the package list as i can see it using the command pkg-config --
libs opencv. – user8038009 Sep 24 '17 at 8:52

add a comment

I suggest you use CMake to compile OpenCV with G++ , this way is more suitable, I think.

4 cmake_minimum_required(VERSION 3.1)
project(YOUR_PROJECT_NAME)

set(CMAKE_GXX_FLAGS "-Wall -Wextra -Wconversion -pedantic -std=gnu11")

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(YOUR_EXCUTABLE YOUR_CODE_SOURCE_FILES)
target_link_libraries(YOUR_EXCUTABLE ${OpenCV_LIBS})

share improve this answer follow answered Mar 6 '19 at 15:17


Sendjasni
563 6 23

With this cmake file I had to change the includes to " #include "opencv2/core/core.hpp" #include
"opencv2/highgui/highgui.hpp" – jjcf89 Aug 7 '19 at 21:45

@jjcf89 great, happy to help. The use of CMake is very suitable for compiling, you should really consider
using it. For me, it helped me a lot, and it's time saving too. – Sendjasni Nov 8 '19 at 14:08

add a comment

1. Download source files in OpenCV folder and install-opencv.sh script.


2. By running script file you automatically install needed files for opencv. Run the following code:
0
chmod +x install-opencv.sh
./install-opencv.sh

In case if you install different version of the library please update the first line of version inside the
installation script. For more information use this tutorial. Compile it with the next line:

g++ `pkg-config --cflags opencv` example.cpp `pkg-config --libs opencv`

share improve this answer follow edited Mar 7 '19 at 16:07 answered Mar 1 '19 at 22:11
Giorgi Gvimradze
300 4 15

add a comment

Your Answer

Sign up or log in Post as a guest


Name
Sign up using Google

Sign up using Facebook Email


Required, but never shown

Sign up using Email and Password

Post Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged c++ opencv image-processing

compilation or ask your own question.

STACK OVERFLOW PRODUCTS COMPANY STACK EXCHANGE Blog Facebook Twitter LinkedIn Instagram
NETWORK
Questions Teams About
Technology
Jobs Talent Press
Life / Arts
Developer Jobs Directory Advertising Work Here
Culture / Recreation
Salary Calculator Enterprise Legal
Science
Help Privacy Policy
Other
Mobile Contact Us site design / logo © 2020 Stack Exchange Inc; user contributions
licensed under cc by-sa 4.0 with attribution required.
Disable Responsiveness rev 2020.5.7.36779

Das könnte Ihnen auch gefallen