用gcc怎么进行c++编程?
1. bbb.h
#include <stdio.h>
class myclass
{
public :
myclass();
~myclass();
void mmm();
};
2. bbb.cxx
#include "bbb.h"
myclass::myclass()
{
}
myclass::~myclass()
{
}
void myclass::mmm()
{
printf("aaaaa");
}
3. main.cxx
#include <stdio.h>
#include "bbb.h"
int main()
{
myclass * aaa;
aaa = new myclass();
aaa->mmm();
delete[] aaa;
return 0;
}
4. makefile
test: main.o bbb.o
gcc -o test main.o bbb.o
main.o: main.cxx
gcc -c main.cxx
bbb.o: bbb.cxx bbb.h
gcc -c bbb.cxx
5.make
结果:
gcc -c main.cxx (通过)
gcc -c bbb.cxx (通过)
gcc -o test main.o bbb.o
main.o(.text+0x16): In function `main':
: undefined reference to `operator new(unsigned)'
main.o(.text+0x54): In function `main':
: undefined reference to `operator delete(void*)'
main.o(.text+0x79): In function `main':
: undefined reference to `operator delete(void*)'
main.o(.text+0xcc): In function `main':
: undefined reference to `operator delete[](void*)'
main.o(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
make: *** [test] Error 1
why?
问题点数:20、回复次数:1Top
1 楼pacman2000(pacman)(影子传说)回复于 2004-09-01 18:20:51 得分 20
把gcc改成g++编译Top




