Ask Your Question

After installing OpenCV, I can't compile any program, g++ gives errors (e.g g++: error: pthread: No such file or directory). Please help!

asked 2013-08-24 06:23:37 -0600

SreudianFlip gravatar image

updated 2013-08-26 02:03:36 -0600

After cloning the source, I followed the instructions on the website to the letter, but on compiling any of the programs that worked fine with OpenCV 2.4.5 with this command:

g++ -ggdb 'pkg-config --cflags opencv' main.cpp 'pkg-config --libs opencv'

, I receive this:

g++: error: rt: No such file or directory
g++: error: pthread: No such file or directory
g++: error: m: No such file or directory
g++: error: dl: No such file or directory

Please help, I'm a beginner here and I really need the intersection and chi^2 kernels for SVMS that aren't in the previous version. If there's any way to use those in the older version, I'd be grateful. Thanks!

edit retag flag offensive close merge delete


Small remark. We suggest not to use hashtags in the tags of your topic. They generate a lot of double tags, rendering the search and filter options useless. Keep this in mind at your next post, adjusted it for you now.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-26 02:17:42 -0600 )edit

3 answers

Sort by ยป oldest newest most voted

answered 2013-08-24 15:29:41 -0600

berak gravatar image

since you're trying to work with the master version, maybe it's a good idea to generate your makefile / proj with cmake in the same way you built the libraries before.

this will saving you the trouble of manually adjusting changed linker settings, include paths, etc.

whenever something changes(and things change fast!), you woud just run cmake again.

a simple CmakeLists.txt file will do:

cmake_minimum_required (VERSION 2.6) 


PROJECT(MyProject) # change this! (project_name)
    main.cpp       # change this! (src files)
edit flag offensive delete link more


Just for clarification, for the field "${OpenCV_LIBS}", would I put in the path to where I have the opencv library installed (ex. /usr/local/include)?

potatoprogrammer gravatar imagepotatoprogrammer ( 2014-09-08 01:51:59 -0600 )edit

answered 2013-10-06 14:25:50 -0600

Can you take a look at [source_dir]/release/unix-install/opencv.pc ?

When I call cmake on my machine, the .pc file is generated badly - the Libs: field ends with: rt pthread m dl, presumably it should end with -lrt -lpthread -lm -ldl.

Building any opencv projects with pkg-config, I got the same error that you do, and the error is fixed by making the appropriate change to opencv.pc.

(NB - of course pkg-config doesn't look in [source_dir]/build/unix-install for opencv.pc. If you want to do a quick test of changing the .pc file and recompiling your application, make sure you're editing the opencv.pc in /usr/lib/pkgconfig or /usr/local/lib/pkgconfig)

edit flag offensive delete link more

answered 2013-08-24 14:08:31 -0600

mviljamaa gravatar image
edit flag offensive delete link more

Question Tools


Asked: 2013-08-24 06:23:37 -0600

Seen: 2,900 times

Last updated: Oct 06 '13