eclipse - build error related to g++ -c flag -
i dont understand g++ -c flag . based on definition:compile or assemble source files, not link. linking stage not done. ultimate output in form of object file each source file. need understand cause error following build process. thanks
i try compile sample helloworld program in eclipse.
#include <iostream> using namespace std; int main () { cout << "hello world!"; return 0; }
without -c. eclipse gives me error:
make 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 created. collect2: ld returned 1 exit status make: *** [app.so] error 1 11:25:49 build finished (took 463ms)
with -c , build fine:
11:33:16 **** incremental build of configuration debug project app **** make 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 build finished (took 311ms)
new fix generate executable file
13:32:44 **** incremental build of configuration debug project app **** make 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
in first case, without -c, first g++ invocation generates linked executable misleadingly named "app.o". (try typing "file ./app.o" describe file in both cases. might interesting.) able run it. (type ./app.o)
with -c flag, g++ invocation generates object code , is suitable further link stage (as observe).
Comments
Post a Comment