Closed Thread
Results 1 to 6 of 6

Thread: collect2: ld returned 1 exit status ERROR

  1. #1
    Namesake is offline Newbie
    Join Date
    Feb 2010
    Posts
    21
    Rep Power
    0

    collect2: ld returned 1 exit status ERROR

    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:
    Code:
    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:
    Code:
    #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:
    Code:
    #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:
    Code:
    #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!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: collect2: ld returned 1 exit status ERROR

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

  4. #3
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: collect2: ld returned 1 exit status ERROR

    Code:
    #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:
    Code:
    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!

  5. #4
    Namesake is offline Newbie
    Join Date
    Feb 2010
    Posts
    21
    Rep Power
    0

    Re: collect2: ld returned 1 exit status ERROR

    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?

  6. #5
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: collect2: ld returned 1 exit status ERROR

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

  7. #6
    Namesake is offline Newbie
    Join Date
    Feb 2010
    Posts
    21
    Rep Power
    0

    Re: collect2: ld returned 1 exit status ERROR

    Quote Originally Posted by WingedPanther View Post
    Not necessarily. It really just depends on the class/constructor's requirements.

    Cheers!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:18 AM
  2. Replies: 6
    Last Post: 06-27-2010, 12:57 AM
  3. What is the value returned by a Dialog?
    By xXZeroXx in forum Python
    Replies: 2
    Last Post: 01-27-2010, 08:50 PM
  4. I've returned - CHILI5 READ THIS!!
    By Brandon W in forum The Lounge
    Replies: 22
    Last Post: 06-11-2009, 03:22 AM
  5. How to exit from this loop
    By Hassan Syed in forum General Programming
    Replies: 2
    Last Post: 02-04-2009, 05:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts