gpt4 book ai didi

undefined reference to `SetPduPowerConsumptionCnt'错误的解决方法

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 24 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章undefined reference to `SetPduPowerConsumptionCnt'错误的解决方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

问题: 程序模型用C++语言编写,在程序模型和调用函数之间添加了一个接口文件modelc.cpp,用来让用c语言程序调用程序模型中的函数; 。

新添加了两个函数setPduPowerConsumptionCnt()和setPduPowerConsumptionTot(),用来清除PDU模型中的总功耗和功耗计数器; 。

编译时出现错误提示:

复制代码 代码如下:

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

解决办法: 1. 忘了在modelc.cpp的函数实现中添加extern "C"了.

复制代码 代码如下:

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; } 。

添加之后,再次编译,错误仍然存在。 查找了半天,原来头文件modelc.h中和实现文件modelc.cpp中的函数名差了一个符号,头文件中是小写的s,setPduPowerConsumptionCnt,而实现文件中用了大写的S,SetPduPowerConsumptionCnt;而使用vim编辑器时,没有设定区分大小写,导致没有很容易一眼看出来.

  。

修改之后,成功编译。 问题解决.

最后此篇关于undefined reference to `SetPduPowerConsumptionCnt'错误的解决方法的文章就讲到这里了,如果你想了解更多关于undefined reference to `SetPduPowerConsumptionCnt'错误的解决方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com