我不明白爲什麼我有這個未定義的引用錯誤。函數和file.cpp和file.h的所有定義都已更正,並且位於正確的目錄路徑中。我用這種方式編譯:未定義的引用和collect2:錯誤:ld返回1
c++ -std=c++11 testpad.cpp RPCgen_i2cprg/ad74.cpp RPCgen_i2cprg/Cma.cpp RPCgen_i2cprg/Cmapad.cpp RPCgen_i2cprg/fpad.cpp RPCgen_i2cprg/i2cConfDict.cpp RPCgen_i2cprg/i2cdev.cpp RPCgen_i2cprg/i2creg.cpp RPCgen_i2cprg/i2cRegList.cpp RPCgen_i2cprg/lm75.cpp RPCgen_i2cprg/pad.cpp RPCgen_i2cprg/PadBoard.cpp RPCgen_i2cprg/PadConfigurator.cpp RPCgen_i2cprg/padDefine.cpp RPCgen_i2cprg/PadDev.cpp RPCgen_i2cprg/PadDeviceMap.cpp RPCgen_i2cprg/PadMeasures.cpp RPCgen_i2cprg/PadPowerSwitch.cpp RPCgen_i2cprg/pcf8575.cpp RPCgen_i2cprg/prode.cpp RPCgen_i2cprg/SectorConfigurator.cpp RPCgen_i2cprg/ttcrx.cpp RPCi2ccan/CanChanFactory.cpp RPCi2ccan/i2cCanNode.cpp
和g ++但沒有。這是我彙編的輸出錯誤:
/tmp/usertest/ccQQ70by.o: In function `CanChanFactory::getChannel(int, unsigned short, int)':
CanChanFactory.cpp:(.text+0x151): undefined reference to `CanInterface::newCanInterface(int, int, int, bool)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::initChannel()':
i2cCanNode.cpp:(.text+0xa9): undefined reference to `CanNodeFactory::instance()'
i2cCanNode.cpp:(.text+0xc6): undefined reference to `CanNodeFactory::getCanNode(int)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::getELMBFirmwareVersion(unsigned char*)':
i2cCanNode.cpp:(.text+0x161): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0x178): undefined reference to `getFirmwareVersion(CanNode*, unsigned char*)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::getELMBHardwareVersion(unsigned char*)':
i2cCanNode.cpp:(.text+0x1a7): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0x1be): undefined reference to `getHardwareVersion(CanNode*, unsigned char*)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::NMTResetNode()':
i2cCanNode.cpp:(.text+0x26a): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0x27f): undefined reference to `CanNode::nmt(int)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::fast_init(int, int&)':
i2cCanNode.cpp:(.text+0x33a): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0x361): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x3c3): undefined reference to `COP_ReadSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x476): undefined reference to `COP_ReadSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::read_error(unsigned char*)':
i2cCanNode.cpp:(.text+0x579): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0x5a9): undefined reference to `read_init_error(CanNode*, int, int, unsigned char*)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::check_locks(int)':
i2cCanNode.cpp:(.text+0x5e4): undefined reference to `read_check_locks(CanNode*, int)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::read_i2c(int, unsigned char, unsigned char, unsigned char*)':
i2cCanNode.cpp:(.text+0x77e): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0x7a4): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x805): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x884): undefined reference to `COP_ReadSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x8ea): undefined reference to `COP_ReadSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::read_i2c_nomsg(int, unsigned char, unsigned char, unsigned char*)':
i2cCanNode.cpp:(.text+0xa0c): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0xa32): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0xa77): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0xada): undefined reference to `COP_ReadSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0xb2b): undefined reference to `COP_ReadSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::write_i2c(int, unsigned char, unsigned char, unsigned char*)':
i2cCanNode.cpp:(.text+0xbd4): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0xc20): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0xc81): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0xcf0): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0xd61): undefined reference to `COP_ReadSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::write_i2c_nomsg(int, unsigned char, unsigned char, unsigned char*)':
i2cCanNode.cpp:(.text+0xe2e): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0xe81): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0xec6): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0xf19): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0xf72): undefined reference to `COP_ReadSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::write_i2c_suba(int, unsigned char, unsigned char, unsigned char, unsigned char*)':
i2cCanNode.cpp:(.text+0xfde): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0x1020): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x1081): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x10e2): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x115b): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x11ca): undefined reference to `COP_ReadSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::read_i2c_suba(int, unsigned char, unsigned char, unsigned char, unsigned char*)':
i2cCanNode.cpp:(.text+0x12d2): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0x1321): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x1382): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x13e3): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x145b): undefined reference to `COP_ReadSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
i2cCanNode.cpp:(.text+0x14c1): undefined reference to `COP_ReadSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::cmreset()':
i2cCanNode.cpp:(.text+0x15b5): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0x15dc): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::xilinx_init()':
i2cCanNode.cpp:(.text+0x1655): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0x167b): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
/tmp/usertest/ccSmDSn9.o: In function `i2cCanNode::polar_init()':
i2cCanNode.cpp:(.text+0x16ed): undefined reference to `CanNode::setNodeId(int)'
i2cCanNode.cpp:(.text+0x1714): undefined reference to `COP_WriteSDO(CanNode*, int, int, unsigned char*, unsigned char*)'
collect2: error: ld returned 1 exit status
有什麼麻煩?謝謝。
你是什麼意思,「用g ++但沒有」?什麼操作系統?當你輸入'哪個C++'和'哪個g ++'時,你會得到什麼? –
使用g ++我已經這樣做了:g ++ -std = C++ 11 testpad.cpp RPCgen_i2cprg/ad74.cpp RPCgen_i2cprg/Cma.cpp RPCgen_i2cprg/Cmapad.cpp RPCgen_i2cprg/fpad.cpp RPCgen_i2cprg/i2cConfDict.cpp RPCgen_i2cprg/i2cdev.cpp RPCgen_i2cprg /i2creg.cpp RPCgen_i2cprg/i2cRegList.cpp RPCgen_i2cprg/lm75.cpp RPCgen_i2cprg/pad.cpp RPCgen_i2cprg/PadBoard.cpp RPCgen_i2cprg/PadConfigurator.cpp RPCgen_i2cprg/padDefine.cpp RPCgen_i2cprg/PadDev.cpp RPCgen_i2cprg/PadDeviceMap.cpp RPCgen_i2cprg/PadMeasures.cpp RPCgen_i2cprg /PadPowerSwitch.cpp。操作系統是科學Linux 6和C++和g ++相同 –
這並不能回答我的問題。 –