Jump to content

collect2: ld returned 1 exit status ERROR

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
Namesake

Namesake

    Newbie

  • Members
  • PipPip
  • 21 posts
hey all,

I am getting an error I am unsure of how to deal with, when running my simple code. I have been over my code for the past hour, and swear that the syntax is correct.

This is just the beginning of a much larger project, and I haven't even got the basics right. The output is:

lloyd@lloyd-laptop:~/Desktop/Code/Viscious Walker$ g++ vicioustest.cpp -o viciousResults 

/tmp/cceanGG8.o: In function `main':

vicioustest.cpp:(.text+0x31): undefined reference to `ViciousWalker::ViciousWalker(int, int, int, int)'

collect2: ld returned 1 exit status



Header:

#ifndef Vic

#define Vic

#include <iostream>

#include <vector>

#include <iomanip>

#include <cmath>

#include <algorithm>

#include <iterator>

#include <limits.h>


using namespace std;


class ViciousWalker {


	public:

/*Initialising Constructor*/

		ViciousWalker(int = 2, int=1, int=1, int=1);


/*Set Functions*/

		void setArray(int,int);

		void setTimeStep(int);


/*Get Functions*/

		int getArray();

		int getTimeSteps();


	private:

		int arrayRow, arrayCol;

		int timeSteps;

		int numberOfWalkers;


};


#endif

Class file:

#include <iostream>

#include <vector>

#include <iomanip>

#include <cmath>

#include <algorithm>

#include <iterator>

#include <limits.h>


#include "vicious.h"


using namespace std;

/*Constructor*/

ViciousWalker::ViciousWalker(int R, int C, int t, int n){

	arrayRow=R; 

	arrayCol=C;

	timeSteps=t;

	numberOfWalkers=n;


};

/*Set Functions*/


void ViciousWalker::setArray(int a, int b){


   if (a>=1 && b>=1 ) {

	arrayRow = a;

	arrayCol = b;

   }

   else {

      cout<<"Array parameters need to be greater than zero."<<endl; 

      exit( EXIT_SUCCESS );

   }


};


/*void ViciousWalker::setArray(int a){


   if (a>=1) {

	int arrayRow = a;

	int arrayCol = a;

   }

   else {

      cout<<"Array parameters need to be greater than zero."<<endl; 

      exit( EXIT_SUCCESS );

   }


};*/

void ViciousWalker::setTimeStep(int i){

   if (i>=1) {

	timeSteps = i;


   }

   else {

      cout<<"Number of time steps need to be greater than zero."<<endl; 

      exit( EXIT_SUCCESS );

   }

};


Main function file:

#include <iostream>

#include <vector>

#include <iomanip>

#include <cmath>

#include <algorithm>

#include <iterator>

#include <limits.h>


#include "vicious.h"


int main(){

	ViciousWalker deathRing(4,3,100,3);

	//deathRing.setArray(4,3);

	return 0;

}



Any help at all would be greatly appreciated! :D

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You have to compile BOTH source files, not just one.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
#ifndef Vic
#define Vic
Ew. Please don't use a word that small for your header guards, use something like "VICIOUS_H_INCLUDED". Remember that that define will be global for any file that happens to include it, so make sure the header guard include is unique!

And yeah, you need to compile using something like this:
g++ vicioustest.cpp vicious.cpp -o viciousResults
(Assuming that your .cpp file is the same name as it's according header file. It should be.)

If your project gets big, you'll eventually want to use some automake tools to create a Makefile for your program.
Wow I changed my sig!

#4
Namesake

Namesake

    Newbie

  • Members
  • PipPip
  • 21 posts
thanks all for such rapid respone - feeling slightly foolish at an obvious mistake. Tired eyes and not thinking!

One question:

When I construct a class, is it necessary for it to have any input parameters?

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Not necessarily. It really just depends on the class/constructor's requirements.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
Namesake

Namesake

    Newbie

  • Members
  • PipPip
  • 21 posts

WingedPanther said:

Not necessarily. It really just depends on the class/constructor's requirements.


Cheers!
:thumbup: