Linkage Error with Inherited Class - c++

I have static library and another program which uses it.
In the static library If I define header without inheretence it works fine.
class TcpCommunication
On the other hand If I use inheretence with a QT class,
class TcpCommunication:public QTcpServer
I'm getting linkage error when I compiling code which uses this static library.
>MStoDKAPId.lib(TcpCommunication.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QTcpServer::~QTcpServer(void)" (__imp_??1QTcpServer##UAE#XZ) referenced in function "public: virtual __thiscall TcpCommunication::~TcpCommunication(void)" (??1TcpCommunication##UAE#XZ)
What can be the problem?
Thanks.

You need to add a reference to the library that contains the definition of the QTcpServer class.
Your IDE should have an option to specify link options, one of which will be the names of the libraries and another to specify search paths for libraries. Update these two to add the path / library of the QT framework.

The application using your static library also needs to link to QT

Related

LNK2019 Error Header is included but not linked?

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.

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.

static library linkage failure in visual c

In visual c++, I created a static library with two files, myLib.h and myLib.cpp. I also have a console application project with the file testSequence.cpp that references this library.
Within myLib.h I have defined a class template<class prec> class sequence which has the function declaration prec *getPrimes(int numToGet) this function is then defined in myLib.cpp. However, when I build testSequence, there is a linking error, and it says error LNK2019: unresolved external symbol "public: int * __thiscall mathLib::sequence<int>::getPrimes(int)" (?getPrimes#?$sequence#H#mathLib##QAEPAHH#Z) referenced in function "char * __cdecl codeString(char *,char *,bool)" (?codeString##YAPADPAD0_N#Z)
So, yeah, help would be nice.
Read this for an explanation of the error.
Basically, what you're trying to do cannot be done. The compiler must be able to see the implementation of the class template when it tries to instantiate it for a given template type parameter. You need to move the implementations for all the member functions to the header file.

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.

Using a DLL that links to a static lib

I'm trying to build a solution in Visual C++ where I have a front-end project that references a DLL project that I created. In the DLL project I link to a static library (that I have not written) that has static objects and definitions. Everything builds fine but I have linking problems.
I have a couple of questions. First, I should only get unresolved symbols for objects that I reference in the front-end that are not exported, right? I want the DLL to be the only interface to the static library and do not directly reference any part of it in the front-end, and yet I get a number of unresolved symbols from this library. There symbols seem to be #included and at least some not directly linked by the DLL project. I suspect it has to do with the static declarations in the static lib but how can I deal with these?
Some of the unresolved symbol errors:
2>AnalysisVis.obj : error LNK2001: unresolved external symbol "public: __thiscall SharkException::SharkException(char const *,int,char const *)" (??0SharkException##$$FQAE#PBDH0#Z)
2>AnalysisVis.obj : error LNK2001: unresolved external symbol "public: static class Bernoulli Rng::coinToss" (?coinToss#Rng##2VBernoulli##A)
2>AnalysisVis.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall ChromosomeT<bool>::operator<(class Chromosome const &)const " (??M?$ChromosomeT#_N##$$FUBE_NABVChromosome###Z)
The exported symbols are mangled. If the static lib was compiled using a different compiler (or compiler version) than the one you are using, it is possible that the symbols your application is expecting to see were defined in the static lib using a different name mangling scheme. You can use the following command to get the name mangling used in the static lib and then compare it to the one in the error message:
>pushd <path_to_msvc_dir>\Microsoft Visual Studio X.0\VC\bin
>dumpbin /all [static_lib_path] > out.txt
>type out.txt | find /I "SharkException"
>type out.txt | find /I "coinToss"
>type out.txt | find /I "ChromosomeT"
BTW, does the DLL that uses the static lib compiles cleanly with the same compiler your application/solution does?