c++调用其他源文件函数 Error Link2019
在c++中,主函数调用另一个cpp文件中的funcm函数,一种方法为,在自建头文件中声明该函数,并且在描述funcm函数实体的cpp文件中引用头文件。具体示例如下:
//主函数源文件SummerSchool.cpp
#include "stdafx.h"
#include<iostream>
#include"Account.h"
#include<Windows.h>
int main()
{
double aa=4.5;
double d=funcm(aa);//调用其他cpp文件中的funcm函数
std::cout<<d;
Sleep(10000);
}
//头文件Account.cpp,声明调用函数
#ifndef CIRCLE_H
#define CIRCLE_H
#include<iostream>
double funcm(double a);
#endif
//源文件funcm.cpp,调用函数实体
#include"Account.h"
#include"stdafx.h"
#include<cmath>
double funcm(double a)
{
double c=cos(a);
return c;
}
在Visual studio2012中,运行以上程序一直出现错误Error Link2019:无法解析的外部符号。提示找不到函数funcm实体。解决办法为在项目中添加函数实体所在的源文件funcm.cpp(右击源文件-添加-现有项)。