2

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?

3 Answers 3

10

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
Sign up to request clarification or add additional context in comments.

1 Comment

@RichardPennington: The OP wants the print to be interpreted as the argument to -o (the output filename), but it's not - so it's being interpreted as an input file instead.
4

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

1 Comment

Yeah, that fixed it . Sorry about that, I'm pretty new to C
1

Use this command line:

gcc -o print -std=c99  print.c

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.