Problem:
The program model is written in C + + language, and an interface file Modelc.cpp is added between the program model and the call function, which is used to call the function in the program model with C language program.
A new addition of two functions setpdupowerconsumptioncnt () and Setpdupowerconsumptiontot () is used to clear the total power and power counter in the PDU model;
Error message at compile time:
Copy Code code as follows:
dingq@wd-u1110:~/hwsvn/2sw/1prj_linux/pdu/src/branches/pdu-isocket$ make Clean;make
rm-f *.o PDU
arm-linux-g++-g3-wall-o0-i. /.. /.. /tools/eldk42/arm/usr/include/-I.. /.. /.. /TOOLS/ELDK42/ARM/USR/INCLUDE/C++/4.2.2/-C Main.cpp-o MAIN.O
arm-linux-g++-g3-wall-o0-i. /.. /.. /tools/eldk42/arm/usr/include/-I.. /.. /.. /TOOLS/ELDK42/ARM/USR/INCLUDE/C++/4.2.2/-C Model.cpp-o MODEL.O
arm-linux-g++-g3-wall-o0-i. /.. /.. /tools/eldk42/arm/usr/include/-I.. /.. /.. /TOOLS/ELDK42/ARM/USR/INCLUDE/C++/4.2.2/-C Modelc.cpp-o MODELC.O
arm-linux-g++-g3-wall-o0-i. /.. /.. /tools/eldk42/arm/usr/include/-I.. /.. /.. /TOOLS/ELDK42/ARM/USR/INCLUDE/C++/4.2.2/-C Inifile.cpp-o INIFILE.O
arm-linux-g++-g3-wall-o0-i. /.. /.. /tools/eldk42/arm/usr/include/-I.. /.. /.. /TOOLS/ELDK42/ARM/USR/INCLUDE/C++/4.2.2/-C Clientsocket.cpp-o CLIENTSOCKET.O
arm-linux-g++-g3-wall-o0-i. /.. /.. /tools/eldk42/arm/usr/include/-I.. /.. /.. /TOOLS/ELDK42/ARM/USR/INCLUDE/C++/4.2.2/-C Thread.cpp-o THREAD.O
arm-linux-g++-g3-wall-o0-i. /.. /.. /tools/eldk42/arm/usr/include/-I.. /.. /.. /TOOLS/ELDK42/ARM/USR/INCLUDE/C++/4.2.2/-C Sensorreader.cpp-o sensorreader.o
arm-linux-g++-g3-wall-o0-i. /.. /.. /tools/eldk42/arm/usr/include/-I.. /.. /.. /TOOLS/ELDK42/ARM/USR/INCLUDE/C++/4.2.2/-C Lcdwriter.cpp-o lcdwriter.o
arm-linux-g++-g3-wall-o0-i. /.. /.. /tools/eldk42/arm/usr/include/-I.. /.. /.. /TOOLS/ELDK42/ARM/USR/INCLUDE/C++/4.2.2/-C Monitor.cpp-o monitor.o
arm-linux-g++-g3-wall-o0-i. /.. /.. /tools/eldk42/arm/usr/include/-I.. /.. /.. /TOOLS/ELDK42/ARM/USR/INCLUDE/C++/4.2.2/-C Helper.cpp-o helper.o
arm-linux-g++-g3-wall-o0-i. /.. /.. /tools/eldk42/arm/usr/include/-I.. /.. /.. /TOOLS/ELDK42/ARM/USR/INCLUDE/C++/4.2.2/-C Mutex.cpp-o MUTEX.O
arm-linux-g++-g3-wall-o0-i. /.. /.. /tools/eldk42/arm/usr/include/-I.. /.. /.. /TOOLS/ELDK42/ARM/USR/INCLUDE/C++/4.2.2/-C Serial.cpp-o SERIAL.O
arm-linux-gcc-g3-wall-o0-c frm_package.c-o FRM_PACKAGE.O
arm-linux-gcc-g3-wall-o0-c nettrans.c-o NETTRANS.O
arm-linux-gcc-g3-wall-o0-c sensor-att7053.c-o sensor-att7053.o
arm-linux-g++-L. /.. /.. /tools/lib/-lpthread-o PDU main.o model.o modelc.o inifile.o clientsocket.o thread.o sensorreader.o LcdWriter.o Monitor. o helper.o mutex.o serial.o frm_package.o nettrans.o sensor-att7053.o
sensor-att7053.o:in function ' Reset_energyport ':
/home/dingq/hwsvn/2sw/1prj_linux/pdu/src/branches/pdu-isocket/sensor-att7053.c:83:undefined reference to ' Setpdupowerconsumptioncnt '
/home/dingq/hwsvn/2sw/1prj_linux/pdu/src/branches/pdu-isocket/sensor-att7053.c:92:undefined reference to ' Setpdupowerconsumptiontot '
Collect2:ld returned 1 exit status
Make: * * * [PDU] Error 1
Solution:
1. Forgot to add extern "C" to the Modelc.cpp function implementation.
Copy Code code as follows:
extern "C" int setpdupowerconsumptioncnt (int index, unsigned int val) {
if (Index > 8 | | Index < 1) {
printf ("Error:the index available is between 1 and 8.\n");
return-1;
}
Model->channels () [index-1]. Theenergyport (). Setpowerconsumptioncount (Val);
return 0;
}
after adding, compile again, error still exists.
looked for half a day, The original header file modelc.h and implementation file modelc.cpp The function name is a symbol, the header file is lowercase s,setpdupowerconsumptioncnt, and the implementation of the file with the capital of the s,setpdupowerconsumptioncnt, and the use of VI M editor when not set to case-sensitive, resulting in no easy to see out.
After modification, compile successfully.
Solve the problem.