undefined reference to `SetPduPowerConsumptionCnt''錯誤的解決方案

來源:互聯網
上載者:User

編譯時間出現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編輯器時,沒有設定區分大小寫,導致沒有很容易一眼看出 來。

修改之後,成功編譯。
問題解決。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.