Strogenstroff
Strogenstroff

Reputation: 47

Using the C99 standard causes GCC compiler errors

I have a very simple print program called "print.c":

#include <stdio.h>

int main(void){
        printf("Random words");
}

Compiling with the command gcc -o print print.c causes a completely clean compile and the executable runs as expected.

Compiling with the command gcc -o -std=c99 print print.c gives me:

print: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crti.o:(.fini+0x0): first defined here
print: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crt1.o:(.data+0x0): first defined here
print: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i686-linux-gnu/4.6.1/crtbegin.o:(.data+0x0): first defined here
print:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
print: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crt1.o:(.text+0x0): first defined here
print:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crt1.o:(.rodata+0x0): first defined here
print: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crti.o:(.init+0x0): first defined here
/tmp/ccfvqWMW.o: In function `main':
print.c:(.text+0x0): multiple definition of `main'
print:(.text+0xb4): first defined here
/usr/lib/gcc/i686-linux-gnu/4.6.1/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
print:(.dtors+0x4): first defined here
/usr/bin/ld: error in print(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status

Does anyone know how to fix this?

Upvotes: 2

Views: 2847

Answers (3)

caf
caf

Reputation: 239011

Your print isn't being interpreted as the argument to the -o option, so it's trying to relink your print executable from the first compilation. This includes numerous symbols that duplicate other symbols it's trying to link, hence the errors.

Try instead:

gcc -std=c99 -o print print.c

or better yet:

gcc -std=c99 -Wall -g -O -o print print.c

Upvotes: 10

Richard Pennington
Richard Pennington

Reputation: 19965

Use this command line:

gcc -o print -std=c99  print.c

Upvotes: 1

Paul Beusterien
Paul Beusterien

Reputation: 29547

The command should be gcc -o print -std=c99 print.c The -o parameter specifies that the next token is the output file.

Upvotes: 4

Related Questions