Menu

Invalid Argument: ld returned 1 exit status

2006-04-10
2012-09-26
  • Nobody/Anonymous

    I just started C++ programming today and already I have a problem I can't get past. I keep getting this

    Invalid Argument
    ld returned 1 exit status

    error when I try to compile. My code is nothing more complicated than:

    // test math program

    include <cstdio>

    include <cstdlib>

    include <iostream>

    using namespace std;

    int main(int nnumberofargs, char* pszargs[])
    {
    // enter temp in celsius
    int celsius;
    cout << "Enter the temp in Celsius: ";
    cin >> celsius;

    // calculate conversion fom C to F
    int factor;
    factor = 212 - 32;
    
    // use conversion factor to convert
    int fahrenheit;
    fahrenheit = factor * celsius/100 +32;
    
    // output results you bastard program (followed by newline)
    cout &lt;&lt; &quot;Fahrenheit temp is: &quot;;
    cout &lt;&lt; fahrenheit &lt;&lt; endl;
    
    // wait until idiot user is ready before closing to allow view of answer
    system(&quot;PAUSE&quot;);
    return 0;
    

    }

    Can someone help please?

     
    • Nobody/Anonymous

      UPDATE >> lol

      umm okay I've tried several simple basic programs like hello world type junk and I always get the same

      Invalid Argument
      ld returned 1 exit status

      error whenever I try to compile. Therefore, I can conclude that I probably forgot to set up a program setting correctly. Can anyone please give me some help?

       
    • Wayne Keen

      Wayne Keen - 2006-04-10

      Well, we can help a little more if you post full compile log. Its on the tab labeled "Compile Log", and the right mouse button brings up the copy menu.

      Wayne

       
    • Wayne Keen

      Wayne Keen - 2006-04-10

      Please post the full log starting from the beginning, do not excerpt the errors. It would also be useful to know what version number of Dev you are using.

      Wayne

       
    • Anonymous

      Anonymous - 2006-04-10

      The invalid argument it is talking about is nothing to do with the code. It is an argument being passed to the linker during the build. All the arguments being passed appear of the build command line which is logged in the 'Compile Log'. We can do nothing further until you post that text (in full).

      This requirement is 'mentioned' in the thread titled "<-PLEASE READ BEFORE POSTING A QUESTION" which of course you read?!

      Clifford.

       
    • Nobody/Anonymous

      Version number: 4.9.9.2

      Log:
      Compiler: Default compiler
      Executing g++.exe...
      g++.exe "\cerulean\students\2009\bse356\celsius to fahrenheit conv.cpp" -o "\cerulean\students\2009\bse356\celsius to fahrenheit conv.exe" -I"C:\c\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\c\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\c\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\c\Dev-Cpp\include\c++\3.4.2" -I"C:\c\Dev-Cpp\include" -L"C:\c\Dev-Cpp\lib"
      C:\c\Dev-Cpp\Bin..\lib\gcc\mingw32\3.4.2........\mingw32\bin\ld.exe: cannot open output file \cerulean\students\2009\bse356\celsius to fahrenheit conv.exe: Invalid argument
      collect2: ld returned 1 exit status

      Execution terminated

      Oh... it looks as if I can't write the .exe because my stupid school doesn't allow applications in personal user files...

      If this is wrong, please let me know lol

       
    • Nobody/Anonymous

      Okay I moved the .cpp file to a writeable folder and it works fine. Coming off of Visual Basic programming, it's hard.

      Thanks for the help!

       
    • Wayne Keen

      Wayne Keen - 2006-04-10

      An important warning!

      Spaces in file names are a BAD idea. It will bite you eventually, and hard.

      Wayne

       
    • Nobody/Anonymous

      Do you mean no spaces in the directory name or the .cpp itself?

       
      • Wayne Keen

        Wayne Keen - 2006-04-11

        BOTH.

        Wayne

         
    • Nobody/Anonymous

      Sorry for being such an annoying noob...

      My code is:

      // test string program

      include <cstdio>

      include <cstdlib>

      include <iostream>

      using namespace std;

      int main(int nnumberofargs, char* pszargs[])
      {
      // display instructions & ask for name
      string name;
      cout << "Welcome to the Name-a-nezator 2000!/n Please enter your name: ";
      cin >> name;

      // ask to verify
      bool verify;
      cout &lt;&lt; &quot;Are you sure your name is &quot;;
      cout &lt;&lt; name;
      cout &lt;&lt; &quot;? (True or False)&quot;;
      cin &gt;&gt; verify;
      

      }
      switch(verify)
      {
      case True:
      cout << name
      cout << " will die in seven days..../n/n Thanks for using the Name-a-nezator 2000!" << endl;
      system("pause");
      return 0;

      case False:
      cout << "Please enter your REAL name!";
      continue;

      default:
      cout << "Please enter a True or False value next time!"
      continue;
      }

      My log is:

      Compiler: Default compiler
      Executing g++.exe...
      g++.exe "E:\cpp-saves\namethingy.cpp" -o "E:\cpp-saves\namethingy.exe" -I"E:\Dev-Cpp\include\c++" -I"E:\Dev-Cpp\include\c++\mingw32" -I"E:\Dev-Cpp\include\c++\backward" -I"E:\Dev-Cpp\include" -L"E:\Dev-Cpp\lib"
      E:/cpp-saves/namethingy.cpp:21: parse error before `switch'

      E:/cpp-saves/namethingy.cpp:26: ISO C++ forbids declaration of system' with no type E:/cpp-saves/namethingy.cpp:26:int system' redeclared as different kind of
      symbol
      E:/Dev-Cpp/include/stdlib.h:373: previous declaration of int system(const char*)' E:/cpp-saves/namethingy.cpp:26: invalid conversion fromconst char*' to int' E:/cpp-saves/namethingy.cpp:27: parse error beforereturn'

      Execution terminated

      I've looked through and there seems to be no problems.... What's wrong

      If at any time you wish me to just shut the hell up, please say so...

       
      • Wayne Keen

        Wayne Keen - 2006-04-11

        Are you the original poster on this thread?

        You log shows a much different setup than the previous log. What version of Dev are you using?

        Wayne

         
    • Nobody/Anonymous

      Yes, original poster.

      This is version 4.9.8.0.

       
      • Wayne Keen

        Wayne Keen - 2006-04-11

        That is not the version you reported in an earlier post. Please be clear about your Basic 3 with each question. Features vary with version.

        Now, with that quite old version of Dev, you may need to add

        include<stdlib.h>

        I am guessing a bit, that version is a couple of years old at least.

        Is this a different computer than you were using earlier? I hope you didn't install it instead of 4.9.9.2

        Wayne

         
    • Wayne Keen

      Wayne Keen - 2006-04-11

      Note you also have a LOT of other errors in your code. Missing ; problems with case sensitivity (True does not equal true), misuse of continue...

      Wayne

       
    • Nobody/Anonymous

      Yeah, it's a different computer, but I'm running it off my portable hard drive and all these school computers have the same crap anyway.

      Maybe a bit of background knowledge would help here. I'm learning C++ from (here it comes)
      C++ for Dummies. I decided to switch back to the old version of Dev-C++ because it's the one they include with the book. According to the book, the Include files for this version of dev-c++ don't end in .h (only very old-fashioned programmers use .h according to them, lol)

      But anyway I did try the

      include<stdlib.h>

      command and I get the same errors, parse error before 'switch' and such.

      My goal is to make a crappy 2D RPG by the end of the year (using directx... which I have no idea how to reference yet...) and I really could use some help with basics.

      Thanks so much for putting up with my problems!

       
    • Anonymous

      Anonymous - 2006-04-11

      There is nothing wrong with either <cstdlib> or <stdlib.h>. You need to read the error messages from the top. The first message:

      E:/cpp-saves/namethingy.cpp:21: parse error before `switch'

      Indicates that the compiler no longer regards the code as valid at that point. Just before that line you have a closing brace( } ), that terminated teh main() function. All the rest of the code is then outside of any function, and in that context makes no sense.

      Always address the first reported error first, then consider if the others are 'cascaded' from the first, or separate issues. If in doubt, just re-compile.

      You really should use 4.9.9.2, that is what most of the people that can help you here are using, so it helps if they need to reproduce your error.

      Clifford

       
    • Nobody/Anonymous

      I'm on the IRC support channel at #bloodshed that no one uses according to the title... Can someone join up there and talk me through some of the basic syntax and errors?

       
      • Anonymous

        Anonymous - 2006-04-12

        Are we talking about the same code you posted above? You should probably start more than one thread, you seem to have started several different subjects in one thread.

        Please also sign your threads with a distinct moniker (or create a Sourceforge login); it is not always clear that we are talking to the same person - especially as you keep changing the subject!

        The benefit of having problems discussed in this forum is that it benefts the whole community, and the information remains available for reference. IRC is more transient, and benefits very few. This is the place to get your problems solved.

        If you are talking about the code posted earlier, then it does have mre problems that the stray brace I mentioned. Reading and understanding teh error messages is a skill you need to learn, they are your first source of help. If you are havig problems understanding them, post the log. If you provide god quality information - such as what version you are using today ;) , the compile log and commented code - then you will generally get a fast response from here.

        With respect yo your earlier code, after removing the stray brace:

        The only values a bool type can take are true (non-zero), or false (zero). Values True and False (capitalised) are not defined - C++ is case sensitive).

        If you ask the user to type True or False and assign the response to a bool, what do you expect t happen? The only response that I'd like to guarantee the result for are numeric values - zero for false, or non-zero for true. If the user types non-numeric text, I am not sure what will happen, probably always fales, always true, or undefined.

        bool is a numeric type, not a string type. If you want to accept a text response, you need to use a string class object. You can't then use switch, that is only valid for integer types. If it works for bool, that is probably only because of an implicit cast to int.

        Switching on a bool type!? What's the point? It only has two possible states, the default case is unreachable if you have a true and false case. A simple if-else construct will deal with a boolean value.

        Clifford

         
    • Nobody/Anonymous

      Thanks!

      I'll take the advice and start a new thread for basic help issues.

      --original poster

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.