Viewed   4.5k times

I see the error collect2: error: ld returned 1 exit status very often. For example, I was executing the following snippet of code:

void main() {
  char i;

  printf("ENTER i");


  switch(i) {
    case 1:
    case 2:
    case 3:

and I got this:

main.c:(.text+0x33): undefined reference to `clrscr'                       
collect2: error: ld returned 1 exit status 

What does it mean?



The ld returned 1 exit status error is the consequence of previous errors. In your example there is an earlier error - undefined reference to 'clrscr' - and this is the real one. The exit status error just signals that the linking step in the build process encountered some errors. Normally exit status 0 means success, and exit status > 0 means errors.

When you build your program, multiple tools may be run as separate steps to create the final executable. In your case one of those tools is ld, which first reports the error it found (clrscr reference missing), and then it returns the exit status. Since the exit status is > 0, it means an error and is reported.

In many cases tools return as the exit status the number of errors they encountered. So if ld tool finds two errors, its exit status would be 2.

Thursday, December 22, 2022

This probably is a problem with type inferance, apperently the compiler infers a as an Action<T> instead of Action (it might think a is ActionSurrogate, which would fit the Action<Action>> signature). Try specifying the type of a explicitly:

    ActionSurrogate b = (Action a) =>

If this is not the case - might check around your project for any self defined Action delegates taking one parameter.

Friday, December 16, 2022

There is no way to suppress an error other than to fix it.

An error, by its nature, is indicating that the compiler believes it cannot generate valid code. The only way to suppress errors is to fix them. Just add the return statement it wants and then raise an issue on Microsoft Connect indicating that you believe the compiler is getting this one wrong.

I suspect, however, that this is expected behaviour as the compiler is not aware that the method you are calling will always throw and to determine that in a predictable manner for any possible call tree would be difficult, if not impossible (imagine if you called a chain of 20 methods before concluding with a throw).

Tuesday, October 25, 2022

First things first, you need to know that the command-line programs named gcc and g++ are only umbrella (wrappers) around the actual preprocessor/parser-compiler/assembler/linker commands. Their real name is cpp, cc1 or cc1plus, as and ld, respectively. GCC helps in unifying their use, command line interface and providing a meaningful set of default (and required) options for them. It is very hard, for example, to link a binary directly using ld - if ld is not run with all the 20+ (IIRC) correct options, it just fails to work.

Now that you know that, you can see:

Does it mean I am using ld ? I configured my project / Makefile so that g++ should do the linking, so why is LD still involved

It rather means you invoke GCC but in turn it invokes LD. GCC itself knows nothing - neither compiling, neither linking, as it's just a wrapper. (Go do a wc -c on /usr/bin/gcc and be surprised that it's only a few kilobytes! Now do the same for /usr/libexec/gcc/cc1plus and find out the horrifying truth: it is several 10 megs big!)

What does "collect2:" mean? Is it a step make invokes ? I can't find an executable with that name on my system.

Collect2 is also another level of indirection between gcc and ld. More about it on its official website.

Who is writing that message ? make ? ld ? g++ ?

Either g++ (that's it as far as I know) or collect2 itself maybe.

Is there a meaningful list of possible exit codes ?

The meaning is conventional - zero means success, nonzero means failure. If an exhaustive list exists, it should be able to be viewed by invoking man ld.

Wednesday, August 17, 2022

It seems like you forgot to create your List::getNewNode function.

Wednesday, August 10, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :