$ gcc -o -g firstdrvtest firstdrvtest.c
报错:
firstdrvtest: 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
firstdrvtest: 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
firstdrvtest: 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
firstdrvtest:(.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
firstdrvtest: 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
firstdrvtest: 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
/tmp/ccztJcA4.o: In function `main':
firstdrvtest.c:(.text+0x0): multiple definition of `main'
firstdrvtest:(.text+0xf6): first defined here
/usr/lib/gcc/x86_64-linux-gnu/5/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'
firstdrvtest:(.data+0x10): first defined here
/usr/bin/ld: error in firstdrvtest(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status
在网上搜索后才知道,这是因为-g是选项,后面不需要给参数,而-o是参数,后面需要加上输出文件名称,所以,gcc -o -g firstdrvtest firstdrvtest.c,会生成一个-g的输出文件,而后面的firstdrvtest就成非法参数了。
正确的写法是gcc -g -o firstdrvtest firstdrvtest.c,让-g在-o之后,编译器就不会报告这样的错误了。