C++ Builder XE unresolved external error - c++

I have the following header file containing a class and some variables
extern bool akwizycja_w_toku;
extern LPCTSTR pFileName;
extern int numer_akwizycji;
class Akwizycja : public TThread
{
public:
__fastcall Akwizycja(bool CreateSuspended);
void __fastcall Akwizycja::UpdateLabels();
Akwizycja::Akwizycja() {}
};
(just a sample, there is more but it doesn't matter)
furthermore I've got the main project
#include "Akwizycja.h"
void __fastcall Akwizycja::UpdateLabels()
{
Form1->Label12->Caption=FloatToStrF(dRate,ffFixed,8,4);
Form1->Label13->Caption=FloatToStrF(ActualRate,ffFixed,8,3);
Form1->Label14->Caption=FloatToStrF(EffectiveRate,ffFixed,8,3);
Form1->Label15->Caption=pow(2,Clock_Divider);
}
where arguments like dRate or ffFixed are some of the extern variables.
The problem starts when I want to use some of the functions
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Akwizycja* new_object = new Akwizycja;
}
I get [ILINK32 Error] Error: Unresolved external '_dRate' referenced from D:\DF\DEBUG\WIN32\RECEIVER.OBJ
for all of the variables used.
Suppose it's some path-setting issue, but all of them are added. Many thanks for any piece of advice.

Related

compile error due to virtual function in dynamic link library

in a MSVC dll project, i tried to create a dll containing a base class
//header file
class MATHLIBRARY_API Shape {
protected:
int width, height;
public:
Shape(int, int);
int area(void) { return -1; };
};
it's compiled successfully, but when adding a virtual specifier to the function
class MATHLIBRARY_API Shape {
protected:
int width, height;
public:
Shape(int, int);
virtual int area(void) { return -1; };
};
the compiler showed error msg
Error LNK2019 unresolved external symbol `__declspec(dllimport) const Shape::`vftable'" (__imp_??_7Shape##6B#) referenced in function "public: __thiscall Shape::Shape(int,int)" (??0Shape##QAE#HH#Z) Dll3 c:\Users\langj\source\repos\Dll3\Dll3\Dll3.obj 1
where could be the problem?

Use imported dll inner class methods in c++

I've got a problem using 3rd party .dll library:
That library has some class with methods I need to use in my compiled .dll via JNI from my Java app.
I'm trying to declare something like that :
#ifdef SERVER_EXPORTS
#define SERVER_API __declspec(dllexport)
#else
#define SERVER_API __declspec(dllimport)
#endif
namespace MYDLLNAMESPACE
{
class SERVER_API IServer
{
public:
int NFun(int func);
};
class SERVER_API ServerClass : public IServer {
public:
ServerClass();
int NFun(int func) {
return MYDLLNAMESPACE::ServerClass::NFun(func);
}
};
}
Ant then use it in code like :
IServer *Myserv = new Server();
int a = Myserv->NFun(5007);
return a;
but it goes to the error "error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall MYDLLNAMESPACE::IServer:"
I need to do something like:
Iserver myServer = new Server();
int result = myServer.do_smth();
return result;
where Server is MYDLL.dll --> namespace MYDLLNAMESPACE --> class Server
Is there any ways how to do it?
P.S. I haven't any .lib of .h files of 3rd party .dll
EDIT:
Now I've got Server.h file :
namespace NS {
class __declspec(dllexport) ServerClass
{
public:
ServerClass() {
}
const char* GParam(const char* key);
const char* SParam(const char* key, const char* value);
};
}
And my Impl.cpp file, where I tryin' to instantiate ServerClass and use its method 'GParam' like this:
ServerClass *serv = new ServerClass();
const char* str = serv->GParam("LastErrorTxt");
but it goes to StackOverFlowException, seems like serv->GParam("LastErrorTxt") is executing itself instead of dll class implementation
Problem is solved by using com4j:
http://com4j.kohsuke.org/

error LNK2019: unresolved external symbol in derived class

The error occurred when I called a constructor of a derived class in another project. I omitted some details in the code. I am using Visual Studio 2012.
-Base/derived classes and the test file are in two different projects. Base/derived classes can be compiled without problems.
-The Test project can be compiled successfully when comment the constructor line.
-Test.cpp plays well with other constructor in the DerivationFunction file.
// Test.cpp
#include "DerivationFunction.h"
Child con(123, 123); // error LNK2019: unresolved external symbol "public: __thiscall Child::Child(unsigned short,unsigned int)" (??Child##QAE#GI#Z) referenced in function _main
The header file of base class and derived class:
// DerivationFunction.h
class Base
{
public:
virtual void AppendEnums() = 0;
static int CopyBuffer();
uint16 GetFeatureID();
protected:
uint16 baseValue;
static int Copy();
};
// Child class
class Child : public Base
{
public:
uint32 childValue;
Child(uint16 featureID, uint32 value);
void AppendEnums();
};
The source file:
// DerivationFunction.cpp
int Base::CopyBuffer()
{
return 0;
}
uint16 Base::GetFeatureID()
{
return baseValue;
}
int Base::Copy()
{
return 0;
}
// Child class
Child::Child(uint16 featureID, uint32 value)
{
baseValue = featureID;
childValue = value;
}
void Child::AppendEnums()
{
}
The simplest answer is that you haven't built and included the implementation file in with your main and hence the linker cannot find the code for the Child constructor. Look in the MSDN help for that particular error code and check all of the possibilities there.
If you want to use these classes in another project then you either include the whole sources (headers and cpp files) and build them, or export them from a DLL project and import them in the other project(s).

unresolved external symbol when accessing a static variable

class CommandManager {
public:
void sendText(std::string command);
static bool CommandManager::started;
private:
bool parseCommand(std::string commands);
void changeSpeed(std::vector<std::string> vec);
void help(std::vector<std::string> vec);
};
And here's the client code:
CommandManager::started = true;
Linking these two files together I get:
1>UAlbertaBotModule.obj : error LNK2001: unresolved external symbol "public: static bool CommandManager::started" (?started#CommandManager##2_NA)
1>C:\Development\School\cmput350-uofabot\UAlbertaBot\vs2008\Release\UAlbertaBot.dll : fatal error LNK1120: 1 unresolved externals
Where did I go wrong here?
You're doing that incorrectly.
class CommandManager {
public:
void sendText(std::string command);
static bool started; //NOT this -> bool CommandManager::started
//...
};
then put the definition of static member in .cpp file as:
#include "CommandManager.h" //or whatever it is
bool CommandManager::started = true; //you must do this in .cpp file
Now you can use CommandManager::started in your client code.
You should have inside your class:
class CommandManager {
public:
void sendText(std::string command);
static bool started;
//// etc
};
and outside your class, in a *.cc file (not in a *.hh header file), a definition like
bool CommandManager::started;
BTW, I believe you'll better make that private.
Consider putting
bool CommandManager::started;
where you define other members.

Link error CString

I'm getting a linker error using CString the error is:
error LNK2001: unresolved external symbol "private: static class ATL::CStringT<wchar_t,class StrTraitMFC<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > CConfiguration::_campaignFolderPath" (?_campaignFolderPath#CConfiguration##0V?$CStringT#_WV?$StrTraitMFC#_WV?$ChTraitsCRT#_W#ATL#####ATL##A)
I have a class which is defined as:
class CConfiguration
{
private:
static CString _campaignFolderPath;
public:
static void Read();
private:
CConfiguration(void);
~CConfiguration(void);
};
Its Read method is defined as:
void CConfiguration::Read()
{
CConfigFile configReader(_T("Config.ini"));
TCHAR temp[1024];
configReader.GetStringValue(_T("Campaigns"), _T("CampaignsFolderPath"), temp);
_campaignFolderPath = temp;
}
Any clues as to what is causing the error? I'm using Visual Studio 2008
You need to instantiate the string, you're just declaring it as static now. Add:
CString CConfiguration::_campaignFolderPath;
in the implementation file.
Do you have an implementation line like the following somewhere?
CString CConfiguration::_campaignFolderPath;