当前位置: 技术问答>linux和unix
急!急!急!急!急!本人制作的Makefile文件和程序,执行时错误,
来源: 互联网 发布时间:2015-08-04
本文导语: //a.h #ifndef __A_H__ #define __A_H__ class CAA { public: CAA(); virtual ~CAA(); public: void AA(); }; #endif //(__A_H__) //a.cpp #include "a.h" #include #include CAA::CAA() { } CAA::~CAA() { } void CAA::AA() { printf("This AA!n"); return; } //b.h #ifndef...
//a.h
#ifndef __A_H__
#define __A_H__
class CAA
{
public:
CAA();
virtual ~CAA();
public:
void AA();
};
#endif //(__A_H__)
//a.cpp
#include "a.h"
#include
#include
CAA::CAA()
{
}
CAA::~CAA()
{
}
void CAA::AA()
{
printf("This AA!n");
return;
}
//b.h
#ifndef __B_H__
#define __B_H__
class CBB
{
public:
CBB();
virtual ~CBB();
public:
void BB();
};
#endif //(__B_H__)
//b.cpp
#include "b.h"
#include
#include
CBB::CBB()
{
}
CBB::~CBB()
{
}
void CBB::BB()
{
printf("This BB!n");
return;
}
//Main.cpp
#include "a.h"
#include "b.h"
int main()
{
CAA a;
CBB b;
a.AA();
b.BB();
return 0;
}
//Makefile
Main: a.o b.o Main.o
a.o: a.cpp a.h
g++ -c -g a.cpp
b.o: b.cpp b.h
g++ -c -g b.cpp
Main.o: a.h b.h Main.cpp
g++ -c -g Main.cpp
//执行是错误,是连接的错误,那位大虾可以解决这个问题,下面为错误代码。
[sheep@workserver sheep]$ make
g++ -c -g Main.cpp
g++ -c -g a.cpp
g++ -c -g b.cpp
cc Main.o a.o b.o -o Main
Main.o(.eh_frame+0x12): In function `main':
/home/sheep/Main.cpp:7: undefined reference to `__gxx_personality_v0'
a.o(.text+0x3e): In function `CAA::~CAA [not-in-charge]()':
/home/sheep/a.cpp:13: undefined reference to `operator delete(void*)'
a.o(.text+0x6a): In function `CAA::~CAA [in-charge]()':
/home/sheep/a.cpp:13: undefined reference to `operator delete(void*)'
a.o(.text+0x96): In function `CAA::~CAA [in-charge deleting]()':
/home/sheep/a.cpp:13: undefined reference to `operator delete(void*)'
a.o(.gnu.linkonce.d._ZTI3CAA+0x0):/home/sheep/a.cpp:6: undefined reference to `vtable for __cxxabiv1::__class_type_info'
b.o(.text+0x3e): In function `CBB::~CBB [not-in-charge]()':
/home/sheep/b.cpp:13: undefined reference to `operator delete(void*)'
b.o(.text+0x6a): In function `CBB::~CBB [in-charge]()':
/home/sheep/b.cpp:13: undefined reference to `operator delete(void*)'
b.o(.text+0x96): In function `CBB::~CBB [in-charge deleting]()':
/home/sheep/b.cpp:13: undefined reference to `operator delete(void*)'
b.o(.gnu.linkonce.d._ZTI3CBB+0x0):/home/sheep/b.cpp:6: undefined reference to `vtable for __cxxabiv1::__class_type_info'
collect2: ld returned 1 exit status
make: *** [Main] Error 1
#ifndef __A_H__
#define __A_H__
class CAA
{
public:
CAA();
virtual ~CAA();
public:
void AA();
};
#endif //(__A_H__)
//a.cpp
#include "a.h"
#include
#include
CAA::CAA()
{
}
CAA::~CAA()
{
}
void CAA::AA()
{
printf("This AA!n");
return;
}
//b.h
#ifndef __B_H__
#define __B_H__
class CBB
{
public:
CBB();
virtual ~CBB();
public:
void BB();
};
#endif //(__B_H__)
//b.cpp
#include "b.h"
#include
#include
CBB::CBB()
{
}
CBB::~CBB()
{
}
void CBB::BB()
{
printf("This BB!n");
return;
}
//Main.cpp
#include "a.h"
#include "b.h"
int main()
{
CAA a;
CBB b;
a.AA();
b.BB();
return 0;
}
//Makefile
Main: a.o b.o Main.o
a.o: a.cpp a.h
g++ -c -g a.cpp
b.o: b.cpp b.h
g++ -c -g b.cpp
Main.o: a.h b.h Main.cpp
g++ -c -g Main.cpp
//执行是错误,是连接的错误,那位大虾可以解决这个问题,下面为错误代码。
[sheep@workserver sheep]$ make
g++ -c -g Main.cpp
g++ -c -g a.cpp
g++ -c -g b.cpp
cc Main.o a.o b.o -o Main
Main.o(.eh_frame+0x12): In function `main':
/home/sheep/Main.cpp:7: undefined reference to `__gxx_personality_v0'
a.o(.text+0x3e): In function `CAA::~CAA [not-in-charge]()':
/home/sheep/a.cpp:13: undefined reference to `operator delete(void*)'
a.o(.text+0x6a): In function `CAA::~CAA [in-charge]()':
/home/sheep/a.cpp:13: undefined reference to `operator delete(void*)'
a.o(.text+0x96): In function `CAA::~CAA [in-charge deleting]()':
/home/sheep/a.cpp:13: undefined reference to `operator delete(void*)'
a.o(.gnu.linkonce.d._ZTI3CAA+0x0):/home/sheep/a.cpp:6: undefined reference to `vtable for __cxxabiv1::__class_type_info'
b.o(.text+0x3e): In function `CBB::~CBB [not-in-charge]()':
/home/sheep/b.cpp:13: undefined reference to `operator delete(void*)'
b.o(.text+0x6a): In function `CBB::~CBB [in-charge]()':
/home/sheep/b.cpp:13: undefined reference to `operator delete(void*)'
b.o(.text+0x96): In function `CBB::~CBB [in-charge deleting]()':
/home/sheep/b.cpp:13: undefined reference to `operator delete(void*)'
b.o(.gnu.linkonce.d._ZTI3CBB+0x0):/home/sheep/b.cpp:6: undefined reference to `vtable for __cxxabiv1::__class_type_info'
collect2: ld returned 1 exit status
make: *** [Main] Error 1
|
//Makefile
all: Main
Main: a.o b.o Main.o
g++ -g -o Main a.o b.o Main.o
a.o: a.cpp a.h
g++ -c -g a.cpp
b.o: b.cpp b.h
g++ -c -g b.cpp
Main.o: a.h b.h Main.cpp
g++ -c -g Main.cpp
all: Main
Main: a.o b.o Main.o
g++ -g -o Main a.o b.o Main.o
a.o: a.cpp a.h
g++ -c -g a.cpp
b.o: b.cpp b.h
g++ -c -g b.cpp
Main.o: a.h b.h Main.cpp
g++ -c -g Main.cpp
|
最后不能用cc去做连接,用g++好了。
|
CC 和 GCC 和 G++ 用一个就行了.
|
把cc改为c++
|
楼上很详细了,
补充一点:写Makefile时,*.o和*.cpp的写法也是支持的。
补充一点:写Makefile时,*.o和*.cpp的写法也是支持的。