OPENCV linking Error - Win32 & VS2012 - c++

i have build openCV 3.0.0 both alpha & beta versions. but everytime i run my project i get this Error only for "imread" function:
error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class cv::String const &,int)" (?imread#cv##YA?AVMat#1#ABVString#1#H#Z) referenced in function _main ...
Here's my code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdlib.h>
#include <stdio.h>
using namespace cv;
int main()
{
Mat a=Mat::zeros(10,10,0);
Mat b;
b=imread("Mu.jpg");
imshow("s",a);
waitKey(1000);
}
when i remove the "imread" function it works fine. builds and runs with no errors and displays the little black image (from "A" Matrix)
I have Re-Build the solutions & OpenCV from scratch and still getting this error.
I'm working with VS2012 and i have added the include & lib paths in a property sheet for the project.
Can anyone help with this?

imread function has been moved to imgcodecs library so you have to include it :
For MSVC users : add "opencv_imgcodecs300d.lib" to "configuration properties-> Linker->Input->Aditional Dependencies" and include "#include "
For Qt users : For Qt IDE users add -lopencv_imgcodecs300d or -lopencv_imgcodecs300 to your .pro file
and #include <opencv2/imgcodecs/imgcodecs.hpp> to your main file
note: the number 300 in the lib name should be changed to match OpenCV version used.

This unresolved external symbol linker errors basically arrives when the compiler is not able to get the definition of that function which is declared.
So make sure you have defined imread("Mu.jpg"){} somewhere in your code and then try compiling the same.
Check whether you have linked the libraries properly and also link may be useful if you are using opencv2.2.

Related

Linker error _SDL_main unresolved in _main_getcmdline [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 4 years ago.
I'm following LazyFoo's tutorial for SDL2. I went through the first ten lessons, and now i'm getting this error (until i compile i don't get any errors from VS).
1>------ Inizio compilazione: Progetto: yetANewSDLProj, Configurazione: Debug Win32 ------
1>SDL2main.lib(SDL_windows_main.obj) : error LNK2019: riferimento al simbolo esterno _SDL_main non risolto nella funzione _main_getcmdline
1>Compilazione progetto "yetANewSDLProj.vcxproj" NON COMPLETATA.
========== Compilazione: 0 completate, 1 non riuscite, 0 aggiornate, 0 ignorate ==========
"Reference to external symbol "_SDL_main" unresolved in the function "_SDL_getcmdline"
It seems to me that the error is not in my code but rather between SDL's files but i can't figure out which file supposedly Visual Studio doesn't find or why.
I created a new empty project, the only code i have (one file, main.cpp) is:
#include <SDL.h>
#include <SDL_image.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cmath>
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_VIDEO);
while(1){}
SDL_Quit();
return 0;
}
The include files are in the path: "C:\vs_dev_lib\include"
The DLL/lib files: "C:\vs_dev_lib\lib\x86"
Both paths are inserted in "VC++ Directories" (Include Directories / Library Directories).
I also copied all DLLs in both System32 and SysWOW64.
I also tried copying DLLs and .lib file in my project directory.
The headers, dll and lib files are from SDL2, SDL2 image, Mixer and TTF (in all cases development libraries for windows (Visual C++ 32/64-bit).
Linker/Input/Additional Denpendencies look like this:
SDL2.lib
SDL2main.lib
SDL2_image.lib
SDL2_ttf.lib
SDL2_mixer.lib
Linker/System/Subsystem is set to "Console(/SUBSYSTEM:CONSOLE)"
Character set is "Multibyte character set" (translated, not sure how exactly it's spelled in english).
Thanks in advance, if you need any other info let me know.
Googling didn't bring me any luck, i've been stuck with this for the past two days :/
Try defining #define SDL_MAIN_HANDLED prior to including sdl headers if you are going to manually provide an entry point.
#define SDL_MAIN_HANDLED
#include "SDL.h"
int main(int argc, char *argv[])
{
SDL_SetMainReady();
SDL_Init(SDL_INIT_VIDEO);
...

Protobuf - Refuses to link vs2013 or vs2015

As the title states I cannot get protobuf to link successfully.
Here is the small test program. note the AddressBook class was generated usin gthe protoc compiler that was built when i compiled protobuf.Additionally, this proto file is part of googles protobuf examples that is included with the source.
#define PROTOBUF_USE_DLLS
#include <iostream>
#include "addressbook.pb.h"
#pragma comment(lib, "libprotocd.lib")
#pragma comment(lib, "libprotobufd.lib")
#pragma comment(lib, "libprotobuf-lited.lib")
int main(int argc, const char* argv[])
{
tutorial::AddressBook ab;
return 0;
}
Here are the errors I am receiving.
LNK2001: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const * const google::protobuf::internal::empty_string_" (?empty_string_#internal#protobuf#google##3PEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##EB)
LNK2001: unresolved external symbol "__int64 google::protobuf::internal::empty_string_once_init_" (?empty_string_once_init_#internal#protobuf#google##3_JA)
Some assertions:
Same code running on linux.. With the exception of -lprotoc -lprotobuf -lprotobuf-lite vs. the #pregma stuff
Happens both in VS2013 and VS2015
Tried both 3.0-Release and latest code from git. Same issue.
I have tried this with both the debugtarget as well as the release (when using release removed trailing d from library name) target
Made sure that both the additional include and library directories were set in the VS project. linker --> General --> Additional Library Directories is set to the place where the compiled .dll are located`
At this point I pretty much turned my attention to google to see what I could find. I ran across the following.
2015 not fully supported. It was old, but figured I would try vs2013
protobuf dynamic linking Yes. When building with cmake I enabled shared library support and have the #define in my program
disable inline expansion
Still, not able to progress past the above errors. Any help is greatly appreciated.

Qr read and generation under QT creator using leadtools

I want to buy license for QR codes read and generating from Leadtools but first I want to try their demo tools. I'm using MSVC 2013 x64 compiler. I think I did everything as follows in documentation:
Copied all dll's to my project directory (where build and release folder are located)
Copied Include and Lib folders to my project directory and add this lines to .pro file.
LIBS += -L$$PWD/Lib/CDLLVC12/x64/ -lLtkrn_x
INCLUDEPATH += $$PWD/Include
PRE_TARGETDEPS += $$PWD/Bin/CDLLVC12/x64/Ltkrnx.dll
include and #define LTV19_CONFIG, here is my code:
#define LTV19_CONFIG
#include <iostream>
#include <Ltkrn.h>
#include <ClassLib/LtWrappr.h>
using namespace std;
int main( ){
if( LT_KRN == LBase::LoadLibraries( LT_KRN, LT_DLGKRN))
cout << "success" << endl;
L_TCHAR licenseFile[] = L"d:\\temp\\TestLic.lic";
L_TCHAR key[] = L"xyz123abc";
LSettings::SetLicenseFile( licenseFile, key);
return 0;
}
Ask leadtools support, but they don't have much experience with working with QT...
When I tries to build application I get following errors:
LNK2019: unresolved external symbol "__declspec(dllimport) public: static unsigned int __cdecl LBase::LoadLibraries(unsigned int,unsigned int)" (__imp_?LoadLibraries#LBase##SAIII#Z) referenced in function main
LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl LSettings::SetLicenseFile(wchar_t *,wchar_t *)" (__imp_?SetLicenseFile#LSettings##SAHPEA_W0#Z) referenced in function main
For following methods documentation says that I only need one dll/lib package (ltkrn). How to fix it? Still I don't get differences between static and dynamic linkage and this could be the problem.
If your linker accepted the 64-bit Ltkrn_x.lib, this suggests the problem is related to how you're using LEADTOOLS and not to QT. That's why I'm posting this as suggested reply instead of a note.
When programming using LEADTOOLS with C++, you normally use one of 2 sets of headers and LIBs:
Either include L_Bitmap.H (or a bunch of headers that includes LtKrn.H) and use the Ltkrn_x, Ltfil_x, etc. set of LIB files.
Or include ClassLib\LtWrappr.h and use only one LIB file, which in your case is Ltwvc_x.lib
Although in both cases you would be using many of the same DLL files such as Ltfilx.dll and Ltkrnx.dll, the reason you don't need their LIB files when using LtWrapper is that the ClassLibrary performs late (on demand) loading of these DLLs at run-time instead of referencing their LIB files at link time.
That's also why you need to call LBase::LoadLibraries() and specify the DLLs you need before your code uses these DLLs.
So to summarize, please try this:
Remove #include "Ltkrn.h"
Remove the linker reference to Ltkrn_x.lib (although you'll need the DLL)
Keep #include "ClassLib/LtWrappr.h"
Add a linker reference to Ltwvc_x.lib

CGAL unresolved externals when compiling/linking on Windows

I'm getting strange (for me) errors during compiling a test program which uses some parts of the CGAL library.
First, the environment:
Windows 7 64 bits
Boost 1.53
CGAL 4.3
Qt 4.8.4
CMake 2.8.10.2
Visual Studio 2010 professional
I installed all the libraries for 32 bits (if this was an option during installation).
Installation wrong?
In order to install CGAL on my computer, I followed this tutorial: http://www.cgal.org/windows_installation.html. I have to note here that this did not work out-of-the-box for me. During the configuration phase of CGAL in CMake, the boost libraries were not found (although I set the corresponding environment variables, as stated in the tutorial). After setting the incorrect variables in CMake, I was able to complete the configuration and generation phase. After that, I was able to compile both the Debug as well as the Release configurations of CGAL in Visual Studio.
In order to test whether the CGAL lib was installed successfully, I tried to compile and run both the examples and demos. These also did not work immediately. The problem was that the CGAL and Boost headers (and binaries) were not found. After setting the right paths in Project properties => Configuration properties => C/C++ => Additional Include Directories and in Project properties => Configuration properties => Linker => Additional Library Directories the examples and demos could be build. I successfully ran these examples after that.
Actual problem
Now, I'm tyring to compile a simple program, in order to be able to make a certain exercise (http://acg.cs.tau.ac.il/courses/algorithmic-robotics/spring-2013/exercises/assignment-2 exercise 2.1). Here, there are two files supplied: basic_typdef.h and cgal_bootcamp.cpp
*basic_typedef.h*
#pragma once
#include <CGAL/Cartesian.h>
#include <CGAL/Gmpq.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Boolean_set_operations_2/Gps_default_dcel.h>
#include <CGAL/Polygon_set_2.h>
#include <list>
/*******************************************************************************************
* This file contatins basic typedefs (from CGAL and more).
*******************************************************************************************/
typedef CGAL::Gmpq Number_type;
typedef CGAL::Cartesian<Number_type> Kernel;
typedef Kernel::Point_2 Point;
typedef CGAL::Polygon_2<Kernel> Polygon;
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes;
typedef CGAL::Polygon_set_2<Kernel> Polygon_set;
typedef std::list<Polygon_with_holes> Polygon_with_holes_container;
*cgal_bootcamp.cpp*
#include "basic_typedef.h"
int main(int argc, char* argv[])
{
return 0;
}
(For convenience I removed the comments in the file cgal_bootcamp.cpp)
With Visual Studio, I can compile the two files as above. However, when I try to create a Point (as defined in basic_typedef.h), I'm getting the (strange) errors:
#include "basic_typedef.h"
int main(int argc, char* argv[])
{
/*
1. Point
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Kernel_23_ref/Class_Point_2.html
*/
// Create Point with the coordinates (0.5, 0.6)
Point p;
return 0;
}
The errors that occur:
Error 1 error LNK2019: unresolved external symbol __imp____gmpq_init referenced in function "public: __thiscall CGAL::Gmpq_rep::Gmpq_rep(void)" (??0Gmpq_rep#CGAL##QAE#XZ) C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\cgal_bootcamp.obj warmup-exercise
Error 2 error LNK2019: unresolved external symbol __imp____gmpq_clear referenced in function "public: __thiscall CGAL::Gmpq_rep::~Gmpq_rep(void)" (??1Gmpq_rep#CGAL##QAE#XZ) C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\cgal_bootcamp.obj warmup-exercise
Error 3 error LNK1120: 2 unresolved externals C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\Debug\warmup-exercise.exe 1 1 warmup-exercise
4 IntelliSense: #error directive: "Mixing a dll CGAL library with a static runtime is a really bad idea..." c:\dev\cgal-4.3\include\cgal\auto_link\auto_link.h 364 4
5 IntelliSense: #error directive: "some required macros where not defined (internal logic error)." c:\dev\cgal-4.3\include\cgal\auto_link\auto_link.h 397 4
I have no clue what is going wrong here (I have to note that I'm still a noob with C++). It seems that there is something wrong with the GMP library (at least the linking to this?) I found in another post that for someone there were no libgmp files build (can't find that post anymore), but that is not the case for me (I think): in CGAL-4.3/auxiliary/gmp/lib I see four files, libgmp-10.dll libgmp-10.lib libmpfr-4.dll and libmpfr-4.lib.
Also the error on line 4 points to something that might cause this error ("Mixing a dll CGAL library with a static runtime is a really bad idea..."), but I do not know what this actually means (or how I can resolve it).
Further, I tried to setup all the libraries on another computer, but I got the same errors there also.
Could anyone point me in the right direction to solve this problem? If you need more information, please let me know.
This comment answered the question: the script cgal_create_cmake_script can be used to create a CMake file that can be used to generate a correct Visual Studio project using CGAL.

error LNK2019: unresolved external symbol due to helper library

I think the issue is with a function ConvertToUpperCase included in a helper library used in my CS course. I am trying to write something for my experiment but I learned with the helper library - so I don't know what to do without it.
The full error error:
LNK2019: unresolved external symbol "class std::basic_string,class std::allocator > __cdecl ConvertToUpperCase(class std::basic_string,class std::allocator >)" (?ConvertToUpperCase##YA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V12##Z) referenced in function "public: bool __thiscall Lexicon::containsPrefix(class std::basic_string,class std::allocator >)" (?containsPrefix#Lexicon##QAE_NV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
The function is included in strutils.h and explained here
Sample code:
#include "stdafx.h"
#include <cstdlib>
#include <string>
#include <iostream>
#include <set>
#include <fstream>
#include "genlib.h"
#include "strutils.h"
#include "simpio.h"
#include "set.h"
#include "lexicon.h"
using namespace std;
/* Function: AddWord1
* -----------------
* This function prompts the user for a code and then
* coverts entry to upper case and adds this word to the code list passed in.
*/
void AddWord1(Lexicon & lex)
{
cout << "Please enter activity code to add: ";
string word = ConvertToUpperCase(GetLine()); //may need to remove for code
lex.add(word);
cout << word << " added to code list." << endl;
}
Clarification:
yes, this was working code in 2009 and 2010 - so it was implemented.
the library was a .lib and I am now using the sourceForge version.
VS 2008, it last was working from a VS2005 compile, I have tried VS2005 and VS2011BETA but still have errors.
I am trying to make sure the appropriate cpp files are added to the project; I think they are. My genlib.cpp is dated 2011 and is different than the github.com/b33tr00t/cs106lib version which is for Linux users, so it makes sense that there are some differences.
There should be a library containing the compiled code as well as the header that you have. You need to add that library (a .lib or .obj file) to your project - specifically you need to include it in the linker settings.
If you don't have that then you might have one or more C++ source files defining those functions - you could add those to the project.
If you have none of those then you have a problem, I'm afraid.
If you don't have access to that library anymore (since you may no longer be in the class), you can write your own ConvertToUpperCase function using one of the techniques from this question.