LNK2019 Error Header is included but not linked? - c++

I have some classes and headers that are external to my program that i wish to use. I am using MSVC2013 and have specified the location of these files in the "Additional include directories" entry in the project settings window. Intellisense recognises the paths and provides the appropriate syntax highlight and my program compiles fine except at the end it throws LNK2019 errors for any usage of these classes. Is there another place in linker settings I need to specify to link external files or am i missing something obvious here.
Error messages:
MainWindow.obj : error LNK2019: unresolved external symbol "public: __cdecl QPropertyEditorWidget::QPropertyEditorWidget(class QWidget *)" (??0QPropertyEditorWidget##QEAA#PEAVQWidget###Z) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow##QEAA#PEAVQWidget###Z)

Header files typically provide the API and/or data structures for some other code (most likely a library). With the headers you know about the "other" code, but you don't actually "have it" in your program.
Specifying where to find the headers is only half of the problem. You also need to specify where to find the object files (or libraries), and which objects or libraries to link against.

Related

constructor overloading Class get Linker Error Using DLL?

I have created Regular DLLs Dynamically Linked to MFC.
in before build dll in dll project i used add another class. this class provide more method of constructor overloading.
Then I build dll successfully after i used this lib and dll file include project and then go to build and get linker error when using constructor overloading class
My Class Name: Object
Error 11 error LNK2001: unresolved external symbol "public: __thiscall AvinashiAMF::Object::~Object(void)" (??1Object#AvinashiAMF##QAE#XZ) BuleCappServiceUseDynamicDllDlg.obj
Error 10 error LNK2001: unresolved external symbol "public: __thiscall AvinashiAMF::Object::Object(enum AvinashiAMF::ObjectType,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Object#AvinashiAMF##QAE#W4ObjectType#1#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) BuleCappServiceUseDynamicDllDlg.obj
Error 12 fatal error LNK1120: 2 unresolved externals D:\Test Aplications\Visual Studio 2008\Projects\BuleCappServiceUseDynamicDll\Release\BuleCappServiceUseDynamicDll.exe
You're probably not exporting your class. See here http://msdn.microsoft.com/en-us/library/81h27t8c.aspx
Also, a nice tool to check for this kind of issues is depends.exe, included with Visual Studio, which allows you to check for exported and imported symbols.
There are two significantly different dynamic link libraries: implicitly linked and explicitly linked.
In short, implicitly linked is linked at the compile time. You need an import library to link with(.lib), header file with functions prototypes and properly usage of the dllexport and dllexport or use .def file.
dllexport/dllexport are easier to use in this case. System takes care of loading libraries (DLLs).
Explicit linking is a runtime linking. You do not need any import library or headers. You need to know what is the function signature. You have to explicitly call LoadLibrary and GetProcAddress to call the function.
To see how to properly create macros for export/import create empty Win32 project select DLL and make sure the Export symbols check box is checked.
In the main header file you will see explanation how to use macros for import/export.

Creating object by using new operator causes unresolved external symbol error C++ FTGL

I'm using FTGL library in my Microsoft Visual Studio 2012, C++ project. I finally managed to properly link it to my project as I can properly render a font by using:
FTGLPixmapFont font("C:/Windows/Fonts/Arial.ttf");
font.Render("Hello world");
Everything seems to be ok until I try to create an object by using new operator:
FTGLPixmapFont* font = new FTGLPixmapFont("C:/Windows/Fonts/Arial.ttf"); // This causes error
font->Render("Hello world");
The code above produces this error:
AppLayer.obj : error LNK2001: unresolved external symbol "public: virtual float __thiscall FTFont::Advance(unsigned short const *,int,class FTPoint)" (?Advance#FTFont##UAEMPBGHVFTPoint###Z)
1>AppLayer.obj : error LNK2001: unresolved external symbol "public: virtual class FTBBox __thiscall FTFont::BBox(unsigned short const *,int,class FTPoint,class FTPoint)" (?BBox#FTFont##UAE?AVFTBBox##PBGHVFTPoint##1#Z)
1>AppLayer.obj : error LNK2001: unresolved external symbol "public: virtual class FTPoint __thiscall FTFont::Render(unsigned short const *,int,class FTPoint,class FTPoint,int)" (?Render#FTFont##UAE?AVFTPoint##PBGHV2#1H#Z)
I have completely no idea what can be reason for this. I'd really appreciate any answers.
Thanks!
It looks like you forgot to link a library, or to include a file in the build.
This class inherits the class FTFont. Check that you correctly linked the library including this definition.
In visual, you can just link the list by adding the .lib file to the project like if it is a cpp.
If you link another project from the visual solution, check in the properties of your project if the dependance to the other project is set correctly.
best
Those specific linker errors happen if the "Treat WChar_T As Built in Type" property (found in C/C++ / Language in the property pages) is set to 'Yes' for the complication of the FTGL library and 'No' for the compilation of your application using the library.
The compiler preparing functions with "WChar_t const*" as the argument type in the FTGL library, but your program will be looking for "unsigned short *const", and so won't find any function with that signature.
To fix, change the property "Treat WChar_T As Built in Type" in your project so that it matches the setting in the FTGL library; clean and recompile and it should work.

Linking DLL with Visual C++

I'm trying to use an external DLL (provided by AutoItX) with Visual C++ 2010. AutoItX provides a DLL, but for some reason not a LIB, so I generated one with Visual Studio.
The problem is that the linker seems to have trouble linking against the library. I added AutoItX3.lib as an additional dependency under Properties->Linker -> Inputs, and added the directory to Properties -> Linker -> General -> Additional Library Directories. No matter what I do, I still get these errors:
1>main.obj : error LNK2019: unresolved external symbol _AU3_Send#8 referenced in function _WinMain#16
1>main.obj : error LNK2019: unresolved external symbol _AU3_WinWaitActive#12 referenced in function _WinMain#16
1>main.obj : error LNK2019: unresolved external symbol _AU3_Run#12 referenced in function _WinMain#16
1>main.obj : error LNK2019: unresolved external symbol _AU3_Sleep#4 referenced in function _WinMain#16
AU3_Send, AU3_WinWaitActive, AU3_Run, and AU3_Sleep are functions called by the program, main.cpp. I'm really out of ideas, because these functions clearly exist in the DLL. Any help would be appreciated.
It is very common to provide only DLLs as a mean of interfaces. Many software providers do that. Doing this has following impacts (consequences):
the client applications can only dynamically link to the library provided (hence the name Dynamic-Link Library). The binding between the provider (the library) and the consumer (the App or any other Library) is made dynamically.
the client must use LoadLibray and GetProcAddress in order to bind the library and retrieve the Symbols (functions) desired
the interface (contract) between the Library and the consumer should be documented via a Header file - see AutoIt3.h for example - (or any other documentation like a help file, ..)
No LIB is provided (since it is not needed), since the Linking takes place at runtime, not at compiler/linker time
To resolve your problem you just need to remove the static dependency (the LIB) you put in the Visual Studio configuration and set the dependency at runtime using LoadLibrary and GetProcAddress

unresolved external symbol __imp__Inf and __imp__Nan

I just tried to build Qt for WinCE7.0 using VS2008 after lots of code modification I successfully compiled main libraries.
While Compiling the QtScript library I received the following linker errors:
1>Linking...
1> Creating library ..\..\lib\QtScript4.lib and object ..\..\lib\QtScript4.exp
1>BytecodeGenerator.obj : error LNK2019: unresolved external symbol __imp__Inf referenced in function "public: static double __cdecl QTWTF::FloatHashTraits<double>::emptyValue(void)" (?emptyValue#?$FloatHashTraits#N#QTWTF##SANXZ)
1>Executable.obj : error LNK2001: unresolved external symbol __imp__Inf
1>MathObject.obj : error LNK2001: unresolved external symbol __imp__Inf
1>DateMath.obj : error LNK2019: unresolved external symbol __imp__Nan referenced in function "double __cdecl QTWTF::parseDateFromNullTerminatedCharacters(char const *,bool &,int &)" (?parseDateFromNullTerminatedCharacters#QTWTF##YANPBDAA_NAAH#Z)
1>JSValue.obj : error LNK2001: unresolved external symbol __imp__Nan
1>..\..\lib\QtScript4.dll : fatal error LNK1120: 2 unresolved externals
I have absolutely no idea which libraries I missed to link with!
Thanks
If you're using Windows, I'll assume you're building in MSVS. I often start projects WITHOUT default libs and if I happen to touch "out of reach" terriotry from another lib, I add what I need as I go along.
Fortunately, MSVS is great at helping me with this. Just turn VERBOSE compiling status and see what libs it's trying to access, then just add them:
right click the project, linker, show progress -> select VERBOSE
Another method is when I check MSDN for Microsoft functions and see the lib they are declared in and add it (since VERBOSE can be overkill on my poor output window). I don't know if Qt has a detailed reference documentation (also stating the libs) but it's worth a shot.
When all else fails, just add all libs Qt could possibly want (make sure IGNORE STANDARD LIBS is disabled) then check VERBOSE and only keep those in the list.
Assuming you have all the libraries in the project, another problem is mismatched dependencies (right click the solution, startup project -> select the one you need, [project dependencies -> map each dependency for the specified libs).
Also make sure when you import an extern the lib is defined in Linker->Input.
However, if you modified the source (either adding new functions/global or static vars or you modified function signatures), the unresolved external reference means a function/var definition has no associated body. Either implement one or add { } in the definition; so if that's the case, check the functions/vars from the error message.

Which library I need to add? : error LNK2019

Error 20 error LNK2019: unresolved
external symbol "public: __thiscall
CAnyseeUSBTVControllerDlg::CAnyseeUSBTVControllerDlg(class
CWnd *)"
(??0CAnyseeUSBTVControllerDlg##QAE#PAVCWnd###Z)
referenced in function "int __cdecl
Init(void)"
(?Init##YAHXZ) anyseeUSBTVControllerDlg.obj anyseee30
I have this error when I want compile my win32 dll project in visual studio 2008.
Also second error (propably linked with first):
Error 21 fatal error LNK1120: 1
unresolved
externals .\Debug/anyseeUSBTVController.exe anyseee30
Which library I need to add to linker? I've read that it is the problem.
You need to add the library that contains the CAnyseeUSBTVControllerDlg class. Since a web search for CAnyseeUSBTVControllerDlg returns nothing, the library seems to be a private library without public documentation.
If you only have class declaration and do not have class implementation, then you need to check with whoever gave you that header file. Ask them for the library.
Generally, Libraries come with header files. Implementation will be inside the library.
By including those header files, we can use library classes/functions.
If header file is written by you, then you need to implement the class in a c++ file.