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函数,你最好区别一下

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