嗨我想知道哪一部分错了?将我的头文件分成.h和.cpp后,编译器无法正常工作,因为它们只是构造函数,因此我将它们全部放在我的.h文件中。谢谢!
Graphnode.h:
#ifndef Graphnode_H
#define Graphnode_H
#include <tr1/array>
//using namespace std;
class Graphnode {
public:
std::tr1::array<char, 16> state;
char x;
char depth;
char direction;
Graphnode(std::tr1::array<char, 16> _state,char _x,char _d,char _direction);
Graphnode();
};
#endif
Graphnode.cpp:
#include "Graphnode.h"
Graphnode::Graphnode()
{
int i=0;
for(i=0;i<16;i++)
{
state[i] = 0;
}
x = 0;
depth = 0;
direction = 0;
}
Graphnode::Graphnode(std::tr1::array<char, 16> _state,char _x,char _d,char _direction)
{
int i=0;
for(i=0;i<16;i++)
{
state[i] = _state[i];
}
x = _x;
depth = _d;
direction = _direction;
}
错误:
ZION:ods_v3 weeo$ make local
mpic++ -o local ods_v3.cpp -L/opt/local/lib/ -lboost_iostreams-mt -lz -I/opt/local/include
Undefined symbols for architecture x86_64:
"Graphnode::Graphnode(std::tr1::array<char, 16ul>, char, char, char)", referenced from:
_main in ods_v3-semJJ5.o
"Graphnode::Graphnode()", referenced from:
bfs(Graphnode, std::tr1::array<char, 16ul>, char, std::queue<Graphnode, std::deque<Graphnode, std::allocator<Graphnode> > >&) in ods_v3-semJJ5.o
dfs(Graphnode, std::tr1::array<char, 16ul>, char, std::queue<Graphnode, std::deque<Graphnode, std::allocator<Graphnode> > >, std::queue<Graphnode, std::deque<Graphnode, std::allocator<Graphnode> > >, std::tr1::array<std::tr1::unordered_map<std::string, char, std::tr1::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, char> >, false>, 2000ul>) in ods_v3-semJJ5.o
readcheckfile(char const*, std::queue<Graphnode, std::deque<Graphnode, std::allocator<Graphnode> > >&) in ods_v3-semJJ5.o
_main in ods_v3-semJJ5.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [local] Error 1
答案 0 :(得分:2)
您的makefile看起来已损坏或不完整。输出建议您构建ods_v3.cpp,并且没有跟踪具有mssing定义的Graphnode.cpp发生的任何事情。在构建中包含Graphnode.cpp或在ods_v2.cpp中包含#include.cpp