c++中的体系结构x86_64错误
architecture x86_64 error in c++
当我试图在mac上用g++运行这个c++代码时,我会收到以下错误。有人能告诉我这是什么意思吗。我是编程新手。因此,我们将非常感谢您的帮助。我正在尝试使用抽象类(Expr.cpp)和子类(Binary.cpp)来实现这一点。
我用g++main.cpp编译
错误-
Undefined symbols for architecture x86_64:
"Expr::Expr()", referenced from:
stepexecution(double, double, double)in cc8Vni4M.o
"Expr::setArg(double)", referenced from:
stepexecution(double, double, double)in cc8Vni4M.o
"Expr::setRece(double)", referenced from:
stepexecution(double, double, double)in cc8Vni4M.o
"Binary::sum()", referenced from:
stepexecution(double, double, double)in cc8Vni4M.o
"Expr::Expr()", referenced from:
Binary::Binary()in cc8Vni4M.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
代码
main.cpp-
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void stepexecution(double x, double y, double z)
{
string STRING;
Expr ex;
Binary bi;
ifstream infile;
char ele1;
char ele2;
char rece;
double d = 7;
infile.open ("program.txt");
while(!infile.eof()) // To get you all the lines.
{
getline(infile,STRING);
int length = STRING.length();
if(length>8)
{
rece = STRING.at(0);
ele1 = STRING.at(4);
ele2 = STRING.at(8);
cout << ele1 << ele2;
if(ele1=='x' && ele2=='y')
{
ex.setArg(x);
ex.setRece(y);
double a = bi.sum();
cout << a;
}
}
}
infile.close();
}
int main()
{
char c;
int t = 0;
double x = 10;
double y = 0;
double z = 0;
while(t==0)
{
cout << "Please enter a command:";
cin >> c;
if(c=='r')
{
x=0;
y=0;
z=0;
}
if(c=='x')
{
cout << "Please enter the value of x:";
cin >> x;
}
if(c=='y')
{
cout << "Please enter the value of x:";
cin >> y;
}
if(c=='z')
{
cout << "Please enter the value of x:";
cin >> z;
}
if(c=='s')
{
stepexecution(x,y,z);
}
if(c=='q')
{
exit(0);
}
}
}
Expr.cpp-
#include "Expr.h"
void Expr::setRece(double x)
{
rece = x;
}
void Expr::setArg(double y)
{
arg = y;
}
//Constructor.
Expr::Expr()
{
}
Expr.h-
#ifndef ____Expr__
#define ____Expr__
#include <iostream>
#include "math.h"
using namespace std;
class Expr {
public:
void setRece(double x);
void setArg(double y);
Expr();
protected:
double arg, rece;
};
#endif /* defined(____Expr__) */
Binary.cpp-
#include "Binary.h"
double Binary::sum()
{
return rece+arg;
}
double Binary::subt()
{
return rece-arg;
}
double Binary::mult()
{
return rece*arg;
}
double Binary::divi()
{
return rece/arg;
}
double Binary::exp()
{
return pow(rece,arg);
}
二进制.h-
#ifndef ____Binary__
#define ____Binary__
#include "Expr.h"
#include <iostream>
using namespace std;
class Binary : public Expr
{
public:
double sum();
double subt();
double mult();
double divi();
double exp();
};
#endif
感谢您的帮助:)
此错误表示您没有正确链接对象文件。所有对象文件都必须链接到最终程序。
如果它们是链接的,那么有一些函数不在链接的任何对象文件中。请链接正确的文件。
要编译文件以生成obj文件,请使用
g++ -o binary.o -c binary.cpp
g++ -o expr.o -c expr.cpp
最后链接到主文件使用,
g++ -o main main.cpp expr.o binary.o
相关文章:
- Apple Mach-O-Linker 错误:在体系结构 x86-64 中找不到从(行)引用的变量
- 致命错误LNK1112:在 npm 安装期间,模块计算机类型'X86'与目标计算机类型'x64'冲突
- C++/CLR:仅在编译 x86 时出现命令行错误
- Bullet Physics源代码未在X86中构建 - Visual Studio 2017中错误的预处理器指令
- LNK2001在X64环境中的编译代码上看到的错误.但是,该代码在X86环境中填充了罚款
- 致命错误LNK1112:通过 vcvarsall .bat x86 运行构建'X86'模块计算机类型'x64'与目标计算机类型冲突
- QtGui4.lib(QtGui4.dll):致命错误LNK1112:模块计算机类型"X86"与目标计算机类型"x64"冲突
- Visual C 2012(x86)中可能的编译器错误
- x86逻辑地址语法错误
- Solaris 5.10 x86 CC链接器错误:ld:致命:找不到库-lcryptoki:
- C:x86 英特尔内在函数对 _mm_log2_ps() -> 错误的用法:不兼容的类型"int"?
- C++中的指针和对象,x86 编译错误
- x86 上的 Android NDK 和 STL 相关参考错误
- 链接错误:QtCore.framework/Versions/4/QtCore for Architecture x86
- 错误0xc000007b:试图在没有VS的计算机上运行编译为Release x86的C++.exe文件
- 没有规则来使目标"类.cpp,"构建/..."需要x86/class.o' 停止。乌班图中的错误
- 用于调试X86构建的Visual Studio链接器错误
- 将c++项目类型从x86更改为x64后的链接器错误
- msvcprtd.lib(MSVCP100D.dll):致命错误LNK1112:模块计算机类型"X86"与目标计算机类型"x64"冲突
- LNK2019错误:在x64机器上使用x86库