一个解决方案中有两个项目,一个项目调用另一个项目中的函数

两个项目分别是test1和test2,test1中有一个函数fun()被test2调用,用法如下:

//test1.h
int fun(int a, int b);

//test1.cpp
#include <iostream>
#include "test1.h"

using namespace std;

int fun(int a, int b)
{
  return a + b;
}

然后将test1的配置类型改为 静态库(.lib)。

//test2.cpp
#include <iostream>
#include "test1.h"

using namespace std;

void main()
{
  cout << fun(2, 3);
}

然后将test2的项目依赖项设置为test1,在test2的附加包含目录中找到test1.h所在的文件夹,调试即可。

//另注:生成 .lib文件的工程中可以没有main()函数。

//另注:工程test1之所以生成的是 .lib文件而不是 .dll文件,是因为test1与test2在同一个解决方案中,没有涉及外部接口。

猜你喜欢

转载自blog.csdn.net/lins1393997412/article/details/7454817