class vtkOBJWriter : public vtkPolyDataAlgorithm { public: //... virtual int writeMtllib(std::ofstream &fout){};//这里被编译了两次(见编译警告),而且链接到同一个文件.但是没有报错.. void setMtl(string s){// 同上 mMtllibStr = s; } }
/** int foo(){} //但是这个如果不注释的话不能编译. */
#endif ```
编译时,这个头文件被 main.cpp vtkOBJWriter.cxx include 却能编译.
[ 25%] Built target Non-Rigid-Registar
Scanning dependencies of target optimal_nonrigid_icp [ 50%] Building CXX object src/optimal_nonrigid_icp/CMakeFiles/optimal_nonrigid_icp.dir/vtkOBJWriter.cxx.o In file included from /Users/gerrie/repos/Non-Rigid-Registar/src/optimal_nonrigid_icp/vtkOBJWriter.cxx:29: /Users/gerrie/repos/Non-Rigid-Registar/src/optimal_nonrigid_icp/vtkOBJWriter.hpp:57:48: warning: control reaches end of non-void function [-Wreturn-type] virtual int writeMtllib(std::ofstream &fout){}; //这里被编译了两次(见编译警告),而且链接到同一个文件.但是没有报错.. ^ 1 warning generated. [ 75%] Building CXX object src/optimal_nonrigid_icp/CMakeFiles/optimal_nonrigid_icp.dir/main.cpp.o In file included from /Users/gerrie/repos/Non-Rigid-Registar/src/optimal_nonrigid_icp/main.cpp:17: /Users/gerrie/repos/Non-Rigid-Registar/src/optimal_nonrigid_icp/vtkOBJWriter.hpp:57:48: warning: control reaches end of non-void function [-Wreturn-type] virtual int writeMtllib(std::ofstream &fout){}; //这里被编译了两次(见编译警告),而且链接到同一个文件.但是没有报错.. ^ 1 warning generated. Linking CXX executable ../../bin/optimal_nonrigid_icp [100%] Built target optimal_nonrigid_icp
但是nm 显示只有一个.o正真包含这个符号:
O_O[11:03:07]release$ nm src/optimal_nonrigid_icp/CMakeFiles/optimal_nonrigid_icp.dir/vtkOBJWriter.cxx.o |grep writeMtllib 0000000000005a20 S __ZN12vtkOBJWriter11writeMtllibERNSt3__114basic_ofstreamIcNS0_11char_traitsIcEEEE 000000000000d680 S __ZN12vtkOBJWriter11writeMtllibERNSt3__114basic_ofstreamIcNS0_11char_traitsIcEEEE.eh 0000000000005ab0 S __ZN14myVtkOBJWriter11writeMtllibERNSt3__114basic_ofstreamIcNS0_11char_traitsIcEEEE 000000000000d700 S __ZN14myVtkOBJWriter11writeMtllibERNSt3__114basic_ofstreamIcNS0_11char_traitsIcEEEE.eh ^_^[11:03:16]release$ nm src/optimal_nonrigid_icp/CMakeFiles/optimal_nonrigid_icp.dir/main.cpp.o |grep writeMtllib O_O[11:05:19]release$