我在Linux上写了一个C程序。当我编译程序时,没有错误发生,但是当我运行它时,我收到了一些错误。我的节目是,
#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[]);
}
错误是:
./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
答案 0 :(得分:1)
要编译,你需要写这个:
gcc -o newproject newproject.c
这将创建一个名为newproject
的文件,您可以通过编写此文件来运行该文件:
./newproject
将gcc ./newproject
写入运行您的程序没有任何意义。