I was trying to compile a vc++ project on pclsceleton tracking but got the following errors inspite of the fact that i have already included header files for them
the code for which the error gives is-
// Callback: New user was detected
void XN_CALLBACK_TYPE User_NewUser(xn::UserGenerator& generator, XnUserID nId, void* pCookie)
{
printf("New User %d\n", nId);
userGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
osc::OutboundPacketStream p( osc_buffer, OUTPUT_BUFFER_SIZE );
p << osc::BeginBundleImmediate;
p << osc::BeginMessage( "/new_user" );
p << (int)nId;
p << osc::EndMessage;
p << osc::EndBundle;
transmitSocket->Send(p.Data(), p.Size());
}
// Callback: An existing user was lost
void XN_CALLBACK_TYPE User_LostUser(xn::UserGenerator& generator, XnUserID nId, void* pCookie) {
printf("Lost user %d\n", nId);
if (kitchenMode) return;
osc::OutboundPacketStream p( osc_buffer, OUTPUT_BUFFER_SIZE );
p << osc::BeginBundleImmediate;
p << osc::BeginMessage( "/lost_user" );
p << (int)nId;
p << osc::EndMessage;
p << osc::EndBundle;
transmitSocket->Send(p.Data(), p.Size());
}
// Callback: Detected a pose
void XN_CALLBACK_TYPE UserPose_PoseDetected(xn::PoseDetectionCapability& capability, const XnChar* strPose, XnUserID nId, void* pCookie)
{
printf("Pose %s detected for user %d\n", strPose, nId);
userGenerator.GetPoseDetectionCap().StopPoseDetection(nId);
userGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
}
the error is as follows-
Error 54 error LNK2019: unresolved external symbol "public: __cdecl osc::OutboundPacketStream::~OutboundPacketStream(void)" (??1OutboundPacketStream#osc##QEAA#XZ) referenced in function "void __cdecl User_NewUser(class xn::UserGenerator &,unsigned int,void *)" (?User_NewUser##YAXAEAVUserGenerator#xn##IPEAX#Z) G:\project\pclsceleton\build\pclsceleton.obj pclsceleton
Error 55 error LNK2019: unresolved external symbol "public: void __cdecl UdpSocket::Send(char const *,int)" (?Send#UdpSocket##QEAAXPEBDH#Z) referenced in function "void __cdecl User_NewUser(class xn::UserGenerator &,unsigned int,void *)" (?User_NewUser##YAXAEAVUserGenerator#xn##IPEAX#Z) G:\project\pclsceleton\build\pclsceleton.obj pclsceleton
Error 56 error LNK2019: unresolved external symbol "public: char const * __cdecl osc::OutboundPacketStream::Data(void)const " (?Data#OutboundPacketStream#osc##QEBAPEBDXZ) referenced in function "void __cdecl User_NewUser(class xn::UserGenerator &,unsigned int,void *)" (?User_NewUser##YAXAEAVUserGenerator#xn##IPEAX#Z) G:\project\pclsceleton\build\pclsceleton.obj pclsceleton
Related
I have just tried to add a second DDX_CBWordIndex to my header file:
#pragma once
#include "stdafx.h"
template<typename E>
void AFXAPI DDX_RadioEnum(CDataExchange* pDX, int nIDC, E& value)
{
if (pDX == nullptr)
return;
// (1) Prepare the control for data exchange
pDX->PrepareCtrl(nIDC);
HWND hWndCtrl;
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
// (2) Make sure this routine is associated with the first
// radio button in a radio button group
ASSERT(::GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP);
// And verify, that it is indeed a radio button
ASSERT(::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON);
// (3) Iterate over all radio buttons in this group
using value_t = std::underlying_type_t<E>;
value_t rdbtn_index{};
do {
if (::SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0L) & DLGC_RADIOBUTTON) {
// (4) Control is a radio button
if (pDX->m_bSaveAndValidate) {
// (5) Transfer data from UI to class member
if (::SendMessage(hWndCtrl, BM_GETCHECK, 0, 0L) != 0) {
value = static_cast<E>(rdbtn_index);
}
}
else {
// (6) Transfer data from class member to UI
::SendMessage(hWndCtrl, BM_SETCHECK,
(static_cast<E>(rdbtn_index) == value), 0L);
}
++rdbtn_index;
}
else {
// (7) Not a radio button -> Issue warning
TRACE(traceAppMsg, 0,
"Warning: skipping non-radio button in group.\n");
}
// (8) Move to next control in tab order
hWndCtrl = ::GetWindow(hWndCtrl, GW_HWNDNEXT);
}
// (9) Until there are no more, or we moved to the next group
while (hWndCtrl != nullptr && !(GetWindowLong(hWndCtrl, GWL_STYLE) & WS_GROUP));
}
template<typename E>
void AFXAPI DDX_CBIndexEnum(CDataExchange* pDX, int nIDC, E& value)
{
pDX->PrepareCtrl(nIDC);
HWND hWndCtrl;
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
if (pDX->m_bSaveAndValidate)
value = static_cast<E>(::SendMessage(hWndCtrl, CB_GETCURSEL, 0, 0L));
else
::SendMessage(hWndCtrl, CB_SETCURSEL, static_cast<WPARAM>(value), 0L);
}
void AFXAPI DDX_CBWordIndex(CDataExchange* pDX, int nIDC, WORD& index)
{
pDX->PrepareCtrl(nIDC);
HWND hWndCtrl;
pDX->m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
if (pDX->m_bSaveAndValidate)
index = (WORD)::SendMessage(hWndCtrl, CB_GETCURSEL, 0, 0L);
else
::SendMessage(hWndCtrl, CB_SETCURSEL, (WPARAM)index, 0L);
}
I am using #pragma once. But this will not compile:
7>ImportFromCLMExplorerDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)"
(?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined in
AssignHistoryDlg.obj
7>OtherSettingsAutomaticBackupPage.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined in
AssignHistoryDlg.obj
7>ChristianLifeMinistryPersonalCopiesDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short
&)" (?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined
in AssignHistoryDlg.obj
7>ChristianLifeMinistryEditorDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined in
AssignHistoryDlg.obj
7>ChristianLifeMinistryStudentMaterialDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short
&)" (?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined
in AssignHistoryDlg.obj
7>ClearAssignmentsDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)"
(?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined in
AssignHistoryDlg.obj
7>InsertDateDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)"
(?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined in
AssignHistoryDlg.obj
7>OptionsDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)"
(?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined in
AssignHistoryDlg.obj
7>OtherSettingsUpdatePage.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)"
(?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined in
AssignHistoryDlg.obj
7>SpecialEventBethelSpeakerServiceTalkDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short
&)" (?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined
in AssignHistoryDlg.obj
7>SpecialEventVideoconferenceInfoDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)" (?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined in
AssignHistoryDlg.obj
7>SMCustomizeDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)"
(?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined in
AssignHistoryDlg.obj
7>SpecialEventDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)"
(?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined in
AssignHistoryDlg.obj
7>SpecialEventManager.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)"
(?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined in
AssignHistoryDlg.obj
7>UpdateCalendarDlg.obj : error LNK2005: "void __cdecl DDX_CBWordIndex(class CDataExchange *,int,unsigned short &)"
(?DDX_CBWordIndex##YAXPEAVCDataExchange##HAEAG#Z) already defined in
AssignHistoryDlg.obj
I don't understand why it complains because the function is only defined once.
I have been trying to use the GetStagedPackageOrigin() to get the origin of a specific application in my system.
But my program is not compiling because of an unresolved external error.
Error LNK2019 : unresolved external symbol __imp__GetStagedPackageOrigin#8 referenced in function "void __cdecl check(wchar_t const *)" (?check##YAXPB_W#Z)
Here is my code:
void check(__in PCWSTR fullName)
{
PackageOrigin origin;
LONG rc = GetStagedPackageOrigin(fullName, &origin);
if (rc == ERROR_SUCCESS)
{
static PCWSTR originstring[] = {L"Unknown",L"Unsigned",L"Inbox",L"Store",L"DeveloperUnsigned",L"DeveloperSigned",L"LineOfBusiness" };
PCWSTR str = originstring[origin];
wcout << str << endl;
}
}
Why does this error keep coming and is there any way to resolve that?
I used dumpbin command in the visual studio command prompt and that function was not being exported from kernel32.dll. The function was not present in the dll in the first place.
I think that is why the error occured.
To reproduce the issue,
Create a project > VC++ > CLR > Class library, name the project "ClassLibrary2" and use below two files as is.
// ClassLibrary2.h
#pragma once
#include <msclr\marshal.h>
#include <ShObjIdl.h>
using namespace System;
namespace ClassLibrary2 {
public ref class Class1
{
public : void ClassLibrary2::Class1::GetAllOpenWithProgs(String^ ext);
};
}
// ClassLibrary2.cpp
// This is the main DLL file.
#include "stdafx.h"
#include "ClassLibrary2.h"
void ClassLibrary2::Class1::GetAllOpenWithProgs(String^ ext)
{
msclr::interop::marshal_context ^ context = gcnew msclr::interop::marshal_context();
PCWSTR pszStr = context->marshal_as<const wchar_t*>(ext);
IEnumAssocHandlers *pEnumHandlers = NULL;
/* below line is producing problems */
SHAssocEnumHandlers(pszStr, ASSOC_FILTER_RECOMMENDED, &pEnumHandlers);
}
Now, if I build the project, I get following errors :
Error 2 error LNK2028: unresolved token (0A0000A2) "extern "C" long
__cdecl SHAssocEnumHandlers(wchar_t const *,enum ASSOC_FILTER,struct IEnumAssocHandlers * *)"
(?SHAssocEnumHandlers##$$J0YAJPEB_WW4ASSOC_FILTER##PEAPEAUIEnumAssocHandlers###Z)
referenced in function "public: void __clrcall
ClassLibrary2::Class1::GetAllOpenWithProgs(class System::String ^)"
(?GetAllOpenWithProgs#Class1#ClassLibrary2##$$FQE$AAMXPE$AAVString#System###Z) C:\Users\Anjum\Documents\Visual
Studio
2012\Projects\WpfApplication2\ClassLibrary2\ClassLibrary2.obj ClassLibrary2
Error 3 error LNK2019: unresolved external symbol "extern "C" long
__cdecl SHAssocEnumHandlers(wchar_t const *,enum ASSOC_FILTER,struct IEnumAssocHandlers * *)"
(?SHAssocEnumHandlers##$$J0YAJPEB_WW4ASSOC_FILTER##PEAPEAUIEnumAssocHandlers###Z)
referenced in function "public: void __clrcall
ClassLibrary2::Class1::GetAllOpenWithProgs(class System::String ^)"
(?GetAllOpenWithProgs#Class1#ClassLibrary2##$$FQE$AAMXPE$AAVString#System###Z) C:\Users\Anjum\Documents\Visual
Studio
2012\Projects\WpfApplication2\ClassLibrary2\ClassLibrary2.obj ClassLibrary2
How to remove those linker errors ?
I am trying to create a simple C++ class and a Matlab mex file. My code is as follows:
Matlab: mexTest1.cpp
#include "mex.h"
#include "K:\\My Documents\\Visual Studio 2010\\Projects\\HelloWorld\\HelloWorld\\Class1.h"
/* Input Arguments */
#define X prhs[0]
/* Output Arguments */
#define RESULT plhs[0]
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] ){
/* Initialize input and output pointers
// Inputs */
double *x;
/* Outputs */
double r;
double *result;
mwSize m,n;
m = mxGetM(X);
n = mxGetN(X);
/* Create a matrix for the return argument */
RESULT = mxCreateDoubleMatrix(1, 1, mxREAL);
/* Assign pointers to the various parameters */
result = mxGetPr(RESULT);
x = mxGetPr(X);
/* Do the actual computations in a subroutine */
Class1 c1(2, 15.0);
r = c1.product();
result[0] = r;
return;
}
Class1.h:
#pragma once
#include <string> // Standard string class in C++
class Class1
{
public:
int a;
double b;
public:
Class1(const int& a, const double& b);
//virtual ~Class1();
void print() const;
double product() const;
};
Class1.cpp:
#include "stdafx.h"
#include <iostream>
#include "Class1.h"
Class1::Class1(const int& a, const double& b){
Class1::a = a;
Class1::b = b;
}
void Class1::print() const{
std::cout << "a=" << Class1::a << " * b=" << Class1::b << " = " << Class1::product() << std::endl;
}
double Class1::product() const{
return a*b;
}
Running the Matlab command mex mexTest1.cpp gives the error messages:
Creating library C:\DOCUME~1\K\LOCALS~1\TEMP\MEX_RH~1\templib.x and object C:\DOCUME~1\K\LOCALS~1\TEMP\MEX_RH~1\templib.exp
mexTest1.obj : error LNK2019: unresolved external symbol "public: double __thiscall Class1::product(void)const " (?product#Class1##QBENXZ) referenced in function _mexFunction
mexTest1.obj : error LNK2019: unresolved external symbol "public: __thiscall Class1::Class1(int const &,double const &)" (??0Class1##QAE#ABHABN#Z) referenced in function _mexFunction
mexTest1.mexw32 : fatal error LNK1120: 2 unresolved externals
C:\PROGRA~1\MATLAB\R2011A\BIN\MEX.PL: Error: Link of 'mexTest1.mexw32' failed.
??? Error using ==> mex at 208
Unable to complete successfully.
Can anyone help me fix this problem?
Thanks.
The linker is telling you that in trying to construct an executable, it wasn't supplied with an object file that contains Class1::product and Class1::Class1. That's because those functions would be supplied by compiling Class1.cpp, which your command line doesn't ask for.
You should use the syntax of mex for multiple files: mex mexTest1.cpp Class1.cpp
Your linker is unable to find deinitions(bodies) Class1 methods (constructor and product). This may be due to
You haven't provided any definition(body)
The definitions are in a lib file which you forgot to link to
I have a simple logger that is implemented as a singleton. It works like i want when I compile and run it with g++ in linux but when I compile in Visual Studio 9.0 with vc++ I get the following errors. Is there a way to fix this? I don't mind changing the logger class around, but I would like to avoid changing how it is called.
1>Linking...
1>loggerTest.obj : error LNK2005: "public: static class Logger * __cdecl Logger::getInstance(void)" (?getInstance#Logger##SAPAV1#XZ) already defined in Logger.obj
1>loggerTest.obj : error LNK2005: "public: void __thiscall Logger::log(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?log#Logger##QAEXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) already defined in Logger.obj
1>loggerTest.obj : error LNK2005: "public: void __thiscall Logger::closeLog(void)" (?closeLog#Logger##QAEXXZ) already defined in Logger.obj
1>loggerTest.obj : error LNK2005: "private: static class Logger * Logger::_instance" (?_instance#Logger##0PAV1#A) already defined in Logger.obj
1>Logger.obj : error LNK2001: unresolved external symbol "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > Logger::_path" (?_path#Logger##0V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##A)
1>loggerTest.obj : error LNK2001: unresolved external symbol "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > Logger::_path" (?_path#Logger##0V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##A)
1>Logger.obj : error LNK2001: unresolved external symbol "private: static class boost::mutex Logger::_mutex" (?_mutex#Logger##0Vmutex#boost##A)
1>loggerTest.obj : error LNK2001: unresolved external symbol "private: static class boost::mutex Logger::_mutex" (?_mutex#Logger##0Vmutex#boost##A)
1>Logger.obj : error LNK2001: unresolved external symbol "private: static class std::basic_ofstream<char,struct std::char_traits<char> > Logger::_log" (?_log#Logger##0V?$basic_ofstream#DU?$char_traits#D#std###std##A)
1>loggerTest.obj : error LNK2001: unresolved external symbol "private: static class std::basic_ofstream<char,struct std::char_traits<char> > Logger::_log" (?_log#Logger##0V?$basic_ofstream#DU?$char_traits#D#std###std##A)
The code, three files Logger.h Logger.cpp test.cpp
#ifndef __LOGGER_CPP__
#define __LOGGER_CPP__
#include "Logger.h"
Logger* Logger::_instance = 0;
//string Logger::_path = "log";
//ofstream Logger::_log;
//boost::mutex Logger::_mutex;
Logger* Logger::getInstance(){
{
boost::mutex::scoped_lock lock(_mutex);
if(_instance == 0) {
_instance = new Logger;
_path = "log";
}
} //mutex
return _instance;
}
void Logger::log(const std::string& msg){
{
boost::mutex::scoped_lock lock(_mutex);
if(!_log.is_open()){
_log.open(_path.c_str());
}
if(_log.is_open()){
_log << msg.c_str() << std::endl;
}
}
}
void Logger::closeLog(){
Logger::_log.close();
}
#endif
` ...
#ifndef __LOGGER_H__
#define __LOGGER_H__
#include <iostream>
#include <string>
#include <fstream>
#include <boost/thread/mutex.hpp>
#include <boost/thread.hpp>
using namespace std;
class Logger {
public:
static Logger* getInstance();
void log(const std::string& msg);
void closeLog();
protected:
Logger(){}
private:
static Logger* _instance;
static string _path;
static bool _logOpen;
static ofstream _log;
static boost::mutex _mutex; //check mutable
};
#endif
test.cpp
`
#include <iostream>
#include "Logger.cpp"
using namespace std;
int main(int argc, char *argv[])
{
Logger* log = Logger::getInstance();
log->log("hello world\n");
return 0;
}
This is a problem because you've defined the symbol multiple times by compiling the CPP then also including it in test.cpp... By convention you should only include the declaration, not the definition as you've done.
I am surprised that gcc would allow one to be so lax about this.
change
#include "Logger.cpp"
to
#include "Logger.h"
and give it a try.
The problem is because you have done #include "Logger.cpp" instead of #include "Logger.h" in test.cpp . Because of this, the symbols inside the Logger.cpp will be defined multiple times (once for the translation unit logger.cpp and once for test.cpp). Having multiple inclusion guard doesn't help because it works only within a translation unit.