Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) How to understand error messages? - collect2.exe*:error: ld returned 1 exit status (Read 20206 times)
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Jul 11th, 2016 at 6:19pm
Print Post  
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:

1) What causes this message?
2) How do I diagnose that cause? I.E. What do I look for that will help me understand the cause?
3) How do I fix this problem?
« Last Edit: Jul 11th, 2016 at 6:42pm by Tim@Visual Micro »  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12190
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Ambiguous error message
Reply #1 - Jul 11th, 2016 at 6:30pm
Print Post  
Hi,

I have seen the linker return that error.

You could switch on verbose output and look to see what is being linked incorrectly.

If you want to ensure a full clean build then click "Build>Clean Solution" prior to build
  
Back to top
IP Logged
 
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: Ambiguous error message
Reply #2 - Jul 11th, 2016 at 6:35pm
Print Post  
My verbose output is attached. What indicates "linked incorrectly."? I am hunting through over 500 lines of output. What is the pattern I s/b searching for?
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12190
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Ambiguous error message
Reply #3 - Jul 11th, 2016 at 6:40pm
Print Post  
The link is the last command when it attempts to produce the .elf

The error looks fairly clear to me. A tip is always to go to the end and work backwards.

These are the final lines of your report. The last command attempts to link all the object files and create the .elf program file.

I also recommend viewing the output in a text editor with wrapping OFF

Code (C++)
Select All
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc" -w -Os -Wl,--gc-sections,--relax -mmcu=atmega2560 -o tmega2560/CommandPattern3.ino.elf" tmega2560\CommandPattern3.cpp.o" tmega2560\Wire\Wire.cpp.o" tmega2560\Wire\utility\twi.c.o" tmega2560\BJMotionDetector\BJMotionDetector.cpp.o" tmega2560\BJCompassBase\BJCompassBase.cpp.o" tmega2560\BJCompassHMC5883L\BJCompassHMC5883L.cpp.o" tmega2560\BJCompassLSM303\BJCompassLSM303.cpp.o" tmega2560\BJRobotOptions\BJRobotOptions.cpp.o" tmega2560\LSM303\LSM303.cpp.o" tmega2560\TimerOne\TimerOne.cpp.o" tmega2560\VM_DBG\VM_DBG.cpp.o" tmega2560\ActiveObjectEngine.cpp.o" tmega2560\Command.cpp.o" tmega2560\CommandClient.cpp.o" tmega2560\CommandCodes.cpp.o" tmega2560\CommandDispatcher.cpp.o" tmega2560\CommandMaker.cpp.o" tmega2560\CommandRequest.cpp.o" tmega2560\DemoClient.cpp.o" tmega2560\Detection.cpp.o" tmega2560\Dispatcher.cpp.o" tmega2560\DualMotorL298N.cpp.o" tmega2560\DualMotorL9110.cpp.o" tmega2560\DualMotorRomeo.cpp.o" tmega2560\DualMotorZumo.cpp.o" tmega2560\FreeMemoryDiagnostic.cpp.o" tmega2560\GenericClient.cpp.o" tmega2560\GenericDualMotor.cpp.o" tmega2560\GenericSingleMotor.cpp.o" tmega2560\HMC5883L.cpp.o" tmega2560\LineDetection.cpp.o" tmega2560\LinkedList.cpp.o" tmega2560\MaintainHeading.cpp.o" tmega2560\MotorDefinition.cpp.o" tmega2560\MotorDefinitionL298N.cpp.o" tmega2560\MotorDefinitionL9110.cpp.o" tmega2560\MotorDefinitionRomeo.cpp.o" tmega2560\MotorDefinitionZumo.cpp.o" tmega2560\NavigationClient.cpp.o" tmega2560\ObstacleDetection.cpp.o" tmega2560\OptionSettings.cpp.o" tmega2560\PropulsionSystem.cpp.o" tmega2560\RemoteControlClient.cpp.o" tmega2560\SerialInputClient.cpp.o" tmega2560\Utility.cpp.o" tmega2560\Wire.cpp.o" tmega2560/core.a" _atmega2560" -lm
CommandPattern3.cpp.o:In function `Settings
BJRobotOptions.h:undefined reference to `RobotOptions  obstaclePinSettings
BJRobotOptions.h:undefined reference to `RobotOptions  obstaclePinSettings
BJRobotOptions.h:undefined reference to `RobotOptions  motor_L298N
BJRobotOptions.h:undefined reference to `RobotOptions  motor_L298N
CommandPattern3.cpp.o:In function `DualMotorL298N
DualMotorL298N.h:undefined reference to `vtable for DualMotorL298N
DualMotorL298N.h:undefined reference to `vtable for DualMotorL298N
collect2.exe*:error: ld returned 1 exit status

