+ Reply to Thread
Results 1 to 6 of 6

Thread: collect2: ld returned 1 exit status ERROR

  1. #1
    Newbie Namesake is an unknown quantity at this point
    Join Date
    Feb 2010
    Posts
    21

    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. #2
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,686
    Blog Entries
    57

    Re: collect2: ld returned 1 exit status ERROR

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

  3. #3
    Moderator ZekeDragon is a name known to all ZekeDragon is a name known to all ZekeDragon is a name known to all ZekeDragon is a name known to all ZekeDragon is a name known to all ZekeDragon is a name known to all ZekeDragon's Avatar
    Join Date
    Jul 2009
    Location
    Nowhere, Washington
    Posts
    1,776
    Blog Entries
    40

    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.
    Should I get a userbar here?

  4. #4
    Newbie Namesake is an unknown quantity at this point
    Join Date
    Feb 2010
    Posts
    21

    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?

  5. #5
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,686
    Blog Entries
    57

    Re: collect2: ld returned 1 exit status ERROR

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

  6. #6
    Newbie Namesake is an unknown quantity at this point
    Join Date
    Feb 2010
    Posts
    21

    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!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Cashflow\\ Any suggestions?
    By Demodex in forum C# Programming
    Replies: 13
    Last Post: 01-29-2010, 02:23 AM
  2. Cowsay C++ version !
    By Turk4n in forum Classes and Code Snippets
    Replies: 4
    Last Post: 12-06-2009, 06:37 AM
  3. Replies: 8
    Last Post: 06-10-2009, 02:26 PM
  4. need urgent help finding parce error!!!
    By siren in forum C and C++
    Replies: 3
    Last Post: 09-13-2007, 09:45 AM
  5. can someone help me with my c librarys?
    By bobwrit in forum C and C++
    Replies: 4
    Last Post: 04-27-2007, 06:19 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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