我正在开发一个需要我使用各种类的项目。 出于某种原因,每当我尝试编译,我得到一个错误,指出:
Undefined symbols for architecture x86_64:
C++多类导致架构错误
我原本是工作的一个类,我们可以调用User
是曾在user.h
这样的声明:
#ifndef USER_H
#define USER_H
...other include statements
class User
{
public:
User();
public and private members and functions
};
#endif
这些方法的定义被安置在同一目录中的单独文件中,user.cpp
。
每当我尝试编译,我会得到一个错误,说有构造函数和析构函数的未定义符号。我在.cpp
文件中定义了这两个,但我无法让错误消失。
我包括用户类主要有以下几点:
#include "user.h"
我设法通过粘贴从user.cpp
文件中的所有代码到user.h
来解决这个问题,但是现在我有其他类,它们的代码,我的问题我不允许修改。
现在,我有一个叫做GMLReader的类,在gmlreader.h
中有一个静态调用的方法。然而,即使我将其导入我的主,我收到以下错误代码每当我试图把它叫做:
Undefined symbols for architecture x86_64:
"GMLReader::read(char const*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)", referenced from:
_main in cchnzOEh.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
我现在用的是在与sn.cpp
编译住房我的主:
g++ -g -Wall -o sn sn.cpp
是否有任何这样的错误会发生的原因,我该如何去解决它?
我之前有很多已经得到了这个错误,请确保您传递正确类型的变量的函数 – TopGunCoder
是你的目标体系的确是64位?可能有些文件正在编译32位,其他文件正在编译64位。 – paddy
另外,向我们展示'#include'语句以及如何编译代码。 –