error LNK2019: unresolved external symbol _ Open CV program - opencv

I am learning open CV and for the same i was trying few programs.
I am referring to this link.
http://docs.opencv.org/modules/contrib/doc/facerec/tutorial/facerec_gender_classification.html
I am using visual studio 10 to run the same, and i think somewhere i have messed up with some configuration.
I am facing the same problem in couple of more programs (picked from same source) ,
The error which i get is as follows:-
1>main.obj : error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey#cv##YAHH#Z) referenced in function __catch$_main$0
1>main.obj : error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::subspaceReconstruct(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputArray const &)" (?subspaceReconstruct#cv##YA?AVMat#1#ABV_InputArray#1#00#Z) referenced in function __catch$_main$0
..... (more such unresolved external symbol error)
1>main.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall cv::_InputArray::empty(void)const " (?empty#_InputArray#cv##UBE_NXZ)
1>c:\users\isenses\documents\visual studio 2010\Projects\gender_classification\Debug\gender_classification.exe : fatal error LNK1120: 37 unresolved externals
1>
1>Build FAILED.
1>Time Elapsed 00:00:00.36
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
My Project Properties are as follows:-
Properties->Configuration Properties ->Debugging->command arguments->C:\Users\isenses\Documents\Visual Studio 2010\Projects\gender_classification\csv.txt
Properties->Configuration Properties ->VC++ directories->Include directories->(added C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib
&
C:\openCV_2.4\opencv\build\x86\vc10\lib)
C/C++->general->additional include directories (added include path of openCV ie:-
C:\openCV_2.4\opencv\build
Linker->General---
Enable incremental linking=no
Additional Library directories=C:\Program Files %28x86%29\Microsoft Visual Studio 10.0\VC\lib
C:\openCV_2.4\opencv\build\x86\vc10
linker->System---SubSystem= /SUBSYSTEM:CONSOLE
Linker->Input---
additional dependencies=
wsock32.lib
opencv_contrib2411d.lib
opencv_calib3d2411d.lib
opencv_ml2411d.lib
opencv_objdetect2411d.lib
Thank you.

Thanks to #miki i was able to build the file successfully.
The solution to my problem was:-
adding proper additional Dependencies in properties->linker->input.
Adding libraries path in windows environment variables.
I had not used proper additional dependencies as pointed by #miki and as quoted by him "well you also have to link opencv_coreXXX,opencv_highguiXXX, opencv_imgprocXXX etc... (with trailing "d" if in debug) in your Linker->Input--- additional dependencies"
Thanks again

I want to add an answer to this because I feel the documentation on the opencv site needs to be updated. I followed the tutorial and could not get the library to link. After many permutations I decided to look at the .lib files. My problem was quite simple. The lib files in the opencv tutorial are not complete. Specifically my lib directory includes three more lib files. I added three extra lib files to visual studio linker and the external symbol problem was solved.
I am unsure why this is the case because I was only trying to use functions contained within the core module. Anyway, hopefully this will help someone.
I am using opencv 3 and visual studio 2017.

Related

How to link luajit to c++ dll program?

This is similiar topic to this one: How to link LuaJIT with a C++ program?
I've done all the same steps he did in that topic to install luajit..
I added luajit to my project like this:
Additional Library Directiories: C:\Documents\LuaJIT-2.1.0-beta3\src
Additional Include Directiories: C:\Documents\LuaJIT-2.1.0-beta3\src
And even added this #pragma comment(lib, "lua51.lib")
and for him this worked to get rid of the linker errors. Yet still im getting these errors:
1>Clua.obj : error LNK2001: unresolved external symbol _luaopen_jit
1>Clua.obj : error LNK2001: unresolved external symbol _luaopen_ffi
1>Clua.obj : error LNK2001: unresolved external symbol _luaopen_bit
1>Clua.obj : error LNK2001: unresolved external symbol _luaJIT_setmode

How to fix Unresolved external from FILE2.0?

I have some HDF5 C code that I am trying to port to C++Builder. I am getting this error at build time:
[ilink64 Error] Error: Unresolved external 'H5check_version' referenced from D:\DELPHITOOLS\PASHDF\C\WIN64\DEBUG\FILE2.O
H5check_version is included in H5public.h as a macro.
Why does C++Builder not find this?
H5check_version is included in H5public.h as a macro.
If that were true, you would not be getting a linker error, since macros are handled only during the preprocessor stage.
Somewhere in your project, the compiler is seeing a declaration of H5check_version as a function, and your file2 unit is calling it as a function, but the linker can't find the implementation of that function, hence the error.
Your project needs to contain a reference to the appropriate .lib file that either implements the actual function (static linking) or tells the linker which DLL the function is exported from (dynamic linking).
C/C++ is case sensitive, so H5check_version is different from H5Check_version.
AFAIK pascal is not case sensitive at all.
Regards

How to setup jpeglib with MS Visual C++ 2010 Express

I try to use the well known "jpeglib" now available in version 9.
Overview: I am a programming starter in C using MS Visual C++ 2010 Express and read a C-book finally. My goal is to compress a RGB(.bmp)-file into JPEG. So I downloaded the jpeglib (v9), read all the install and so on *.txt-files. It was possible to compile the C-files to get cjpeg.exe, djpeg.exe, jpeg.lib and so on.
After this success I tried to use the example.c to get deeper into the jpeg and to control the compression. -> It did not work. Then I tried to use the jpeglib included in OpenCV. Same non working result, while the OpenCV code samples are compiled successfully.
I googled lots of samples, problem solutions and tips how to use jpeglib. Most helpful information I found here. But in the result I was still not able to compile my own jpeg-tool or example.c (rewriting the write_JPEG_file() function ).
Question: What in the basics could be wrong, when every other programmer just uses #include "jpeglib.h" in their codes to run the jpeg functions successfully? For me including this file seems not to be enough. Because of that I have to ask you and to relaunch a one year old Question that also did not helped solving my probs. I can not give you a specific error message because of multiple attempts to solve those issues.
Here is my current MS-VC++2010 config for using OpenCV 2.4.6:
C/C++ -> General -> Additional Include Directories:
C:\opencv\build\include
C:\opencv\build\include\opencv
C:\opencv\build\include\opencv2
C:\opencv\include
C:\opencv\include\opencv
C:\opencv\include\opencv2
C:\opencv\3rdparty\libjpeg
Linker -> General -> Additional Library Directories:
C:\opencv\build\x86\vc10\lib
Linker -> Input -> Additional Dependencies:
opencv_core246d.lib
opencv_imgproc246d.lib
opencv_highgui246d.lib
opencv_ml246d.lib
opencv_video246d.lib
opencv_features2d246d.lib
opencv_calib3d246d.lib
opencv_objdetect246d.lib
opencv_contrib246d.lib
opencv_legacy246d.lib
opencv_flann246d.lib
jpeg.lib [this I added into C:\opencv\build\x86\vc10\lib]
At last some threads I have already read:
Compressing IplImage to JPEG using libjpeg in OpenCV - 1
Compressing IplImage to JPEG using libjpeg in OpenCV - 2
Need help in reading JPEG file using libjpeg
how can i use jpeg_mem_src, jpeg_mem_dest in libjpeg-turbo?
If there is something missing you want to know I will do my best to add this information!
EDIT - Some error messages:
1>jpeg_coder.obj : error LNK2001: unresolved external symbol ""unsigned char * image_buffer" (?image_buffer##3PAEA)".
1>jpeg_coder.obj : error LNK2001: unresolved external symbol ""int image_height" (?image_height##3HA)".
1>jpeg_coder.obj : error LNK2001: unresolved external symbol """int image_width" (?image_width##3HA)".
First symbol should be typedefed in jpeglib.h as JSAMPLE FAR *JSAMPROW,
second and third are defined in rdjpgcom.c as unsigned int image_height, image_width;
Maybe, with a lot of luck, I figured out what is need to be done to get jpeglib running. In the current state I have to check and double check whether my problem solution is correct or not. At this point thank you very much for your attention for my issues. As soon as I am sure with the solution I will post it.
Problem Solution: I did not setup OpenCV correctly for using jpeglib. The mistake I made was to link the wrong *.lib-file. The proper file for linking is libjpegd.lib. Too bad that jpeglib v6.2 is included in OpenCV 2.4.6 instead of v9. The hint to add HAVE_JPEG to use jpeglib functions inside OpenCV I ignored completely. For now the problem is solved.
Problem Solution: I did not setup OpenCV correctly for using jpeglib. The mistake I made was to link the wrong *.lib-file.
The proper file for linking is libjpegd.lib.
Too bad that jpeglib v6.2 is included in OpenCV 2.4.6 instead of v9. The hint to add HAVE_JPEG to use jpeglib functions inside OpenCV I ignored completely. Thanks to all who tried solving this issue. For now the problem is solved.

CAP_PROP_FRAME_WIDTH undeclared in 'How to build applications with OpenCV inside the Microsoft Visual Studio' sample code

I'm following the instructions in How to build applications with OpenCV inside the Microsoft Visual Studio but I'm getting errors from the sample code:
error C2065: 'CAP_PROP_FRAME_WIDTH' : undeclared identifier
error C2065: 'CAP_PROP_FRAME_HEIGHT' : undeclared identifier
error C2065: 'CAP_PROP_FRAME_COUNT' : undeclared identifier
I think the identifiers that are undeclared should be declared in highgui so why am I not getting them despite the demo code's #include <opencv2/highgui/highgui.hpp>?
Here are the steps I have taken.
I've unpacked the OpenCV (Version 2.4.6) files into C:\OpenCV, run setx -m OPENCV_DIR C:\OpenCV\Build\x64\vc11 from an elevated command prompt and added %OPENCV_DIR%\bin to my path (following instructions in Installation in Windows). Then using the Property pages (View -> Property Pages or Shift-F4) set to 'All Configurations'
I've added $(OPENCV_DIR)\..\..\include to my C/C++ Additional Include Directories
I've added $(OPENCV_DIR)\lib to the linker Additional Library Directories
I've cut-an-paste the directory listing of the lib files in C:\OpenCV\build\x64\vc11\lib into my input Additional Dependencies
I've copied the sample code from the article into a new C++ console app (with ATL). I had to change one line in the template code from int _tmain(int argc, _TCHAR* argv[]) to int _tmain(int argc, char* argv[])
I think the identifiers that are undeclared should be (are) declared in highgui so why am I not getting them despite the demo code's #include <opencv2/highgui/highgui.hpp>?
Other people having similar issues getting this sample code working in the How to build applications with OpenCV inside the Microsoft Visual Studio note seem to fall over with link errors (e.g. here and here) but I am getting past the linker.
========== EDIT ==========
There appear to be more insurmountable difficulties with the sample code. It is documented as a simple example to load and display an image whose path is supplied as the sole argument to main, while the code listing itself is video code requiring four command line arguments (i.e. it first checks and stops if argc != 5). I've submitted a documentation bug. I think the sample code listing should have been be taken from this: https://github.com/Itseez/opencv/blob/master/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp
Try with CV_CAP_ or cv::CAP_... It looks like there were some changes aiming to improve consistency of constants in OpenCV...
I am using the opencv 2.4.6 and this has helped me do the trick
change CAP_PROP_FRAME_WIDTH into CV_CAP_PROP_FRAME_WIDTH
change CAP_PROP_FRAME_HEIGHT into CV_CAP_PROP_FRAME_HEIGHT
change CAP_PROP_FRAME_COUNT into CV_CAP_PROP_FRAME_COUNT
and similarly if there are any other cap prop keywords into cv cap prop keywords
try this.

Cannot link a minimal Lua program

I have the following trivial Lua program which I copied from the book Programming In Lua
#include <stdio.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
int main (void)
{
char buff[256];
int error;
lua_State *L = luaL_newstate(); /* opens Lua */
luaL_openlibs(L); /* opens the standard libraries */
while (fgets(buff, sizeof(buff), stdin) != NULL)
{
error = luaL_loadbuffer(L, buff, strlen(buff), "line") ||
lua_pcall(L, 0, 0, 0);
if (error)
{
fprintf(stderr, "%s", lua_tostring(L, -1));
lua_pop(L, 1); /* pop error message from the stack */
}
}
lua_close(L);
return 0;
}
my environment is cywin
my make file looks like this:
CC=gcc
INCLUDE='-I/home/xyz/c_drive/Program Files/Lua/5.1/include'
LINKFLAGS='-L/home/xyz/c_drive/Program Files/Lua/5.1/lib' -llua51
li.o:li.c
$(CC) $(INCLUDE) -c li.c
main:li.o
$(CC) -o main $(LINKFLAGS) li.o
clean:
rm *.o
rm main
My /home/xyz/c_drive/Program Files/Lua/5.1/lib directory contains lua5.1.dll lua5.1.lib lua51.dll and lua51.lib
Trying to build my main target I am getting the following errors:
li.o:li.c:(.text+0x35): undefined reference to `_luaL_newstate'
li.o:li.c:(.text+0x49): undefined reference to `_luaL_openlibs'
li.o:li.c:(.text+0xaf): undefined reference to `_luaL_loadbuffer'
li.o:li.c:(.text+0xd9): undefined reference to `_lua_pcall'
li.o:li.c:(.text+0x120): undefined reference to `_lua_tolstring'
li.o:li.c:(.text+0x154): undefined reference to `_lua_settop'
li.o:li.c:(.text+0x167): undefined reference to `_lua_close'
Any ideas about what I might be doing wrong here?
The problem is that you have named the libraries on the link command line before the object files that require them. The linker loads modules from left to right on the command line. At the point on the line where you name -llua51, no undefined symbols that could be satisfied by that library are known. Then you name li.o, which does have unknown symbols.
Some Unix-like environments don't treat this as an error because part of the link process is deferred to the program load when reference to .so files are satisfied. But Cygwin, MinGW, and Windows in general must treat this as an error because DLLs work quite differently from .so files.
The solution is to put -llua51 after all the .o files on your link line.
Edit: Incidentally, it appears you are linking against the Lua for Windows distribution, but building with GCC under Cygwin. You will want to use Dependency Walker to make sure that your program does not depend on the Cygwin runtime, and that it does depend on the same C runtime as the lua51.dll from Lua for Windows. IIRC, that will be the runtime for the previous version of Visual Studio. It is possible to make GCC link against that, but you will need to be using the MinGW port (which you can use from Cygwin), and link against a couple of specific libraries to get that version. I'm away from my usual PC, or I'd quote an exact link line. (I believe you need -lmoldname -lmsvcr80 or something like that, as the last items on the link line.)
It will cause mysterious and very hard to diagnose problems if more than one C runtime library is in use. The easy answer is to use the same one as your preferred Lua DLL. Another alternative is that the Lua Binaries project has pre-compiled Lua DLLs for a wide array of C toolchains on Windows. If you need a Lua application that understands the Cygwin environment, you will want one that is built by GCC for Cygwin and not the Lua for Windows flavor. Lua Binaries will be your friend, or you can build Lua your self from source.
The names in the Lua API do not have those leading underscores. Try compiling with -fno-leading-underscore.

Resources