I was trying to run the following program when this big error occurred. What am I doing wrong?
#include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <string.h> #include <stdlib.h> int main() { char *file = "zahl.txt"; int fd; struct flock lock = { F_WRLCK, SEEK_SET, 0, 0, 0 }; lock.l_pid = getpid(); fd = open(file, O_RDWR | O_APPEND); if (fcntl(fd, F_SETLKW, &lock) != -1) //setting the lock to wait while another instance is already running { FILE *fp1; int i; char buff[255]; fp1 = fopen(file, "a+"); //read from file while (fgets(buff, 255, fp1) != NULL); //moves to last line of file i = atoi(buff); i++; char temp[10]; sprintf(temp, "%d\n", i); //printing the incremented value to temp fputs(temp, fp1); fclose(fp1); lock.l_type = F_UNLCK; fcntl(fd, F_SETLK, &lock); close(fd); } return 0; } [rmig0489@linux Assign9]$ gcc -Wall -o -g ink ink.cink: In function
_start': (.text+0x0): multiple definition of_start' /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o:(.text+0x0): first defined here ink: In function_fini': (.fini+0x0): multiple definition of_fini' /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crti.o:(.fini+0x0): first defined here ink:(.rodata+0x0): multiple definition of_IO_stdin_used' /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o:(.rodata.cst4+0x0): first defined here ink: In function__data_start': (.data+0x0): multiple definition of__data_start' /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o:(.data+0x0): first defined here ink:(.rodata+0x8): multiple definition of__dso_handle' /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtbegin.o:(.rodata+0x0): first defined here ink: In function_init': (.init+0x0): multiple definition of_init' /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crti.o:(.init+0x0): first defined here /tmp/ccmuhndv.o: In functionmain': ink.c:(.text+0x0): multiple definition ofmain' ink:/home/scs/licenta/an1/gr712/rmig0489/C-Programm/Assign9/ink.c:6: first defined here /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtend.o:(.dtors+0x0): multiple definition of `DTOR_END' ink:(.dtors+0x8): first defined here /usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored. /usr/bin/ld: error in ink(.eh_frame); no .eh_frame_hdr table will be created. collect2: ld returned 1 exit status
gcc -Wall -o ink -g ink.c-gas output file andink ink.cas input files.