rhj4
July 11, 2016, 6:21pm
1
Occasionally, I get one error message and many warnings.
The error message is utterly useless:
"Error error: ld returned 1 exit status collect2.exe"
The verbose build output is attached.
My code is huge, so I am not going to waste your (or my) time trying to attach it. Instead, I want to understand:
What causes this message?
How do I diagnose that cause? I.E. What do I look for that will help me understand the cause?
How do I fix this problem?
BuildOutput.txt (134 KB)
system
July 11, 2016, 6:30pm
2
What causes this message?
Errors in your code.
How do I diagnose that cause?
Do not ignore the messages that come before the last one (that you show).
I.E. What do I look for that will help me understand the cause?
The messages that come before that one.
How do I fix this problem?
Fix the errors that precede it.
rhj4
July 18, 2016, 5:10am
3
I would appreciate a serious answer rather than a simplistic one. Here is the data:
There is only 1 error: "ld returned 1 exit status collect2.exe"
There are a number of warnings:
The two that are at the heart of the problem are (I believe) the "Undefined reference to 'vtable... messages. I have checked carefully to make sure that all abstract methods in parent classes have corresponding concrete methods in this class. I have made sure that every class has a destructor. Beyond that, I can find no information on how to determine what the "undefined references to vtable" are. I can find no utility program that can give me an answer to this question and I have had no success with any other sources.
The verbose output of the build is attached.
BuildVerboseOutput.txt (153 KB)
DualMotorRomeo.h:undefined reference to vtable for DualMotorRomeo DualMotorRomeo.h:undefined reference to vtable for DualMotorRomeo
Are you adorning initialized object instances with PROGMEM that have virtual methods?
rhj4
July 18, 2016, 10:59pm
5
I am still struggling with cryptic output from gcc, Here is the complete error / warning list:
Severity Description File Line Column Category
Warning In function `DualMotorRomeo D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\CommandPattern3.cpp.o -1
Error error: ld returned 1 exit status collect2.exe
Warning undefined reference to `vtable for DualMotorRomeo D:\Users\Bob.ObigOne\Documents\Arduino\CommandPattern3\DualMotorRomeo.h 40
Warning undefined reference to `vtable for DualMotorRomeo D:\Users\Bob.ObigOne\Documents\Arduino\CommandPattern3\DualMotorRomeo.h 40
Here is the DualMotorRomeo.h code:
#ifndef _DUALMOTORROMEO_h
#define _DUALMOTORROMEO_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
#include "BJRobotOptions.h"
#include "AssertDiagnostic.h"
#include "PropulsionSystem.h"
#include "GenericDualMotor.h"
#include "MotorDefinition.h"
#include "MotorDefinitionRomeo.h"
class DualMotorRomeo : public GenericDualMotor {
public:
int _leftMotion;
int _leftSpeed;
bool _leftFlip;
int _rightMotion;
int _rightSpeed;
bool _rightFlip;
bool _validated;
MotorDefinitionRomeo *leftMotor;
MotorDefinitionRomeo *rightMotor;
BJRobotOptions::Settings *settings;
// Constructor
DualMotorRomeo(BJRobotOptions::Settings *s) : settings(s), GenericDualMotor(this, MT_ROMEO) {
_leftMotion = settings->motorPins.leftMotion;
_leftSpeed = settings->motorPins.leftSpeed;
_leftFlip = settings->motorPins.leftFlip;
_rightMotion = settings->motorPins.rightMotion;
_rightSpeed = settings->motorPins.rightSpeed;
_rightFlip = settings->motorPins.rightFlip;
};
// Destructor
~DualMotorRomeo() {};
virtual bool init();
// Show motor pin configurations
virtual void showMotorPins();
// Show motor diagnostics
virtual void diagnostics();
virtual void forward(int speed);
virtual void backward(int speed);
virtual void stop();
virtual void forwardLeft(int speed);
virtual void backwardLeft(int speed);
virtual void stopLeft();
virtual void forwardRight(int speed);
virtual void backwardRight(int speed);
virtual void stopRight();
virtual void turnLeft(int speed, int heading);
virtual void turnRight(int speed, int heading);
virtual void spinLeft(int speed, int heading);
virtual void spinRight(int speed, int heading);
};
#endif
#endif
The entire verbose build output is attached.
The critical questions is, "what references to vtable are undefined? Is there a Window's based too that can give me an answer to this?
BuildVerboseOutput.txt (31.7 KB)
J-M-L
July 19, 2016, 6:46am
7
Coding Badly might have a hint I guess
#include "[color=red]a[/color]rduino.h" ??
system
July 19, 2016, 1:39pm
8
Why do you have the implementation in the header file? Real programmers define classes in header files and implement the classes in source files.
Makes it a LOT easier to see the definition vs. the implementation.
rhj4
July 22, 2016, 1:02am
9
Only the constructor code was included in the header file, as any "Real Programmer" (thank you, PAUL S) would be able to see. And a "Real Programmer" would actually answer my questions with useful answers instead of disparaging remarks.
rhj4
July 22, 2016, 4:41am
11
In response to "Coding Badly", all PROGMEM references have been removed, so that is not the problem. It is a linking problem. There are two references not being resolved and I have been unable to spot them. I have been asking for any tools or diagnostics that could help me chase this problem down.
The last few lines of the output are:
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc" -w -Os -Wl,--gc-sections,--relax -mmcu=atmega2560 -o "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560/CommandPattern3.ino.elf" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\CommandPattern3.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\Wire\Wire.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\Wire\utility\twi.c.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\BJMotionDetector\BJMotionDetector.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\LSM303\LSM303.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\TimerOne\TimerOne.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\VM_DBG\VM_DBG.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\ActiveObjectEngine.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\AssertDiagnostic.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\BJCompass.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\BJCompassBase.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\BJCompassHeading.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\BJCompassHMC5883L.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\BJCompassLSM303.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\BJRobotOptions.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\BJRobotSettings.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\Command.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\CommandClient.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\CommandCodes.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\CommandDispatcher.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\CommandMaker.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\CommandRequest.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\DemoClient.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\Detection.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\Dispatcher.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\DualMotorL298N.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\DualMotorL9110.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\DualMotorRomeo.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\DualMotorZumo.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\FreeMemoryDiagnostic.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\GenericClient.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\GenericDualMotor.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\GenericSingleMotor.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\HMC5883L.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\LineDetection.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\LinkedList.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\MaintainHeading.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\MotorDefinition.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\MotorDefinitionL298N.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\MotorDefinitionL9110.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\MotorDefinitionRomeo.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\MotorDefinitionZumo.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\NavigationClient.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\ObstacleDetection.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\OptionSettings.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\PropulsionSystem.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\RemoteControlClient.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560\SerialInputClient.cpp.o" "D:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560/core.a" "-LD:\Users\Bob.ObigOne\Documents\Arduino\TEMP_BUILD_FOLDER\CommandPattern3\mega_atmega2560" -lm
CommandPattern3.cpp.o:In function `DualMotorRomeo
DualMotorRomeo.h:undefined reference to `vtable for DualMotorRomeo
DualMotorRomeo.h:undefined reference to `vtable for DualMotorRomeo
collect2.exe*:error: ld returned 1 exit status
Error compiling for board Arduino/Genuino Mega w/ ATmega2560 (Mega 2560)
I guess the problem is not in your code but in the Arduino program files,
check this out: