Thread: ld returned 1 exit status

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    7

    ld returned 1 exit status

    Hi,
    how can I solve this error message;
    "collect2: ld returned 1 exit status"
    thank you.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Well, since my crystal ball is currently in for service and the martians are jamming the forum's mind reading code again... I'd say you should post your code --in code tags-- and let us have a look at it.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by CommonTater View Post
    Well, since my crystal ball is currently in for service and the martians are jamming the forum's mind reading code again... I'd say you should post your code --in code tags-- and let us have a look at it.

    here is my code;
    Code:
    #include <stdio.h>
    
    #define MAXWEIGHT 100
    
    
    
    void fill_sack(int c[], int v[], int W, int n) {
    	int a[MAXWEIGHT]; /* a[i] holds the maximum value that can be obtained
    				using at most i weight */
    	int last_added[MAXWEIGHT]; /* I use this to calculate which object were
    					added */
    	int i, j, k=0, m;
    	int totalweight=0;
    	int totalvalue=0;
    	char names[MAXWEIGHT];
    	int weights[MAXWEIGHT];
    	int values[MAXWEIGHT];
    	int aux;
    	char ch;
    
    	for (i = 0; i <= W; ++i) {
    		a[i] = 0;
    		last_added[i] = -1;
    	}
    
    	a[0] = 0;
    	for (i = 1; i <= W; ++i)
    		for (j = 0; j < n; ++j)
    			if ((c[j] <= i) && (a[i] < a[i - c[j]] + v[j])) {
    				a[i] = a[i - c[j]] + v[j];
    				last_added[i] = j;
    			}
    
    	for (i = 0; i <= W; ++i)
    		if (last_added[i] != -1)
    			printf("Weight %d; Benefit: %d; To reach this weight I added object %d (%d$ %dKg) to weight %d.\n", i, a[i], last_added[i] + 1, v[last_added[i]], c[last_added[i]], i - c[last_added[i]]);
    		else
    			printf("Weight %d; Benefit: 0; Can't reach this exact weight.\n", i);
    
    	printf("---\n");
    
    	aux = W;
    	while ((aux > 0) && (last_added[aux] != -1)) {
              
    		names[k]=last_added[aux]+1;
    		values[k]=v[last_added[aux]];
    		weights[k]=aux-c[last_added[aux]];
    		k=k+1;
    		aux -= c[last_added[aux]];
    	}
    
    for(m=0; m<k;m++)
    	{
    		totalvalue=totalvalue+values[m];
    		totalweight=totalweight+weights[m];
    		printf("%s;", names[m]);
    	}	
    		printf("%s",names[m+1]);
    		printf("/n%d;TOTAL VALUE IN BAG",totalvalue);
    		printf("/n%d;TOTAL WEIGHT IN BAG",totalweight);
    		ch=getchar();
    
    }
    
    int main(void) {
    
    char ch;
    int n = 3; /* The number of objects */
    int c[10] = {8, 6, 4}; /* c[i] is the *COST* of the ith object; i.e. what
    				YOU PAY to take the object */
    int v[10] = {16, 10, 7}; /* v[i] is the *VALUE* of the ith object; i.e.
    				what YOU GET for taking the object */
    int W = 10; /* The maximum weight you can take */ 
        
        fill_sack(c, v, W, n);
        ch=getchar();
    	return 0;
    }

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Throwing your quoted string at Google answers your question a bajillion times.

    If you read the output, it should also tell you the problem; output, which I might add, you didn't share.

    Soma

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by phantomotap View Post
    Throwing your quoted string at Google answers your question a bajillion times.

    If you read the output, it should also tell you the problem; output, which I might add, you didn't share.

    Soma
    the Dev-C compiler says;
    " Invalid argument "
    " ld returned 1 exit status "

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by madennn View Post
    the Dev-C compiler says;
    " Invalid argument "
    " ld returned 1 exit status "
    Go into your settings and put the warning level on maximum...
    the compiler should be giving you line numbers, function names, etc in your warnings.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Have you ever successfully built a program in this (miserable) IDE?

  8. #8
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by CommonTater View Post
    Go into your settings and put the warning level on maximum...
    the compiler should be giving you line numbers, function names, etc in your warnings.
    simple programs are not even compiled also.
    i have mingw installed also, i am trying gcc compilation it does not work either, giving the same error "ld returned 1 exit status"

    Quote Originally Posted by rags_to_riches View Post
    Have you ever successfully built a program in this (miserable) IDE?
    before installing mingw Devc was working fine. i could not understand the problem exactly.
    Last edited by madennn; 03-29-2011 at 09:49 AM.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by madennn View Post
    before installing mingw Devc was working fine. i could not understand the problem exactly.
    Ok... Do you do any C++ coding, or is it all just plain C?

    The DEV IDE and compiler are abandonware. They haven't been supported in nearly a decade and things like updating the compiler are going to cause you irresolvable problems... like you're having now.

    For "just plain C" (C-99, to be exact) your best tool is Pelles-C

    If you are doing C and C++ on windows, look into Visual C++

    In either case DEVC++ and TurboC++ are dinosaurs that just won't go extinct. Neither has even the first bit of support, neither will be updated --ever-- and both suffer problems that are mainly the result of time having left them behind.

  10. #10
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    before installing mingw Devc was working fine. i could not understand the problem exactly.
    That's a known issue. The installers setup some environment variables and the different installations trip over each other. You'll have to manually fix the paths and the environment. Unless it has been deleted, you'll find a "step-by-step" at the board for "Dev-C++".




    The DEV IDE and compiler are abandonware.
    neither will be updated --ever--
    O_o

    GCC and the compiler that was "Turbo C++" are updated every year.

    With this in mind, it makes even less sense for people to stick with old or just bad compilers. (They have several excellent, free, and modern compiler suites to choose from.)

    Soma

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by phantomotap View Post
    GCC and the compiler that was "Turbo C++" are updated every year.
    Turbo C++ Community
    Turbo C++ is no longer available. We invite you to learn more about C++Builder XE and download a free trial
    ... C++Builder XE Starter Edition... $194.76 after 30 day evaluation expires.

    Pelles C ... free ... with more features than XE Starter.
    MSVC++... free... need to find 3rd party resource editor (also free)
    Last edited by CommonTater; 03-29-2011 at 10:24 AM.

  12. #12
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by CommonTater View Post
    Turbo C++ Community


    ... C++Builder XE Starter Edition... $194.76 after 30 day evaluation expires.

    Pelles C ... free ... with more features than XE Starter.
    MSVC++... free... need to find 3rd party resource editor (also free)
    i installed Pelles c but the "compile" option is not clickable. it is really weird.

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by madennn View Post
    i installed Pelles c but the "compile" option is not clickable. it is really weird.
    In Pelles C you have to create a project...
    Click File->New->Project... choose your project type (probably "Win32 console Program") and give it a name at the bottom... then click OK.

    Now right click on the project name in the tree window and Add Files ... Add your source file and it should be able to compile it for you right away...

    Pelles C is a complete build environment, it's a bit different than you're used to, but a couple of times through the "new project" loop and you'll be fine...

    Also look in the help file ... it's VERY complete. Everything the IDE does is detailed as are all function calls in the library.

  14. #14
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by CommonTater View Post
    In Pelles C you have to create a project...
    Click File->New->Project... choose your project type (probably "Win32 console Program") and give it a name at the bottom... then click OK.

    Now right click on the project name in the tree window and Add Files ... Add your source file and it should be able to compile it for you right away...

    Pelles C is a complete build environment, it's a bit different than you're used to, but a couple of times through the "new project" loop and you'll be fine...

    Also look in the help file ... it's VERY complete. Everything the IDE does is detailed as are all function calls in the library.
    ok thank you very much it worked like you mentioned..

  15. #15
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by madennn View Post
    ok thank you very much it worked like you mentioned..
    Enjoy!

    But please do spend some time with the help file...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An efficient approach to TicTacToe AI?
    By xofvc4rqb in forum C++ Programming
    Replies: 11
    Last Post: 01-15-2011, 05:09 PM
  2. cygwin on win64
    By Vanzemljak in forum Tech Board
    Replies: 3
    Last Post: 01-12-2011, 04:28 PM
  3. Need help in C programming (too lazy)
    By cwillygs in forum C Programming
    Replies: 12
    Last Post: 04-20-2010, 12:23 AM
  4. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  5. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM