Unresolve external symbol - c++

I got this when compiling my DLL project:
Error 1 error LNK2019: unresolved external symbol "public: unsigned char * __thiscall CDetour::GetThisPtr(void)" (?GetThisPtr#CDetour##QAEPAEXZ) referenced in function "void __stdcall zCharacter_OnDamagedHook(struct ZObject *,struct D3DXVECTOR3,int,int,float,float,int)" (?zCharacter_OnDamagedHook##YGXPAUZObject##UD3DXVECTOR3##HHMMH#Z) C:\Users\Andrés\Documents\Visual Studio 2010\Projects\2k7_A-H\2k7_A-H\AntiLead.obj 2k7_A-H
Where I'm using "zCharacter_OnDamagedHook" is here:
void __stdcall zCharacter_OnDamagedHook(ZObject* pAttacker, D3DXVECTOR3 srcPos, int damageType, int weaponType, float fDamage, float fPiercingRatio, int nMeleeType) {
zCharacter_OnDamagedDetour.Ret(true);
std::string channelName = ZGameClient::GetInstance()->CurrentChannel;
ZCharacter* victim = (ZCharacter*)zCharacter_OnDamagedDetour.GetThisPtr();
ZCharacter* attacker = (ZCharacter*)pAttacker;
ZCharacter* me = (ZCharacter*)ZGame::GetInstance()->pMyCharacter;
if ((channelName.find("[No-Lead]") == std::string::npos) && (channelName.find("[No-Lead]") == std::string::npos)) {
ZCharacterManager* charm = ZCharacterManager::GetInstance();
if (((attacker == me) && (victim != me)) && (damageType != 5) && (damageType != 1) && (damageType != 2)) {
zCharacter_OnDamagedDetour.Ret(false);
MUID uidVictim;
for (unsigned int i = 0; i < muidList.size(); ++i) {
if (charm->Find(muidList[i]) == victim) {
uidVictim = muidList[i];
break;
}
}
MCommand* pCmd = MCommand::Create(0xD3D9);
pCmd->AddParameter(new MCommandParameterInt(uidVictim.lowId));
pCmd->AddParameter(new MCommandParameterFloat(srcPos.x));
pCmd->AddParameter(new MCommandParameterFloat(srcPos.y));
pCmd->AddParameter(new MCommandParameterFloat(srcPos.z));
pCmd->AddParameter(new MCommandParameterInt(damageType));
pCmd->AddParameter(new MCommandParameterInt(weaponType));
pCmd->AddParameter(new MCommandParameterFloat(fDamage));
pCmd->AddParameter(new MCommandParameterFloat(fPiercingRatio));
pCmd->AddParameter(new MCommandParameterInt(nMeleeType));
MCommand::Post(pCmd);
}
I really don't know what I'm doing wrong, also I hadn't got this error before so I hope someone could help me, thranks in advance.

Your CDetour class has declared a member function GetThisPtr but none of your source (.cpp) files has provided a definition.
Since you didn't show any of that code it's impossible to comment further.

Related

Failed to link the polygon tessellation library poly2tri

I was trying to draw the HalfEdge Data Structure solid with openGL, and I have to subdivision face which may have holes and turn the face to triangles. I use the poly2tri lib. Relate Code is blow.
void Renderer::Poly2Triangles(Face* face)
{
Plane2D plane(face);
std::vector<p2t::Point*> all_points;
std::vector<p2t::Point*> out_points;
std::vector<p2t::Point*> in_points;
//outter loop
Loop* outerLoop = face->fLoops;
while (outerLoop->IsInnerLoop) outerLoop = outerLoop->lNext;
glm::vec3 firstEdge = (outerLoop->lHEdge->destination->Pos).position - (outerLoop->lHEdge->origin->Pos).position;
glm::vec3 secondEdge = (outerLoop->lHEdge->Next->destination->Pos).position - (outerLoop->lHEdge->Next->origin->Pos).position;
glm::vec3 norm = glm::normalize(glm::cross(firstEdge, secondEdge));
HalfEdge* he = outerLoop->lHEdge;
do {
glm::vec2 p = plane.Space3DToPlane2D((he->origin->Pos).position);
p2t::Point* point = new p2t::Point(p.x, p.y);
all_points.push_back(point);
out_points.push_back(point);
he = he->Next;
} while (he != outerLoop->lHEdge);
p2t::CDT cdt(std::move(out_points)); //-----------first link error here---------------
//inner loop
Loop* innerLoop = face->fLoops;
do {
if (!(innerLoop->IsInnerLoop)) {
innerLoop = innerLoop->lNext;
continue;
}
HalfEdge* he = innerLoop->lHEdge;
do {
glm::vec2 p = plane.Space3DToPlane2D((he->origin->Pos).position);
p2t::Point* point = new p2t::Point(p.x, p.y);
in_points.push_back(point);
all_points.push_back(point);
he = he->Next;
} while (he != innerLoop->lHEdge);
cdt.AddHole(std::move(in_points));//----------------link error-------------
innerLoop = innerLoop->lNext;
} while (innerLoop != face->fLoops);
cdt.Triangulate();//-----------------------link error------------------------
auto tris = cdt.GetTriangles();//------------------------link error----------------------
for (auto tri : tris) {
Triangle triangle;
for (int i = 0; i < 3; i++) {
auto _p = tri->GetPoint(i);
triangle.vertex[i] = plane.Plane2DToSpace3D(glm::vec2(_p->x, _p->y));
triangle.normal[i] = norm;
}
triangles.push_back(triangle);
}
for (auto p : all_points)
delete p;
}
When I try to run it, it shows five link error:
Renderer.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall p2t::CDT::CDT(class std::vector<struct p2t::Point *,class std::allocator<struct p2t::Point *> >)" (??0CDT#p2t##QAE#V?$vector#PAUPoint#p2t##V?$allocator#PAUPoint#p2t###std###std###Z),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
1>Renderer.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall p2t::CDT::~CDT(void)" (??1CDT#p2t##QAE#XZ),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
1>Renderer.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall p2t::CDT::AddHole(class std::vector<struct p2t::Point *,class std::allocator<struct p2t::Point *> >)" (?AddHole#CDT#p2t##QAEXV?$vector#PAUPoint#p2t##V?$allocator#PAUPoint#p2t###std###std###Z),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
1>Renderer.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall p2t::CDT::Triangulate(void)" (?Triangulate#CDT#p2t##QAEXXZ),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
1>Renderer.obj : error LNK2019: 无法解析的外部符号 "public: class std::vector<class p2t::Triangle *,class std::allocator<class p2t::Triangle *> > __thiscall p2t::CDT::GetTriangles(void)" (?GetTriangles#CDT#p2t##QAE?AV?$vector#PAVTriangle#p2t##V?$allocator#PAVTriangle#p2t###std###std##XZ),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
just all the p2t::CDT class member was unresolved external symbol: CDT、~CDT、CDT::AddHole、 CDT::Triangulate、CDT::GetTriangles
I use VS2022 build this project, I add the poly2tri header file to the include file path in project properties. the file structure is blow and I just #include "poly2tri.h". it actually pass the compile.
I have no idea what's going on, I want to find errors and correct them. Or I'm happy to know other way to subdivision polygon to triangles.

error LNK2001: unresolved external symbol "public: __thiscall CDboTSTAgency::CDboTSTAgency(void)" [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 1 year ago.
I am trying to compile some files related to a server. During compilation I get some errors with unresolved external symbol public: __thiscall CDboTSTAgency::CDboTSTAgency(void), so I read some peoples answers about how to resolve it. Basically, most of the people problems was that they forgot to implement the constructor in the cpp after declaring it. In my case they are implemented but I still get the errors.
See code below:
DboTSTAgency.h
#ifndef _DBO_TSTAGENCY_H_
#define _DBO_TSTAGENCY_H_
#include "DboTSCoreDefine.h"
class CDboTSCompleteQInfo;
class CDboTSTRecv;
class CDboTSTCtrl;
class CDboTSMain;
/**
Trigger agency
*/
class CDboTSTAgency : public CNtlTSAgency
{
NTL_TS_DECLARE_RTTI
// Declarations
public:
typedef std::map<NTL_TS_T_ID, CDboTSTCtrl*> mapdef_TRIGGER_LIST;
// Member variables
protected:
CDboTSMain* m_pParent;
CDboTSTRecv* m_pRecv;
mapdef_TRIGGER_LIST m_defCurTList;
// Constructions and Destructions
public:
CDboTSTAgency();
virtual ~CDboTSTAgency( void );
// Methods
public:
virtual void Update( void );
CDboTSMain* GetParent( void );
void SetParent( CDboTSMain* pParent );
CDboTSTRecv* GetRecv( void );
void SetRecv( CDboTSTRecv* pRecv );
mapdef_TRIGGER_LIST* GetCurTList( void ) { return &m_defCurTList; }
CDboTSTCtrl* FindProgressTrigger( NTL_TS_T_ID tId );
void AttachProgressTrigger( NTL_TS_T_ID tId, CDboTSTCtrl* pCtrl );
void DetachProgressTrigger( NTL_TS_T_ID tId );
// Implementations
protected:
virtual CDboTSTCtrl* MakeTriggerController( CNtlTSTrigger* pTrig );
};
inline CDboTSMain* CDboTSTAgency::GetParent( void )
{
return m_pParent;
}
inline CDboTSTRecv* CDboTSTAgency::GetRecv( void )
{
return m_pRecv;
}
#endif
DboTSTAgency.cpp
#include "precomp_trigger.h"
#include "DboTSTRecv.h"
#include "DboTSTCtrl.h"
#include "DboTSMain.h"
#include "DboTSCtrlFactory.h"
#include "DboTSTAgency.h"
/**
Trigger agency
*/
NTL_TS_IMPLEMENT_RTTI(CDboTSTAgency, CNtlTSAgency)
CDboTSTAgency::CDboTSTAgency(void)
: m_pParent( 0 ),
m_pRecv( 0 )
{
}
CDboTSTAgency::~CDboTSTAgency( void )
{
}
void CDboTSTAgency::Update( void )
{
mapdef_TRIGGER_LIST::iterator itCPQ = m_defCurTList.begin();
for ( ; itCPQ != m_defCurTList.end(); )
{
CDboTSTCtrl* pQCtrl = itCPQ->second;
if ( pQCtrl->IsExitState() )
{
GetParent()->GetControlFactory()->DeleteObj( (CNtlTSControlObject*&)pQCtrl );
itCPQ = m_defCurTList.erase( itCPQ );
}
else
{
pQCtrl->Update();
++itCPQ;
}
}
}
void CDboTSTAgency::SetParent( CDboTSMain* pParent )
{
m_pParent = pParent;
}
void CDboTSTAgency::SetRecv( CDboTSTRecv* pRecv )
{
m_pRecv = pRecv;
}
CDboTSTCtrl* CDboTSTAgency::FindProgressTrigger( NTL_TS_T_ID tId )
{
mapdef_TRIGGER_LIST::iterator it = m_defCurTList.find( tId );
if ( it == m_defCurTList.end() ) return 0;
else return it->second;
}
void CDboTSTAgency::AttachProgressTrigger( NTL_TS_T_ID tId, CDboTSTCtrl* pCtrl )
{
m_defCurTList[tId] = pCtrl;
}
void CDboTSTAgency::DetachProgressTrigger( NTL_TS_T_ID tId )
{
mapdef_TRIGGER_LIST::iterator it = m_defCurTList.find( tId );
if ( it != m_defCurTList.end() ) m_defCurTList.erase( it );
}
CDboTSTCtrl* CDboTSTAgency::MakeTriggerController( CNtlTSTrigger* pTrig )
{
// Trigger controller
CNtlTSControlObject* pCtrlObj = GetParent()->GetControlFactory()->CreateObj( "CDboTSTCtrl" );
if ( !pCtrlObj->IsDerivedClass( "CDboTSTCtrl" ) )
{
CNtlTSLog::Log( "Can not do type cast from CNtlTSControlObject to CDboTSTCtrl. Info[%s]. [%s]", pCtrlObj->GetClassName(), TS_CODE_TRACE() );
m_pParent->GetControlFactory()->DeleteObj( pCtrlObj );
return 0;
}
((CDboTSTCtrl*)pCtrlObj)->SetTrigger( pTrig );
((CDboTSTCtrl*)pCtrlObj)->SetParent( this );
return (CDboTSTCtrl*)pCtrlObj;
}
The error during compilation is:
error LNK2001: unresolved external symbol "public: __thiscall
CDboTSTAgency::CDboTSTAgency(void)" (??0CDboTSTAgency##QAE#XZ)
"unresolved external symbol" is most of the time linker error.
Also in LNK2001 LNK indicates linker .So here linker is unable to find the definition of the function CDboTSTAgency::CDboTSTAgency(void).
Your declaration of constructor is CDboTSTAgency::CDboTSTAgency()
but you are defining constructor for CDboTSTAgency::CDboTSTAgency(void)
Change your code like this and see if it works
DboTSTAgency.h
// Constructions and Destructions
public:
CDboTSTAgency(void );
virtual ~CDboTSTAgency( void );

How to call TagLib in Windows Runtime Component C++

So I am using TagLib in WinRT Component and trying to get Album arts of mp3 files and then save them to separate files. So far I am using this code:
auto albumartFolder = ApplicationData::Current->LocalFolder;
StorageFile^ destStorageFile = create_task(albumartFolder->CreateFileAsync("\\AlbumArts\\" + destFileName + ".jpg")).get();
TagLib::MPEG::File mpegFile(file->Path->Data());
static const char *IdPicture = "APIC";
TagLib::ID3v2::Tag *id3v2tag = mpegFile.ID3v2Tag();
TagLib::ID3v2::FrameList Frame;
TagLib::ID3v2::AttachedPictureFrame *PicFrame;
void *RetImage = NULL, *SrcImage;
unsigned long Size;
FILE *jpegFile;
jpegFile = fopen((char*)destStorageFile->Path->Data(), "wb");
if (id3v2tag)
{
Frame = id3v2tag->frameListMap()[IdPicture];
if (!Frame.isEmpty())
{
for (TagLib::ID3v2::FrameList::ConstIterator it = Frame.begin(); it != Frame.end(); ++it)
{
PicFrame = (TagLib::ID3v2::AttachedPictureFrame *)(*it);
if ( PicFrame->type() ==
TagLib::ID3v2::AttachedPictureFrame::FrontCover)
{
Size = PicFrame->picture().size();
SrcImage = malloc(Size);
if (SrcImage)
{
memcpy(SrcImage, PicFrame->picture().data(), Size);
fwrite(SrcImage, Size, 1, jpegFile);
fclose(jpegFile);
free(SrcImage);
}
}
}
}
}
This code should work without a bug I know but here are the exceptions I am recieving:
1>LibraryModule.obj : error LNK2019: unresolved external symbol "public: __thiscall TagLib::FileName::FileName(wchar_t const *)" (??0FileName#TagLib##QAE#PB_W#Z) referenced in function "public: bool __thiscall <lambda_88d334404ef137d46dbb027b26f435b8>::operator()(void)const " (??R<lambda_88d334404ef137d46dbb027b26f435b8>##QBE_NXZ)
1>LibraryModule.obj : error LNK2019: unresolved external symbol "public: __thiscall TagLib::MPEG::File::File(class TagLib::FileName,bool,enum TagLib::AudioProperties::ReadStyle)" (??0File#MPEG#TagLib##QAE#VFileName#2#_NW4ReadStyle#AudioProperties#2##Z) referenced in function "public: bool __thiscall <lambda_88d334404ef137d46dbb027b26f435b8>::operator()(void)const " (??R<lambda_88d334404ef137d46dbb027b26f435b8>##QBE_NXZ)
1>LibraryModule.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall TagLib::MPEG::File::~File(void)" (??1File#MPEG#TagLib##UAE#XZ) referenced in function "public: bool __thiscall <lambda_88d334404ef137d46dbb027b26f435b8>::operator()(void)const " (??R<lambda_88d334404ef137d46dbb027b26f435b8>##QBE_NXZ)
Any help regarding this would be appreciated very much!
Edit:
So, this is marked as duplicate but I still cannot fix the problem. How do I link Taglib correctly? I installed the Nuget package, was I wrong to do so?

using openNN in visual studio (unresolved external symbol)

I am looking to use the C++ neural network library "OpenNN".
http://www.opennn.net/
I am relatively new to C++ project management and I believe my issue is caused by this.
I have cloned the openNN repo.
I copied the relevant folders form the repo across in to the folder that i created to contain all OpenNN project i plan to make.
I then made a c++ console application in visual studio, in this folder that i am using for testing.
so dir structure is :
OpenNN (where i plan to keep all openNN projects)
---eigen
---opennn
---tinyxml2
---OpenNNTest (my test project folder)
I have done some testing with the Vector and Matrix classes that are part of OpenNN and that all worked fine.
The below code however returns the following two external symbol errors:
Error LNK2019 unresolved external symbol "public: __thiscall OpenNN::NeuralNetwork::NeuralNetwork(class OpenNN::Vector<unsigned int> const &)" (??0NeuralNetwork#OpenNN##QAE#ABV?$Vector#I#1##Z) referenced in function "void __cdecl NNTest(void)" (?NNTest##YAXXZ) OpenNNTest D:\Projects\OpenNN\OpenNNTest\OpenNNTest\OpenNNTest.obj 1
Error LNK2019 unresolved external symbol "public: virtual __thiscall
OpenNN::NeuralNetwork::~NeuralNetwork(void)" (??1NeuralNetwork#OpenNN##UAE#XZ) referenced in function "void __cdecl NNTest(void)" (?NNTest##YAXXZ) OpenNNTest D:\Projects\OpenNN\OpenNNTest\OpenNNTest\OpenNNTest.obj 1
interestingly, if I change:
OpenNN::NeuralNetwork nn(architecture);
to
OpenNN::NeuralNetwork nn();
No issues, as if it finds the default constructor but not the overloaded one?
The code I am using is as follows:
#include "stdafx.h"
#include "../../opennn/opennn.h"
using namespace OpenNN;
using std::cout;
using std::endl;
void NNTest()
{
OpenNN::Vector<unsigned> architecture(5);
architecture[0] = 2;
architecture[1] = 2;
architecture[2] = 4;
architecture[3] = 3;
architecture[4] = 1;
OpenNN::NeuralNetwork nn(architecture);
//Vector<double> inputs(2);
//inputs[0] = 0.5;
//inputs[1] = 0.1;
//Vector<double> outputs = nn.calculate_outputs(inputs);
//cout << outputs << endl;
//nn.save("neural_network.xml");
}
int main()
{
NNTest();
getchar();
return 0;
}
You need to change the type unsigned to size_t:
OpenNN::Vector<size_t> architecture(5);
architecture[0] = 2;
architecture[1] = 2;
architecture[2] = 4;
architecture[3] = 3;
architecture[4] = 1;
OpenNN::NeuralNetwork nn(architecture);
I hope that helps.

Unmanaged C++ Unit testing in Visual Studio 2008

I want to create a managed C++ unit test project to test an unmanaged MFC project. I have read msujaws's procedural and followed it. I implemented a test method to test the return string of a function like so:
#include "stdafx.h"
#include "TxStats.h"
#include <cstdlib>
#include <atlstr.h>
#pragma managed
#using <mscorlib.dll>
#using <System.dll>
#using <system.data.dll>
using namespace std;
using namespace System;
using namespace System::Text;
using namespace System::Text::RegularExpressions;
using namespace System::Collections::Generic;
using namespace System::Runtime::InteropServices;
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
namespace AUnitTest
{
[TestClass]
public ref class TxStatsTest
{
private:
TestContext^ testContextInstance;
public:
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
property Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ TestContext
{
Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ get()
{
return testContextInstance;
}
System::Void set(Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ value)
{
testContextInstance = value;
}
};
#pragma region Additional test attributes
//
//You can use the following additional attributes as you write your tests:
//
//Use ClassInitialize to run code before running the first test in the class
//[ClassInitialize()]
//static void MyClassInitialize(TestContext^ testContext) {};
//
//Use ClassCleanup to run code after all tests in a class have run
//[ClassCleanup()]
//static void MyClassCleanup() {};
//
//Use TestInitialize to run code before running each test
//[TestInitialize()]
//void MyTestInitialize() {};
//
//Use TestCleanup to run code after each test has run
//[TestCleanup()]
//void MyTestCleanup() {};
//
#pragma endregion
[TestMethod]
void TestGetTxRateStr()
{
/* str to CString
CManagedClass* pCManagedClass = new CManagedClass();
pCManagedClass->ShowMessage(strMessage);
char* szMessage = (char*)Marshal::StringToHGlobalAnsi(strMessage);
CUnmanagedClass cUnmanagedClass; cUnmanagedClass.ShowMessageBox(szMessage);
Marshal::FreeHGlobal((int)szMessage);
*/
CString out = TxStats::GetTxRateStr(1024);
// convert between MFC and .NET String implementations
String ^ myManagedString = Marshal::PtrToStringAnsi((IntPtr) (char *) out.GetBuffer());
String ^ ret = myManagedString ;///gcnew String( );
Regex ^ matStr = gcnew Regex("1024 KB/s");
StringAssert::Matches(ret, matStr);
}
};
}
That tests the code in a DIFFERENT project that looks like this:
#include "stdafx.h"
#include "TxStats.h"
TxStats::TxStats()
{
}
/*
This method returns a data rate string formatted in either Bytes, KBytes, MBytes or GBytes per sec
from an int of the bytes per second.
*/
CString TxStats::GetTxRateStr(__int64 Bps)
{
enum DataUnits dunit;
const __int64 dataSizes[]= { 0x1, // 2 ^ 0
0x400, // 2 ^ 10
0x100000, // 2 ^ 20
0x40000000};// 2 ^ 30
const char *dataStrs[] = { "B/s",
"KB/s",
"MB/s",
"GB/s"};
CString out;
double datarate;
bool finish = false;
for ( dunit = A_KBYTE; dunit <= LARGER_THAN_BIGGEST_UNIT; dunit = DataUnits(dunit+1) )
{
if ( dunit == LARGER_THAN_BIGGEST_UNIT )
{
if (dataSizes[dunit - 1] <= Bps )
{
//Gigabytes / sec
datarate = Bps / ((double) dataSizes[dunit - 1]);
out.Format("%4.2f %s", datarate, dataStrs[dunit - 1]);
finish = true;
break;
}
}
else
{
if (Bps < dataSizes[dunit])
{
//(Kilo, Mega)bytes / sec
datarate = Bps / ((double) dataSizes[dunit - 1]);
out.Format("%4.2f %s", datarate, dataStrs[dunit - 1]);
finish = true;
break;
}
}
}
if (! finish)
{
out.Format("%s", "Unknown!");
}
return out.GetBuffer();
}
void TxStats::BytesToSizeStr(__int64 bytes, CString &out)
{
if (bytes < 0)
{
out = "Err";
}
else if (bytes == 0)
{
out = "0B";
}
else
{
CString size;
CString byteChar = "B";
CString unit;
int val;
if (bytes < 1024)
{
//Bytes
unit = "";
val = (int)bytes;
}
else if ( (bytes >> 10) < 1024 )
{
//Kilobytes
unit = "K";
__int64 div = 1 << 10;
val = (int) (bytes / ((double) div ));
}
else if ( (bytes >> 20) < 1024 )
{
//Megabytes
unit = "M";
__int64 div = 1 << 20;
val = (int) (bytes / ((double) div ));
}
else
{
//Else assume gigabytes
unit = "G";
__int64 div = 1 << 30;
val = (int) (bytes / ((double) div ));
}
unit = unit + byteChar;
const char * unitCharBuf = unit.GetBuffer();
size.Format("%d%s", ((int) val), unitCharBuf);
out = size.GetBuffer();
}
}
However, when I compile this code I get the following error:
2>TxStatsTest.obj : error LNK2028: unresolved token (0A0005D4) "public: static class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > __cdecl TxStats::GetTxRateStr(__int64)" (?GetTxRateStr#TxStats##$$FSA?AV?$CStringT#DV?$StrTraitMFC_DLL#DV?$ChTraitsCRT#D#ATL#####ATL##_J#Z) referenced in function "public: void __clrcall AUnitTest::TxStatsTest::TestGetTxRateStr(void)" (?TestGetTxRateStr#TxStatsTest#AUnitTest##$$FQ$AAMXXZ)
2>TxStatsTest.obj : error LNK2019: unresolved external symbol "public: static class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > __cdecl TxStats::GetTxRateStr(__int64)" (?GetTxRateStr#TxStats##$$FSA?AV?$CStringT#DV?$StrTraitMFC_DLL#DV?$ChTraitsCRT#D#ATL#####ATL##_J#Z) referenced in function "public: void __clrcall AUnitTest::TxStatsTest::TestGetTxRateStr(void)" (?TestGetTxRateStr#TxStatsTest#AUnitTest##$$FQ$AAMXXZ)
2>\trunk\<proj>\Debug\AUnitTest.dll : fatal error LNK1120: 2 unresolved externals
2>Caching metadata information for c:\program files\microsoft visual studio 9.0\common7\ide\publicassemblies\microsoft.visualstudio.qualitytools.unittestframework.dll...
2>Build log was saved at "file://trunk\<proj>\AUnitTest\Debug\BuildLog.htm"
2>AUnitTest - 3 error(s), 0 warning(s)
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========
Can anyone suggest why the Unit test project might not be linking against the obj files of the main project? (I have already specified the main project as a dependency of the unit test project)
You can add
#pragma comment(lib, "TxStats.lib")
to your unit test project's stdafx.cpp to link against the other library.
You need to add the *.obj files of the project you want to test to the linker inputs of the unit test project