g++和gcc的区别 [重复] 。

问题描述 投票:-2回答:1

我只是有一个简单的C主程序和一个类。VoronoiDiagramGenerator.cppVoronoiDiagramGenerator.h 是类的定义,在 main 函数调用类方法。为什么我使用 gccg++ 给予不同的输出。使用 gcc 有一些错误,但使用g++是可以的。

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++,一切正常

jack@ubuntu:~/dev/practice$ g++ main.cpp VoronoiDiagramGenerator.cpp -o main
jack@ubuntu:~/dev/practice$ 
c++ gcc compilation g++
1个回答
3
投票

两者都是由GCC工具链提供的,都是[围绕]编译器前端的[包装器],但 两者不是一回事:

  • gcc 编制 C;
  • g++ 编译 C++.

C++标准库符号,以及C++运行时为了支持你的C++代码所需要的各种其他符号,都只与后者链接在一起(默认情况下)。


我只是有一个简单的c主程序,并有一个类,VoronoiDiagramGenerator.cpp和VoronoiDiagramGenerator.h是该类的定义。

我想你的意思是一个简单的 C++ 程序。C不是C++,C++也不是C,它们是两种不同的语言。

© www.soinside.com 2019 - 2024. All rights reserved.