the difference between g++ and gcc
本问题已经有最佳答案,请猛点这里访问。
我只有一个简单的C主程序,有一个类voronoidiagramgenerator.cpp和voronoidiagramgenerator.h是类定义,在主函数中调用类方法。为什么我使用gcc和g++给出不同的输出。使用gcc有一些错误。使用G++就可以了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | jack@ubuntu:~/dev/practice$ gcc main.cpp VoronoiDiagramGenerator.cpp -o main /tmp/ccbaXM5L.o:(.eh_frame+0x6b): undefined reference to `__gxx_personality_v0' /tmp/ccCeOqcL.o: In function `VoronoiDiagramGenerator::VoronoiDiagramGenerator()': VoronoiDiagramGenerator.cpp:(.text+0x22): undefined reference to `operator new(unsigned int)' /tmp/ccCeOqcL.o: In function `VoronoiDiagramGenerator::reset()': VoronoiDiagramGenerator.cpp:(.text+0x168): undefined reference to `operator delete(void*)' /tmp/ccCeOqcL.o: In function `VoronoiDiagramGenerator::geominit()': VoronoiDiagramGenerator.cpp:(.text+0xc3d): undefined reference to `sqrt' /tmp/ccCeOqcL.o: In function `VoronoiDiagramGenerator::dist(Site*, Site*)': VoronoiDiagramGenerator.cpp:(.text+0x1318): undefined reference to `sqrt' /tmp/ccCeOqcL.o: In function `VoronoiDiagramGenerator::getfree(Freelist*)': VoronoiDiagramGenerator.cpp:(.text+0x17aa): undefined reference to `operator new(unsigned int)' /tmp/ccCeOqcL.o: In function `VoronoiDiagramGenerator::cleanup()': VoronoiDiagramGenerator.cpp:(.text+0x18cd): undefined reference to `operator delete(void*)' VoronoiDiagramGenerator.cpp:(.text+0x1917): undefined reference to `operator delete(void*)' VoronoiDiagramGenerator.cpp:(.text+0x1923): undefined reference to `operator new(unsigned int)' /tmp/ccCeOqcL.o: In function `VoronoiDiagramGenerator::cleanupEdges()': VoronoiDiagramGenerator.cpp:(.text+0x19e4): undefined reference to `operator delete(void*)' VoronoiDiagramGenerator.cpp:(.text+0x1a3f): undefined reference to `operator delete(void*)' /tmp/ccCeOqcL.o: In function `VoronoiDiagramGenerator::pushGraphEdge(float, float, float, float)': VoronoiDiagramGenerator.cpp:(.text+0x1a8b): undefined reference to `operator new(unsigned int)' /tmp/ccCeOqcL.o: In function `VoronoiDiagramGenerator::pushDelaunayGraphEdge(float, float, float, float)': VoronoiDiagramGenerator.cpp:(.text+0x1afa): undefined reference to `sqrt' VoronoiDiagramGenerator.cpp:(.text+0x1b1a): undefined reference to `operator new(unsigned int)' /tmp/ccCeOqcL.o: In function `VoronoiDiagramGenerator::clip_line(Edge*)': VoronoiDiagramGenerator.cpp:(.text+0x1e50): undefined reference to `sqrt' /tmp/ccCeOqcL.o: In function `VoronoiDiagramGenerator::generateVertexLinks()': VoronoiDiagramGenerator.cpp:(.text+0x33f4): undefined reference to `operator delete[](void*)' VoronoiDiagramGenerator.cpp:(.text+0x3413): undefined reference to `operator delete[](void*)' collect2: ld 返回 1 |
但是用G++就可以了
1 2 | jack@ubuntu:~/dev/practice$ g++ main.cpp VoronoiDiagramGenerator.cpp -o main jack@ubuntu:~/dev/practice$ |
号
这两者都是由gcc工具链提供的,并且都是编译器前端的[包装器],但它们并不相同:
gcc 编译c;- EDCOX1〔1〕编译C++。
C++标准库符号和C++运行时所需的各种其他符号以支持C++代码,只与后者连接(默认情况下)。
i just have a simple c main program and have a class, VoronoiDiagramGenerator.cpp and VoronoiDiagramGenerator.h is the class defination
号
我猜你的意思是一个简单的C++程序。C不是C++,C++不是C。它们是两种不同的语言。