-1

I just have a simple c main program and have a class, VoronoiDiagramGenerator.cpp and VoronoiDiagramGenerator.h is the class definition, in main function call the class method. Why I use the gcc and g++ giving different output. Using gcc have some error, but it's OK using 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

but using g++, all is OK

jack@ubuntu:~/dev/practice$ g++ main.cpp VoronoiDiagramGenerator.cpp -o main
jack@ubuntu:~/dev/practice$ 
NAND
  • 663
  • 8
  • 22
user1279988
  • 757
  • 1
  • 11
  • 27

1 Answers1

4

Both are provided by the GCC toolchain, and both are [wrappers around] compiler front-ends, but they are not the same thing:

  • gcc compiles C;
  • g++ compiles C++.

The C++ standard library symbols, and various other symbols required by the C++ runtime in order to support your C++ code, are only linked in with the latter (by default).


i just have a simple c main program and have a class, VoronoiDiagramGenerator.cpp and VoronoiDiagramGenerator.h is the class defination

I guess you mean a simple C++ program. C is not C++, and C++ is not C. They are two different languages.

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • how make my programm can compile using gcc? And if i want to using the valgrind to check the memoryleak, will both gcc or g++ is OK? – user1279988 Dec 31 '13 at 05:13
  • 1
    @user1279988: `g++` is fine. You could have just tried it. – Lightness Races in Orbit Dec 31 '13 at 05:13
  • Point of clarity: "and C++ is not C" - C++ is (for the most part) a superset of C. – Zac Howland Dec 31 '13 at 05:17
  • 1
    @Zac: Point of clarity: They are distinct languages and that is all that is important. Pretending that one is a superset of the other just muddies the waters. – Lightness Races in Orbit Dec 31 '13 at 14:59
  • @LightnessRacesinOrbit Distinct implies they are completely separate (that is, they would be *unmistakably* different). This is not entirely true (hence the `` header files). While you cannot use C++ features when compiling using a C compiler, you can use all but a few C features when compiling using a C++ compiler. – Zac Howland Dec 31 '13 at 15:12
  • @ZacHowland: So? They are different languages. They have different semantics, different rules, different definitions for things. Especially in C++11 it's _easy_ to come up with C++ programs that are not valid C. Yes, C++ inherits C99 headers. Yes, C++ is "based on" C. Does that mean one is a superset of the other, or that it is helpful to focus on this? No. What is important is to remind language newcomers that they are _two different languages_ and ought to be treated as such in all things. – Lightness Races in Orbit Dec 31 '13 at 15:14
  • @LightnessRacesinOrbit Even with C++98, it was *easy* to write a C++ program that was not valid C - that was not my point. It is much harder to write C code that will not be valid C++ (which was my point). They are not two *different* langauges, but rather two *related* languages. The relationship between the two is important - especially with questions like this one (or [this one](http://stackoverflow.com/a/4388676/529761)). – Zac Howland Dec 31 '13 at 15:43
  • No, the fact that they are distinct is what is important in this question. The OP confusing the two is what has caused the problem. Treat them independently and you will not have any issues. (Have you compared name lookup rules between them lately?) – Lightness Races in Orbit Dec 31 '13 at 15:51