Error compiling for board Arduino/Genuino Mega w/ ATmega2560 (Mega 2560) 



« Last Edit: Jul 11th, 2016 at 6:41pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #4 - Jul 13th, 2016 at 1:50am
Print Post  
Tim,

I am delighted that the error looks fairly clear to you, but I am old and getting senile and it's not clear to me. The two lines that say:

DualMotorL298N.h:undefined reference to `vtable for DualMotorL298N
DualMotorL298N.h:undefined reference to `vtable for DualMotorL298N

Suggest that DualMotorl298N is not implementing all of the abstract methods from its parents, but I have checked carefully and all abstracts have a corresponding concrete in the DualMotor class. 

So why am I getting an "undefined reference" in a .h file?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12190
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #5 - Jul 13th, 2016 at 3:17pm
Print Post  
I was simply saying that the error was more than what you reported.

I don't know the answer to the question. 

You mentioned you were close to the memory limit of the mega. Confusing errors, if they are, can sometimes be due to blowing limits.

Did you try copying your libraries to mydocuments\arduino\libraries then compiling with the Arduino Ide to confirm the same error?

EDIT: if you suspect memory issues you should make sure a Release build works. The Debug build can add extra overhead so should be avoided until you have a stable Release build.
« Last Edit: Jul 13th, 2016 at 7:56pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #6 - Jul 14th, 2016 at 5:41am
Print Post  
Tim,

A couple points of clarification:
1) I exceeded the UNO memory so I switched to a MEGA and have plenty of memory.

2) I did copy some of my libraries to the libraries folder and that was the beginning of some of my problems. I built the library properties file but kind of punted on the keywords.txt file. Am I making a bad assumption that the keywords.txt file is not a key element in the compile?

When I copied my classes to the Libraries folder, the compiler can't find them any more. I add them, refresh the list, check again but the compiler keeps stopping when it thinks it can't find the .h file for that class. So I have moved most of my classes into the same folder as the .ino file.

The verbose output is in the project code file (see buildoutput.txt). I am still stuck trying to understand what the compiler is telling me. Its diagnostic output feels like the kind stuff somebody would write if they never had to use their own code. The Warnings just say "Warning - but I am not going to tell you what the problem is... I am just going to say "Warning" and you can guess... if you're lucky..."


I have attached the entire project code. The Library zips down to about 2MB, so I cannot send it via this interface. Ideas or suggestions?

Thanks again for your help. I am trying to do a really good job with the architecture of this code, but the compiler seems to want to fight with me every step of the way! Sad
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #7 - Jul 15th, 2016 at 8:33pm
Print Post  
I found a reference in Stackoverflow (see http://stackoverflow.com/questions/3065154/undefined-reference-to-vtable)  that says, "nm -C CGameModule.o | grep CGameModule:: will list the methods that are defined, assuming your entire class implementation goes into the logical object file."

Since I am running in Visual Studio under Windows 10, I don't know how to execute commands like "nm -C modulename.o | grep modulename::" 

Can you advise how to accomplish this? Is this something that can be added to the list of commands that the build process executes?

« Last Edit: Jul 15th, 2016 at 8:36pm by Bob Jones »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12190
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #8 - Jul 15th, 2016 at 8:52pm
Print Post  
I bob Visual Micro uses the same process as Arduino so you won't have any problems getting help with this type of request on the arduino.cc forum.

I think the easiest solution will be to grab the verbose output, put in a .bat file then edit or add to it as required.
  
Back to top
IP Logged
 
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #9 - Jul 15th, 2016 at 9:02pm
Print Post  
I am missing one piece here. What program do I use to execute the bat file? Can I use Command (DOS) program or do I need some other program?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12190
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #10 - Jul 15th, 2016 at 9:05pm
Print Post  
Hi Bob,

Yes windows .bat files can be run from the command prompt. If they output to file then you can simply double click and run from windows explorer.

For windows explorer, if I recall, you can also add the "Pause" command at the end of the bat to prevent the window from closing after the .bat runs.
  
Back to top
IP Logged
 
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #11 - Jul 16th, 2016 at 1:14am
Print Post  
OK, I built the batch file and ran it and got the same darn result: undefined reference to `vtable for DualMotorRomeo. The nm utility in Unix roughly corresponds to DumpBin.exe in Windows, but dumpbin won't read a .o file from c++ and there is no EXE file to read because the compile fails. 

So I am still stuck and I really need some help here. What tool that runs in Windows will read the output of the gcc compiler? How do I see the vtable entries in a .o file?

This issue has cost me a week already and I am dead in the water. Cannot proceed until I can get a clean compile. Angry

The build output is attached.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12190
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #12 - Jul 16th, 2016 at 12:32pm
Print Post  
Hi

Best place for questions about avr/gcc tools and object files is probably the arduino.cc forum.

Sorry I am not an expert with gcc

  
Back to top
IP Logged
 
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #13 - Jul 22nd, 2016 at 10:41pm
Print Post  
There is an interesting clue in the warning messages:

Code
Select All
Severity	Description	File	Line	Column	Category
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
Warning	undefined reference to `DualMotorRomeo  ~DualMotorRomeo()	D:\Users\Bob.ObigOne\Documents\Arduino\CommandPattern3\CommandPattern3.ino	104
Warning	In function `__static_initialization_and_destruction_0	mega2560\CommandPattern3.cpp.o	-1
Warning	In function `DualMotorRomeo	mega2560\CommandPattern3.cpp.o	-1
Error	error: ld returned 1 exit status	collect2.exe
 



Notice the "`" character before DualMotorRomeo and also before the word vtable. The is a left quote, not a single quote and I have no idea where it comes from. This character does not appear anywhere in my code, so it is somehow being added by the compiler.

Has anybody seen this before? Any ideas where it is coming from? 

Verbose compiler output is attached.

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12190
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #14 - Jul 22nd, 2016 at 10:49pm
Print Post  
Ignore the quote they always appear in all avr/gcc outputs.
  
Back to top
IP Logged
 
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #15 - Jul 23rd, 2016 at 12:09am
Print Post  
OK, so much for that blind alley. I have gone through the code with a microscope and I cannot see anything that could be causing the problem. The entire code base (I hope) is attached. Please see if you can at least duplicate the problem.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12190
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #16 - Jul 23rd, 2016 at 12:30am
Print Post  
It doesn't build it is missing BJMotionDetector.h
  
Back to top
IP Logged
 
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #17 - Jul 23rd, 2016 at 4:58am
Print Post  
Comment out line 66 in CommandPattern.ino. BJMotionDetector is a stub  for the next bunch of code I want to add, but it compiles fine without this file included.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12190
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to understand error messages? - collect2.exe*:error: ld returned 1 exit status
Reply #18 - Jul 23rd, 2016 at 11:41am
Print Post  
Hi,

I noticed you have posted a visual micro verbose output with your question in the arduino.cc forum. That will just cause confusion. My suggestion was to build using the Arduino IDE to confirm the same error then post the verbose output from the Arduino IDE in the Arduino forum. If you don't work that way you won't get any help from the arduino crowd and it is a main point about why Visual Micro remains compatible with the Arduino IDE


So I comment a missing file and it then fails with this error:-

Code
Select All
DualMotorRomeo.h:undefined reference to `vtable for DualMotorRomeo
 



Double clicking the error takes me to the following line which appears to be expecting the static struct defined in BJRobotOptions.h called BJRobotOptions::Settings to be passed by ref. 

DualMotorRomeo.h
Code
Select All

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



GenericMotorDual.h
Code
Select All
class MotorDefinition;

class GenericDualMotor : public PropulsionSystem {
protected:
	bool validated;
	GenericDualMotor *motor;

public:
	MotorDefinition *leftMotor;
	MotorDefinition *rightMotor;

	//	Constructor
	GenericDualMotor(GenericDualMotor *m, int mType)
		: motor(m), PropulsionSystem(PT_DUAL_MOTOR, mType) {
		validated = false;
	};

	//	Destructor
	virtual ~GenericDualMotor() {}; 




BJRobotOptions.h
Code
Select All
#include "BJRobotSettings.h"

class BJRobotOptions {
public:

#if MOTOR_TYPE == MT_L298N
	static struct MT_L298N_PINS {
		int MotorType = MOTOR_TYPE;
		int IN1 = MT_L298N_IN1;
		int IN2 = MT_L298N_IN2;
		int ENA = MT_L298N_ENA;
		bool FLIPA = MT_L298N_FLIPA;
		int IN3 = MT_L298N_IN3;
		int IN4 = MT_L298N_IN4;
		int ENB = MT_L298N_ENB;
		bool FLIPB = MT_L298N_FLIPB;
	} motor_L298N;
#elif MOTOR_TYPE == MT_L9110
	static struct MT_L9110_PINS {
		int MotorType = MOTOR_TYPE;
		int PWMA = MT_L9110_PWMA;
		int DIRA = MT_L9110_DIRA;
		int FLIPA = MT_L9110_FLIPA;
		int PWMB = MT_L9110_PWMB;
		int DIRB = MT_L9110_DIRB;
		int FLIPB = MT_L9110_FLIPB;
	} motor_L9110;
#elif MOTOR_TYPE == MT_ROMEO
	static struct MT_ROMEO_PINS {
		int MotorType = MOTOR_TYPE;
		int leftMotion = MT_ROMEO_LEFTMOTION;
		int leftSpeed = MT_ROMEO_LEFTSPEED;
		bool leftFlip = MT_ROMEO_LEFTFLIP;
		int rightMotion = MT_ROMEO_RIGHT_MOTION;
		int rightSpeed = MT_ROMEO_RIGHT_SPEED;
		bool rightFlip = MT_ROMEO_RIGHT_FLIP;
	} motor_ROMEO;
#elif MOTOR_TYPE == MT_ZUMO
	static struct MT_ZUMO_PINS {
		int MotorType = MOTOR_TYPE;
		int leftMotion = MT_ZUMO_LEFTMOTION;
		int leftSpeed = MT_ZUMO_LEFTSPEED;
		bool leftFlip = MT_ZUMO_LEFTFLIP;
		int rightMotion = MT_ZUMO_RIGHT_MOTION;
		int rightSpeed = MT_ZUMO_RIGHT_SPEED;
		bool rightFlip = MT_ZUMO_RIGHT_FLIP;
	} motor_ZUMO;
#else
	assert(false);
#endif

	//	Destructor
	~BJRobotOptions() {};


	//	PIN SETTINGS:
	//
	//	Red signals obstacle very close
	//	Yellow signals obstacle nearby but not up close and personal...yet
	//	Green signals no obstacles nearby
	//	Blue signals command(s) being executed which indicate that the robot is moving.
	//
	//	The associated ranges for these signals can be specified with the pin settings:
	struct ObstaclePinSetting {
		int pin;
		int distance;	// in CM
	};

	static struct ObstaclePinSettings {
		ObstaclePinSetting redPin;
		ObstaclePinSetting yellowPin;
		ObstaclePinSetting greenPin;
		ObstaclePinSetting bluePin;
	} obstaclePinSettings;

	//	One ring to rule them all... this struct contains ALL settings values
	struct Settings {
		int CompassType;
		int OutputOptions;
		ObstaclePinSettings *pins;
#if MOTOR_TYPE == MT_L298N
		struct MT_L298N_PINS motorPins;
#elif MOTOR_TYPE == MT_L9110
		struct MT_L9110_PINS motorPins;
#elif MOTOR_TYPE == MT_ROMEO
		struct MT_ROMEO_PINS motorPins;
#elif MOTOR_TYPE == MT_ZUMO
		struct MT_ZUMO_PINS motorPins;
#endif
	} settings;

	bool init(Settings *settings);

	const char* getMotorType(int mType);
	const char* getCompassType(int cType);

private:
	bool _initialized = false;
};

#endif


 



In all of this you have some static, some objects and inheritance.

I have explained previously that I need to keep this forum for support of the plugin for Visual Studio and Atmel Studio. I don't make money from selling hardware and am one person when the arduino forum is many people. Therefore for problems in code, to prevent me from being drowned with unrelated requests, I ask that help with code is found from the many other places on the web.

These other "places" for support will not be as forgiving as me. Posting a verbose output on it's own without showing or giving overview of the code, as I have done above, will not allow people to help you.

You should make a cut down test of what you are trying to achiever. You create BJOptions/settings in the .ino. Later you try to use the settings in a call to a method in a semi-static inherited environment. I don't see how any of your previous reports about this show the issue.

In addition to making better reports I also ask that when you provide examples that you have tested them yourself and informed helpers like myself which libraries need to be installed. It needed TimerOne

Quote:
Comment out line 66 in CommandPattern.ino. BJMotionDetector is a stub  for the next bunch of code I want to add, but it compiles fine without this file included


Do you mean the compile problem you have reported shows when BJMotionDetector.h is commented out? If so then I agree with you.

Lastly I have said before that my knowledge it limited however I see you are expecting a constructor in a class to be used in static way and the constructor is doing some complex stuff with objects and inheritance. I don't know when you expect things to be initialized in this usage? When do you create the non-static objects?
« Last Edit: Jul 23rd, 2016 at 11:55am by Tim@Visual Micro »  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint