#70 Cannot find main() when linking archives?

closed
binutils (7)
5
2011-07-27
2011-07-18
Oliver Maye
No

When (under Windows) linking an archive that contains the main() function (e.g. against the libc), the linker complains about missing main() function. The behaviour can be reproduced as follows.
With a tiny little test program held in test.c:
----------------------------------
#include <stdio.h>

int main( int argc, const char *argv[] ) {
printf("Hallo World\n");
return 0;
}

int putchar( int character ) {
return character;
}

----------------------------------
1) Compile source into object is ok:
msp430-gcc -c -o test.o test.c
2) Then archiving this object file into an archive is fine, as well:
msp430-ar rcs test.a test.o
3) Finally linking this archive against libc produces an error:
msp430-gcc -o test.exe test.a
/cygdrive/d/msp430gcc4/bin/../lib/gcc/msp430/4.4.4/libgcc.a(__jump_to_main.o): In function `__jump_to_main':
/cygdrive/d/mspgcc4-20100829/build/gcc-4.4.4-build/../gcc-4.4.4/libgcc/../gcc/config/msp430/libgcc.S:724: undefined reference to `main'
collect2: ld returned 1 exit status

Linking the object file directly against the libc works fine:
msp430-gcc -o test.exe test.o
Also, the one-step build goes fine:
msp430-gcc -o test.exe test.c

Maybe, the archiver produces a wrong format, or there is a bug in how the linker handles an archive...?

Discussion

  • Peter A. Bigot

    Peter A. Bigot - 2011-07-18

    Please try to reproduce this problem with the recently posted mingw Windows binaries for mspgcc 20110716 at https://sourceforge.net/projects/mspgcc/files/Windows/mingw32/, or with your own build of mspgcc-20110716 on WIndows. mspgcc4 is no longer supported.

    With the current mspgcc, you will have to provide the -mmcu flag on all phases including linking, so the correct CRT files are located.

     
  • Oliver Maye

    Oliver Maye - 2011-07-19

    Using that gcc I couldn't reproduce this error, anymore. So seems working for my little test program.
    However, the current mspgcc produces other error messages, unrelated to the archive/link problem. So I'll leave a bug report there. For now, I regard this issue as being resolved.

     
  • Andrey Vihrov

    Andrey Vihrov - 2011-07-19

    Hi.

    > mspgcc4 is no longer supported

    You should put up a notice on both project websites. Right now there is no information regarding what you mentioned, and this could well confuse people.

     
  • Peter A. Bigot

    Peter A. Bigot - 2011-07-27
    • status: open --> closed
     
  • Peter A. Bigot

    Peter A. Bigot - 2011-07-27

    Closing as not reproducible in mspgcc. (I'll be updating the various documentation to deprecate mspgcc4 soon.)

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks