Kermit_ 2017-11-16 09:42 采纳率: 0%
浏览 1996

c++函数头文件,测试未定义

funk.h

#ifndef FUNK_H
#define FUNK_H

double gz(double z_1); // Function 1
double sz(double z_2); // Function 2
double zt(double s_1); // Function 3
double egz(double s_2); // Function 4
double urs(double g_1); // Function 5
double urh(double g_2); // Function 6

#endif

funk.cpp

#include
#include "funk.h"
double a;

double gz(double z_1) // F1
{
double v;
v = z_1 * a;
return v;
}

double sz(double z_2) // F2
{
double s;
s = a * pow(z_2, 2) / 2;
return s;
}

double zt(double s_1) // F3
{
double t;
t = sqrt(2*s_1/a);
return t;
}

double egz(double s_2) // F4
{
double t;
double g;
t = sqrt(2*s_2/a);
g = a * t;
return g;
}

double urs(double g_1) // F5
{
double ug;
ug = g_1 / 3.6;
return ug;
}

double urh(double g_2) // F6
{
double ug;
ug = g_2 * 3.6;
return ug;
}

编译后显示:Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

test1.cpp

#include
#include "funk.h"
using namespace std;

int main()
{

double Z_1; // F1
cin>>Z_1;
cout<<"v = "<<gz(Z_1)<<" m/s"<<endl;

double z_2; // F2
cin>>z_2;
cout<<"s = "<<sz(z_2)<<" m"<<endl;

double s_1; // F3
cin>>s_1;
cout<<"Benötigte Zeit = "<<zt(s_1)<<" s"<<endl;

double s_2; // F4
cin>>s_2;
cout<<"Erreichte Geschwindigkeit = "<<egz(s_2)<<" m/s"<<endl;

double g_1; // F5
cin>>g_1;
cout<<g_1<<" m/s = "<<urs(g_1)<<" km/h"<<endl;

double g_2; // F5
cin>>g_2;
cout<<g_2<<" km/h = "<<urh(g_2)<<" m/s"<<endl;  

return 0;

}

编译test1.cpp,报错:Undefined symbols for architecture x86_64:
"gz(double)", referenced from:
_main in test1-15ae57.o
"sz(double)", referenced from:
_main in test1-15ae57.o
"zt(double)", referenced from:
_main in test1-15ae57.o
"egz(double)", referenced from:
_main in test1-15ae57.o
"urh(double)", referenced from:
_main in test1-15ae57.o
"urs(double)", referenced from:
_main in test1-15ae57.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

  • 写回答

2条回答 默认 最新

  • xhl1376139719 2017-11-16 09:57
    关注

    最好把错误贴出来,不清楚你说的是那些函数,你可以尝试看一下,需要的文件有没有编译,然后如果这两个文件都编译了,还会出错,因为有两个main函数,你最好区别一下

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog