error LNK2019: unresolved external symbol - only .h files - visual-studio-2010

Argh... I've been struggling lately to make Visual Studio 2010 (VC++) include a bunch of 3rd party libraries I wanna use in my project. That's the issue: The linker seems not to be able to determine every symbol that is generated in my code which come from the 3rd party libraries definitions. I've included the header files path on my include directories and also the sources path on my source directory, but it is still not working. I've googled it for a while and in most of cases, the issues is cause by a missing reference of the .lib file on linker's additional dependencies, however the library don't come with them.
Here's a piece of sample code:
#include "stdafx.h"
#include <fuzzylite\FuzzyEngine.h>
int _tmain(int argc, _TCHAR* argv[])
{
fl::FuzzyEngine eng;
return 0;
}
So that's the output VS shows
Fuzzycolors.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall fl::FuzzyEngine::~FuzzyEngine(void)" (??1FuzzyEngine#fl##UAE#XZ) referenced in function _wmain
Fuzzycolors.obj : error LNK2019: unresolved external symbol "public: __thiscall fl::FuzzyEngine::FuzzyEngine(void)" (??0FuzzyEngine#fl##QAE#XZ) referenced in function _wmain
So i wonder if is there a way to build my sources with the .h and .cpp files of my 3rd party library.
Thank you.
Caio

Check the new version of fuzzylite-2.0 at http://www.fuzzylite.com. That problem has been solved.
Windows requires to add __declspec(dllexport) to classes, which was not present in previous versions. Today, every class starts with class FL_EXPORT Engine, where FL_EXPORT is the missing definition.

Related

QuantLib Date class in Visual C++ 2010

I just started this simple Quantlib date class in VC++ Express 2010:
#include <iostream>
#include <sstream>
#include "ql/time/date.hpp"
int main(int, char* [])
{
QuantLib::Date d(1, QuantLib::January, 2010);
std::cout<<da<<std::endl;
}
When I compiled it, this is one of the errors:
1>ql_inout.obj : error LNK2019: unresolved external symbol "public: __thiscall QuantLib::Date::Date(int,enum QuantLib::Month,int)" (??0Date#QuantLib##QAE#HW4Month#1#H#Z) referenced in function _main
It must be something I didn't setup correctly in 2010 project. I have compiled the library in Debug mode successfully.
Not all headers include the pragma that tells the linker to add QuantLib. If you don't want to include the full headers—which is advisable, as they would increase a lot your compilation time—you can add
#include <ql/auto_link.hpp>
to the included headers.
(You could also add the library explicitly to the linker options, but that is a lot more work since you have to specify different library names depending on the configuration. auto_link.hpp does this for you.)

LNK2019: unresolved external symbol error in Visual Studio C++

This is my code in Visual Studio C++
#include "stdafx.h"
#include<opencv\cv.h>
#include<opencv\highgui.h>
using namespace cv;
int main(int argc, char** argv[]) {
IplImage* img = cvLoadImage("logo.jpg");
cvNamedWindow("Test", CV_WINDOW_AUTOSIZE);
cvShowImage("Test", img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("Test");
return 0;
}
I am using OpenCV 2.4.6 and Visual Studio 2010. This is the error:
openCV_testing.obj : error LNK2019: unresolved external symbol _cvDestroyWindow
referenced in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvReleaseImage
referenced in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvWaitKey referenced in
function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvShowImage referenced
in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvNamedWindow
referenced in function _main
openCV_testing.obj : error LNK2019: unresolved external symbol _cvLoadImage referenced
in function _main
Please help.
'unresolved external symbol' means that you're not linking with required library.
Go to Properties -> Linker -> Additional Library dependencies and add path to OpenCV libs.
First check
How to build applications with OpenCV inside the Microsoft Visual Studio
If you still suffer from the same problem, you could be under one of the below cases.
Your active solution platform is x86 but you are trying to link x64 OpenCV libraries.
Your active solution platform is X64 but you are trying to link x86 OpenCV libraries.
If you are under one of these cases, check
Compiling a 64-bit Application in Microsoft Visual Studio Express 2010
Add these into your code:
#pragma comment (lib, "opencv_core248d.lib")
#pragma comment (lib, "opencv_highgui248d.lib")
#pragma comment (lib, "opencv_imgproc248d.lib")
#pragma comment (lib, "opencv_video248d.lib")
#pragma comment (lib, "opencv_features2d248d.lib")
It worked for me.
i searched a lot for the same problem this was the best solution i had found and it worked for me.
Open Configuration Properties > C/C++ > General, and edit the field Additional Include Directories to add these 3 paths (for the headers):
C:\OpenCV2.3\build\include\opencv
C:\OpenCV2.3\build\include\opencv2
C:\OpenCV2.3\build\include
I know this is not about the OpenCV library, but I already had a problem importing Tiny-Process library. My .lib file was linked correctly in Configuration Properties -> Linker -> Additional Library dependencies and the Additionnal Include Directories were correctly added but the the functions definition (s) were still not found and I was getting the LNK2019 error.
To fix the issue, I had to go in the library project properties, change the Character Set property in Configuration Properties -> Advanced Character Set and change the value Use Multi-Byte Character Set to Use Unicode Character Set.
After recompiling the library and using the new .lib file, it was working.

Using Q_OBJECT in VS2010 project gives unresolved externals

I'm trying to use the Q_OBJECT macro in my Visual Studio 2010 Ultimate project, and it gives me unresolved external errors:
1>Application.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall MyButton::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#MyButton##UAEHW4Call#QMetaObject##HPAPAX#Z)
1>Application.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall MyButton::qt_metacast(char const *)" (?qt_metacast#MyButton##UAEPAXPBD#Z)
1>Application.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall MyButton::metaObject(void)const " (?metaObject#MyButton##UBEPBUQMetaObject##XZ)
I've had a similar project using QMaker, and solved it by doing clean project and re-running qmake. The thing is, there's no "Qmake" button in VS!
I have read few articles like this one and done everything they told me to. Though it didnt really help, because I've got an existing project of a few .cpp and a few header files, and I would like to avoid creating a .pro file and moving code into it.
I've installed VS Qt add-in, it gave me new cool "Qt" button on VS panel, though didn't help with unresolved externals (probably I don't know how to use it properly).
I have ran moc with via custom build tool in VS on my Application.h file (the only one that has Q_OBJECT), but that still didn't help:
C:\Utilities\QtSDK\Desktop\Qt\4.8.1\msvc2010\bin\moc Application.h -o tmp\moc\moc_Application.cpp
What might cause my problem and how do I solve it?
I would guess that you forgot to add the file generated by MOC (moc_Application.cpp in this case) into your Visual Studio project. You have to do this to make sure it gets built. I'm pretty sure this should resolve the linker errors you see.

Having problems linking with v8 on windows

I'm using Visual Studio 2010 on a 64-bit Windows 7 machine. I've pulled v8 source from SVN, built it with no problems (wich arch=x64), but I still can't compile my project that tries to use v8.
Here is a sample code that produces that same error :
#include <v8.h>
int main(int argc, char *argv[])
{
v8::Handle<v8::Context> context = v8::Context::New();
return 0;
}
The linker error I get is :
v8test.obj : error LNK2019: unresolved external symbol "public: static class v8::Persistent<class v8::Context> __cdecl v8::Context::New(class v8::ExtensionConfiguration *,class v8::Handle<class v8::ObjectTemplate>,class v8::Handle<class v8::Value>)" (?New#Context#v8##SA?AV?$Persistent#VContext#v8###2#PAVExtensionConfiguration#2#V?$Handle#VObjectTemplate#v8###2#V?$Handle#VValue#v8###2##Z) referenced in function _main
I built v8 as a static lib, tried both debug and release build, I get the same error.
In addition to v8_base.lib you need to also include v8_snapshot.lib, ws2_32.lib, and winmm.lib.
The sample on the V8 Getting Started Page can be compiled in a Console Application with following dependencies listed under Project Properties->Configuration Properties->Linker->Input->Additional Dependencies:
v8_base.lib;v8_snapshot.lib;ws2_32.lib;winmm.lib;(AdditionalDependencies)

Linking the Windows API

I was using a ITK library. When I wrote a sample program using this library, I've got following linker errors. As we can see these all "unresolved" symbols are Windows API functions and these windows API functions were used by ITK library and not my program.
Error 1 error LNK2019: unresolved external symbol _SnmpUtilVarBindFree#4 referenced in function "int __cdecl gdcm::GetMacAddrSys(unsigned char *)" (?GetMacAddrSys#gdcm##YAHPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 2 error LNK2019: unresolved external symbol _SnmpUtilOidNCmp#12 referenced in function "int __cdecl gdcm::GetMacAddrSys(unsigned char *)" (?GetMacAddrSys#gdcm##YAHPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 3 error LNK2019: unresolved external symbol _SnmpUtilOidCpy#8 referenced in function "int __cdecl gdcm::GetMacAddrSys(unsigned char *)" (?GetMacAddrSys#gdcm##YAHPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 4 error LNK2019: unresolved external symbol _WSAStartup#8 referenced in function "int __cdecl gdcm::GetMacAddrSys(unsigned char *)" (?GetMacAddrSys#gdcm##YAHPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 5 error LNK2019: unresolved external symbol __imp__UuidCreate#4 referenced in function "private: static bool __cdecl gdcm::Util::GenerateUUID(unsigned char *)" (?GenerateUUID#Util#gdcm##CA_NPAE#Z) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 6 error LNK2019: unresolved external symbol _gethostbyname#4 referenced in function "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl gdcm::Util::GetIPAddress(void)" (?GetIPAddress#Util#gdcm##CA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 7 error LNK2019: unresolved external symbol _gethostname#8 referenced in function "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl gdcm::Util::GetIPAddress(void)" (?GetIPAddress#Util#gdcm##CA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
Error 8 error LNK2019: unresolved external symbol _WSACleanup#0 referenced in function "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl gdcm::Util::GetIPAddress(void)" (?GetIPAddress#Util#gdcm##CA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) C:\Projects\sampleProject\bin\itkgdcm.lib(gdcmUtil.obj)
These errors have raised few questions in my mind. For some of them I think I know the answers but I need confirmation if I'm right or wrong.
These Windows API functions are used in gdcmUtil.cpp (because it says gdcmUtil.obj). So, compiler compiles gdcmUtil.cpp to (say)gdcmUtil.asm and it is assembler assembles it to gdcmUtil.obj. Since while compiling the library we are not generating any exe files. These *.obj files aren't linked against any other *.obj. So, windows API symbols are still external symbols for that module and thus left unresolved. Right?
Who is generating the *.LIB file? I mean compiler is generating *.s file and Assembler is generating *.obj file and we are not using linker. So, from where did we get *.lib file? Who packed all *.obj files to a *.lib file?
How are Windows API applications (programs that are written in C and use Windows API) are compiled? I mean, because its a standalone applications how are these WIN32 API symbols resolved? Assuming, I've written such program can anyone tell me what do I need to sucessfully build application?
I know that Windows API is implemented in kernel32.dll, gdi32.dll, user32.dll (which may in turn import some other dlls like wsock32.dll for networking API etc.) but the question is How to use these functions in Windows API functions in a C program. I mean how to dynamically link against these DLLs
In my quest to find answer to my problem of Linker errors. I discovered that I must add wsock32.lib (for WinSock 1.1) or ws2_32.lib(for WinSock 2) or snmpapi.lib to Linker Input.
Since when Windows API is being statically linked?
Since when windows API is being shipped in static libraries (*.lib files)?
In which directory can I find all these strange *.lib files?
Now, Is there any alternative solution other than adding *.lib files to linker input files? because when ever I use some new ITK library function, I get a new linker error. I've to Google to find in which *.lib file this specific symbol (window api function) belongs to then add that *.lib file to my linker input. Its driving me crazy! Is there any sane way?
Yes, that's right.
Who is generating what .lib file? A static library is normally generated by the lib utility. A library for a dll is normally generated by the linker.
You resolve Windows symbols by linking with the right libraries.
Again, by linking against the appropriate library (e.g., kernel32.lib, gdi32.lib and user32.lib for the three DLLs you mentioned).
It's not statically linked. You link against the library. In the case of a library for a DLL (such as those listed above) the linker uses that to embed a record into the executable that tells the loader which DLL to use to resolve those symbols. The .lib files are in the lib subdirectory of wherever you installed the SDK (typically something like C:\Program Files\Microsoft SDKs\Windows\v6.0A. Normally the SDK installer will add those where necessary so you don't have to explicitly specify that directory when linking from the command line or within Visual Studio.
There are a few, though it's open to question whether they're really an improvement. One possibility is to use a pragma to tell the linker to use a particular library:
#pragma comment(lib, "ws2_32.lib")
This is particularly useful in a header if it uses functions that depend on a particular library.

Resources