0
我在Visual C++ 6(我沒有選擇該工具)上遇到這種奇怪的鏈接器錯誤。我甚至不知道從哪裏開始尋找這個(我有限的C++經驗)。這些都是錯誤的:在Python嵌入項目上的VC++ 6「無法解析的外部」
CScripting.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CScripting::~CScripting(void)" ([email protected]@[email protected])
CPythonPg.obj : error LNK2001: unresolved external symbol "private: static struct _object * CPythonPg::pyPgEnv" ([email protected]@@[email protected]@A)
這是CPythonPg.h:
#ifndef _CPYTHONPG_H_
#define _CPYTHONPG_H_
#include <sstream>
#include <Python.h>
#include "pgt.h"
using namespace std;
class CPythonPg {
private:
static PyObject* pyPgEnv;
public:
CPythonPg();
~CPythonPg();
protected:
static PyObject* getPyPgEnv(PGTYPE* pgt1, PGTYPE* pgt2);
};
#endif
這是CSripting.h:(我沒有創建這個類,而我不能改變它除了將實例添加到我的類CPythonPg)
#ifndef _CSCRIPTING_H_
#define _CSCRIPTING_H_
#include <string>
#include <vector>
#include <map>
#include <set>
#include <exception>
#include <sstream>
#include <fstream>
#include <locale>
#include <stdlib.h>
#include <direct.h>
#include <windows.h>
#include <io.h>
#include "pgt.h"
class CPythonPg; // added for python functionality
using namespace std;
class CScripting {
private:
string sMod;
string sCust;
string sProf;
string sScript;
CPythonPg* pyInst; // added for python functionality
typedef vector<pair<string, string> > cmdLines_t;
cmdLines_t vCmdLines;
bool bFoundPy; // added for python functionality
public:
typedef map<string, string> catalog_t;
typedef map<string, string> envVars_t;
CScripting(){};
CScripting(string _sMod, string _sCust, string _sProf, string _sScript, PGTYPE* Pgt1, PGTYPE* Pgt2);
virtual ~CScripting();
int findProcessingScripts();
void run(envVars_t& mEnvVars);
};
#endif
什麼會導致這種類型的錯誤?
編輯:修正了一些錯別字。
您聲明靜態稱爲'pyPgEnv'但不能確定它已經定義。在你的CPythonPgsm.cpp文件中添加'PyObject * CPythonPg :: pyPgEnv;'。這應該解決第一個錯誤。第二個錯誤看起來像包含了CScripting.h,它聲明瞭'CScripting'的析構函數,但它沒有在任何cpp文件中定義。看起來你需要在CScripting.cpp中定義它,或者可能已經在另一個cpp中定義了哪些不包含哪些? – 2013-05-08 22:38:47
優秀。我正在聲明一個靜態的'pyPgEnv',但沒有定義它。添加'PyObject * CPythonPg :: pyPgEnv;'到CPythonPg.cpp並解決了這個問題。今天學到了新東西。在析構函數'CScripting'上,它已經被定義了。當我添加「pyPgEnv」的定義時(第一個錯誤),錯誤消失了。謝謝! (如果您將此作爲正確答案,我會盡可能選擇)。 – 2013-05-09 14:51:51