我正在尝试构建一个包含外部/第三方依赖关系的程序,但我不断向我确定要链接的函数/对象收到undefined reference
错误:
g++ -m64 -pthread -ljpeg -lrt -s -o build/release/darwin_socket build/release/main.o build/release/DarwinRobot.o build/release/dyn_system.o build/release/writefilestuff.o -lCppController /usr/local/webots/resources/projects/robots/darwin-op/libraries/darwin/libdarwin.so ../../lib/OPKinematics/lib/libOPKinematics64.a -lpthread -lipsocket -lboost_system -lboost_serialization -lm -L"/usr/local/webots/lib" -lController -lCppController
build/release/DarwinRobot.o: In function `webots::DarwinRobot::DarwinRobot()':
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:63: undefined reference to `webots::Robot::getLED(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:65: undefined reference to `webots::Robot::getLED(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:72: undefined reference to `webots::Robot::getGyro(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:75: undefined reference to `webots::Robot::getAccelerometer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:78: undefined reference to `webots::Robot::getServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:80: undefined reference to `webots::Robot::getServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:88: undefined reference to `webots::Robot::getServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:90: undefined reference to `webots::Robot::getServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:101: undefined reference to `webots::Robot::getServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
build/release/DarwinRobot.o:/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:103: more undefined references to `webots::Robot::getServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' follow
build/release/DarwinRobot.o: In function `webots::DarwinRobot::DarwinRobot()':
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:118: undefined reference to `webots::Robot::getTouchSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:120: undefined reference to `webots::Robot::getTouchSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:139: undefined reference to `webots::Robot::getTouchSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:141: undefined reference to `webots::Robot::getTouchSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
build/release/DarwinRobot.o: In function `webots::DarwinRobot::savePosition()':
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:170: undefined reference to `webots::Supervisor::getFromDef(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:170: undefined reference to `webots::Node::getField(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:171: undefined reference to `webots::Supervisor::getFromDef(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:171: undefined reference to `webots::Node::getField(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:173: undefined reference to `webots::Supervisor::getFromDef(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o: In function `webots::DarwinRobot::checkFall()':
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:1007: undefined reference to `webots::Supervisor::getFromDef(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/home/code/cpp/darwin/controllers/darwin_socket/src/DarwinRobot.cpp:1007: undefined reference to `webots::Supervisor::getFromDef(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x48): undefined reference to `webots::Robot::createAccelerometer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x50): undefined reference to `webots::Robot::createCamera(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x58): undefined reference to `webots::Robot::createCompass(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x60): undefined reference to `webots::Robot::createConnector(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x68): undefined reference to `webots::Robot::createDisplay(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x70): undefined reference to `webots::Robot::createDistanceSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x78): undefined reference to `webots::Robot::createEmitter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x80): undefined reference to `webots::Robot::createGPS(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x88): undefined reference to `webots::Robot::createGyro(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x90): undefined reference to `webots::Robot::createInertialUnit(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x98): undefined reference to `webots::Robot::createLED(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xa0): undefined reference to `webots::Robot::createLightSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xa8): undefined reference to `webots::Robot::createMotor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xb0): undefined reference to `webots::Robot::createPen(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xb8): undefined reference to `webots::Robot::createPositionSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xc0): undefined reference to `webots::Robot::createReceiver(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xc8): undefined reference to `webots::Robot::createServo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xd0): undefined reference to `webots::Robot::createTouchSensor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0xf0): undefined reference to `webots::Supervisor::startMovie(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int, int, int, int, bool)'
build/release/DarwinRobot.o:(.rodata._ZTVN6webots11DarwinRobotE[_ZTVN6webots11DarwinRobotE]+0x100): undefined reference to `webots::Supervisor::setLabel(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double, double, double, int, double)'
collect2: error: ld returned 1 exit status
make: *** [/usr/local/webots/resources/Makefile.include:530: build/release/darwin_socket] Error 1
我特别确定这些对象是在libCppController.so
中定义的,由标志-lCppController
调用。手动检查共享对象文件(例如&#39; LED&#39;):
objdump -TC lib/libCppController.so | grep LED
0000000000021a8c g DF .text 0000000000000053 Base webots::Robot::createLED(std::string const&) const
00000000000225c6 w DF .text 0000000000000037 Base webots::LED::LED(std::string const&)
00000000000219da g DF .text 00000000000000b2 Base webots::Robot::getLED(std::string const&)
000000000001e074 g DF .text 000000000000002c Base webots::LED::set(int)
00000000000225c6 w DF .text 0000000000000037 Base webots::LED::LED(std::string const&)
000000000001e0a0 g DF .text 0000000000000024 Base webots::LED::get() const
0000000000024018 w DO .rodata 000000000000000e Base typeinfo name for webots::LED
000000000022b650 w DO .data.rel.ro 0000000000000018 Base typeinfo for webots::LED
000000000001e106 w DF .text 0000000000000026 Base webots::LED::~LED()
000000000001e0c4 w DF .text 0000000000000041 Base webots::LED::~LED()
000000000001e0c4 w DF .text 0000000000000041 Base webots::LED::~LED()
000000000022b620 w DO .data.rel.ro 0000000000000028 Base vtable for webots::LED
那我到底错在了什么?