Ask Your Question
0

Unable to compile/link program after inclusion of opencv.hpp

asked 2015-10-08 04:35:20 -0600

elsanky gravatar image

updated 2015-10-08 05:38:29 -0600

berak gravatar image

I am trying to compile a program which uses opencv. I have included the opencv.hpp file in the .h and the .c file which needs the opencv functions. The project also has the properties set to use opencv. I am using 2.4.5 version of opencv. The problems I am facing is that after including these files in the project the project fails to compile. I get an error saying I have failed to #inlcude "stdafx.h". This is because I am using precompiled headers and #include"stdafx.h" has to be the first line of code in that .c or .cpp file. If I add the inclusion of stdafx.h tehn the program compiles but it does not link.

shown below is how i have included the files in the .c file.

#include "../stdafx.h"
#include "C:\opencv\include\opencv2\opencv.hpp"
#include "DPD_AlgorithmInit.h"

and shown below is the inclusion in the .h file
#include "C:\opencv\build\include\opencv2\core\types_c.h"

the error I am receiving is

error C1083: Cannot open source file: '..\MOSS\PedestrianDetection\DPD_Tracker.c': No such file or directory    C:\Users\sankalp\Desktop\check\MOSS_Evaluation\c1
error LNK2001: unresolved external symbol _InitializeTracker    C:\Users\sankalp\Desktop\check\MOSS\DPD_AlgorithmInit.obj
error LNK2001: unresolved external symbol _DPD_Tracker  C:\Users\sankalp\Desktop\check\MOSS\DPD_AlgorithmInit.obj
error LNK2001: unresolved external symbol "unsigned char * __cdecl DPD_Alloc(unsigned int)" (?DPD_Alloc@@YAPAEI@Z)  C:\Users\sankalp\Desktop\check\MOSS\DPD_Tracker1.obj
error LNK1120: 3 unresolved externals   C:\Users\sankalp\Desktop\check\Release\MOSS.exe

Am I doing something wrong while including the .hpp file? Is there a better way to include opencv to alllow compilation and linking?

edit retag flag offensive close merge delete

Comments

2

those are all linker errors, unrelated to c++ headers.

most likely, you forgot to add some cpp file to your project, try to find e.g. the implementation of InitializeTracker

then, just saying, opencv's c-api should no more be used, if you find a lot of IplImage* in that code, consider using something else instead.

berak gravatar imageberak ( 2015-10-08 05:42:11 -0600 )edit

Or you can start by translating it to the new C++ interface and commit it to the repository through a PR :D

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-08 06:10:55 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-10-12 23:06:03 -0600

elsanky gravatar image

Thanks berak and Steven Puttemans. The issue was resolved. The problem was that the the vcxproj file was not getting updated while i was including the new .h and .cpp file [dont know why]. So i copy pasted the contents of the new files into the older version in the older project and added stdafx as the first include file. This works fine now. The error was not due to the opencv headers as berak correctly pointed out.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-10-08 04:35:20 -0600

Seen: 377 times

Last updated: Oct 08 '15