unresolved external symbol

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]

Last edited on
Hello sizeof,

With out the code to look at it is hard to say what the problem is. Generally when I find these type of errors it starts somewhere in the source code not being able to locate a variable or function in the code file(s).

It could also be that a ".lib" file is not being linked because your settings are off and not finding the sub-directory where the ".lib" file is located.

My first thought is that it is in the source code somewhere.

Hope that helps,

Andy
Thanks. I have also searched google. Some people with the same question says that the lacking of lib causes this problem. But I do not know how to figure out which lib is lacking in my case?
Hello sizeof,

At the beginning of the file the "include" files generally do not make any difference as to order, but sometimes it does. I believe that the "include "stdafx.h" file needs to be the first file included in a program. Note: when posting code it is best to leave that file out of your post. A lot of people who may use some version of VS are more likely to create an empty project to put your code in as opposed to what you are doing.

By the time I get to the lines:
1
2
#include "IUmeasure.h"
#include <Python.h> 

I do not have "IUmeasure.h" to include and "Python.h" is not in my VS 2017 or in my VS 2015 include directory.

I do not know about VS 2010, but I would check the include directory and make sure the "Python.h" is there first. you might even try a search of the C drive and see if it shows up somewhere else. I will see if I can find a "Python.h" file.

When you post code like this it is best to include the header file so that whom ever is helping will have all the information need to compile the program.

Right now the error messages I am receiving are completely different because of the files I do not have.

Andy
Topic archived. No new replies allowed.