我不明白 g++ -c flag 。根据定义:编译或汇编源文件,但不要链接。链接阶段根本没有完成。最终输出是每个源文件的目标文件形式。我需要帮助来了解导致以下构建过程错误的原因。谢谢
我尝试在 Eclipse 中编译示例 helloworld 程序。
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
没有-c。日食给了我错误:
make all
Building file: ../app.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -fmessage-length=0 -fPIC -MMD -MP -MF"app.d" -MT"app.d" -o "app.o" "../app.cpp"
Finished building: ../app.cpp
Building target: app.so
Invoking: GCC C++ Linker
g++ -shared -o "app.so" ./app.o
./app.o: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-redhat-linux/4.6.3/../../../../lib64/crti.o:(.fini+0x0): first defined here
./app.o: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-redhat-linux/4.6.3/../../../../lib64/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.6.3/crtendS.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
./app.o:(.dtors+0x8): first defined here
/usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored.
/usr/bin/ld: error in ./app.o(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status
make: *** [app.so] Error 1
11:25:49 Build Finished (took 463ms)
使用 -c ,它构建得很好:
11:33:16 **** Incremental Build of configuration Debug for project app ****
make all
Building file: ../app.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"app.d" -MT"app.d" -o "app.o" "../app.cpp"
Finished building: ../app.cpp
Building target: app.so
Invoking: GCC C++ Linker
g++ -shared -o "app.so" ./app.o
Finished building target: app.so
11:33:16 构建完成(耗时 311 毫秒)
生成可执行文件的新修复
13:32:44 **** Incremental Build of configuration Debug for project app ****
make all
Building file: ../app.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -fPIC -MMD -MP -MF"app.d" -MT"app.d" -o "app.o" "../app.cpp"
Finished building: ../app.cpp
Building target: app
Invoking: GCC C++ Linker
g++ -shared -o "app" ./app.o
Finished building target: app