Write your question here.
VS 2010. When I tried to compile a C++ MFC project. There seems exists a lacking of lib when linking libs. But I do not know which lib is missing and how to fix it.
Both IUmeasurec.cpp and .h are written by myself.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include "stdafx.h"
#include <string>
#include "IUmeasure.h"
#include <Python.h>
using namespace std;
float read_current(void)
{
Py_Initialize();
string path = "~/include";
string chdir_cmd = string("sys.path.append(\"") + path + "\")";
const char* cstr_cmd = chdir_cmd.c_str();
PyRun_SimpleString("import sys");
PyRun_SimpleString(cstr_cmd);
PyObject* moduleName = PyString_FromString("include");
PyObject* pModule = PyImport_Import(moduleName);
if (!pModule)
{
cout << "[ERROR] Python get module failed." << endl;
return 0;
}
cout << "[INFO] Python get module succeed." << endl;
PyObject* pv = PyObject_GetAttrString(pModule, "read_current");
if (!pv || !PyCallable_Check(pv))
{
cout << "[ERROR] Can't find funftion (read_current)" << endl;
return 0;
}
cout << "[INFO] Get function (read_current) succeed." << endl;
PyObject* args = PyTuple_New(0);
PyObject* pRet = PyObject_CallObject(pv, args);
float result;
if (pRet)
{
result = PyInt_AsLong(pRet);
}
Py_Finalize();
return result;
}
float read_voltage(void)
{
Py_Initialize();
string path = "~/include";
string chdir_cmd = string("sys.path.append(\"") + path + "\")";
const char* cstr_cmd = chdir_cmd.c_str();
PyRun_SimpleString("import sys");
PyRun_SimpleString(cstr_cmd);
PyObject* moduleName = PyString_FromString("include");
PyObject* pModule = PyImport_Import(moduleName);
if (!pModule)
{
cout << "[ERROR] Python get module failed." << endl;
return 0;
}
cout << "[INFO] Python get module succeed." << endl;
PyObject* pv = PyObject_GetAttrString(pModule, "read_voltage");
if (!pv || !PyCallable_Check(pv))
{
cout << "[ERROR] Can't find funftion (read_current)" << endl;
return 0;
}
cout << "[INFO] Get function (read_current) succeed." << endl;
PyObject* args = PyTuple_New(0);
PyObject* pRet = PyObject_CallObject(pv, args);
float result;
if (pRet)
{
result = PyInt_AsLong(pRet);
}
Py_Finalize();
return result;
}
[code]// IUmeasure.h : main header file for the I, U measuring application
#if !defined(IUmeasure_H)
#define IUmeasure_H
#include <iostream>
using namespace std;
extern float read_current();
extern float read_voltage();
#endif
|
ERROR:
1>ComSetting.obj : error LNK2001: unresolved external symbol "public: void __thiscall CComSetting::OnCbnSelchangeComAux(void)" (?OnCbnSelchangeComAux@CComSetting@@QAEXXZ)
1>ComSetting.obj : error LNK2001: unresolved external symbol "public: void __thiscall CComSetting::OnCbnSelchangeBaudRate(void)" (?OnCbnSelchangeBaudRate@CComSetting@@QAEXXZ)
1>ComSetting.obj : error LNK2001: unresolved external symbol "int i" (?i@@3HA)
1>ControllerDlg.obj : error LNK2001: unresolved external symbol "public: void __thiscall CControllerDlg::OnEnChangeScannedaddr(void)" (?OnEnChangeScannedaddr@CControllerDlg@@QAEXXZ)
1>ControllerDlg.obj : error LNK2001: unresolved external symbol "public: void __thiscall CControllerDlg::OnEnChangeEditRecv(void)" (?OnEnChangeEditRecv@CControllerDlg@@QAEXXZ)
1>SearchDevice.obj : error LNK2001: unresolved external symbol "public: void __thiscall CSearchDevice::OnLbnSelchangeListdevice(void)" (?OnLbnSelchangeListdevice@CSearchDevice@@QAEXXZ)
1>IUmeasure.obj : error LNK2019: unresolved external symbol _Py_Finalize referenced in function "float __cdecl read_current(void)" (?read_current@@YAMXZ)
1>IUmeasure.obj : error LNK2019: unresolved external symbol _PyInt_AsLong referenced in function "float __cdecl read_current(void)" (?read_current@@YAMXZ)
1>IUmeasure.obj : error LNK2019: unresolved external symbol _PyObject_CallObject referenced in function "float __cdecl read_current(void)" (?read_current@@YAMXZ)
1>IUmeasure.obj : error LNK2019: unresolved external symbol _PyTuple_New referenced in function "float __cdecl read_current(void)" (?read_current@@YAMXZ)
1>IUmeasure.obj : error LNK2019: unresolved external symbol _PyCallable_Check referenced in function "float __cdecl read_current(void)" (?read_current@@YAMXZ)
1>IUmeasure.obj : error LNK2019: unresolved external symbol _PyObject_GetAttrString referenced in function "float __cdecl read_current(void)" (?read_current@@YAMXZ)
1>IUmeasure.obj : error LNK2019: unresolved external symbol _PyImport_Import referenced in function "float __cdecl read_current(void)" (?read_current@@YAMXZ)
1>IUmeasure.obj : error LNK2019: unresolved external symbol _PyString_FromString referenced in function "float __cdecl read_current(void)" (?read_current@@YAMXZ)
1>IUmeasure.obj : error LNK2019: unresolved external symbol _PyRun_SimpleStringFlags referenced in function "float __cdecl read_current(void)" (?read_current@@YAMXZ)
1>IUmeasure.obj : error LNK2019: unresolved external symbol _Py_Initialize referenced in function "float __cdecl read_current(void)" (?read_current@@YAMXZ)
1>SPTNFCSettings.obj : error LNK2001: unresolved external symbol "public: void __thiscall CSPTNFCSettings::OnBnClickedAutoanswercheckbox(void)" (?OnBnClickedAutoanswercheckbox@CSPTNFCSettings@@QAEXXZ)
[/code]