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)