Undefined reference to ' setpdupowerconsumptioncnt ' the wrong solution

Source: Internet
Author: User
Tags mutex
Compile-time appears undefined reference to ' setpdupowerconsumptioncnt ' error How to solve it? Is there any good way to solve it? The following small series for everyone to answer it, if you have encountered this situation, you can come to refer to the next

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. Forget 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, and the error still exists.
Looking for a half-day, the original header file modelc.h and implementation file Modelc.cpp function name is a symbol, the header file is lowercase s,setpdupowerconsumptioncnt, and the implementation file with the capital of S, setpdupowerconsumptioncnt while using the Vim editor, there is no case sensitivity, resulting in no easy to see.

After modification, compile successfully.
Solve the problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.