-2

I wrote a C program on Linux. When I compile the program, no errors occur, but when I run it, I receive a number of errors. My program is,

#include <stdio.h>

typedef struct a{
 char *name;
 int id;
 char *department;
 int num;
} ab;

int main()
{
 ab array[2]={{"Saud",137,"Electronics",500},{"Ebad",111,"Telecom",570}};
 printf("First student data:\n%s\t%d\t%s\t%d",array[0].name,array[0].id,
     array[0].department,array[0].num);

 //ab swap(&array[]);
}

Errors are:

./newproject: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here
./newproject: In function `data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here
./newproject: In function `data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/5/crtbegin.o:(.data+0x0): first defined here
./newproject:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
./newproject: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:(.text+0x0): first defined here
./newproject: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/x86_64-linux-gnu/5/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'
./newproject:(.data+0x10): first defined here
/usr/bin/ld: error in ./newproject(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status
David C. Rankin
  • 81,885
  • 6
  • 58
  • 85
Saud Farooqui
  • 27
  • 1
  • 10

1 Answers1

1

To compile you need to write this:

gcc -o newproject newproject.c

this creates a file named newproject which you can run by writing this:

./newproject

It doesn't make any sense to write gcc ./newproject to run your program.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115