一个项目调用另一个项目中的函数

本文介绍如何在C++项目中创建并使用静态库,包括配置静态库项目、实现基本函数、设置依赖项及包含目录等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考:

	http://blog.youkuaiyun.com/lins1393997412/article/details/7454817
	http://blog.youkuaiyun.com/a5161027/article/details/51409845
	http://blog.youkuaiyun.com/zhouguoqionghai/article/details/46467263
	https://msdn.microsoft.com/zh-cn/library/et61xzb3(v=vs.90).aspx
	
test.h
int fun(int a, int b);
test.cpp
#include "stdafx.h"
#include <iostream>
#include "test.h"

using namespace std;

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

test2.cpp
#include "stdafx.h"
#include <iostream>
#include "../test/test.h"

using namespace std;

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

test.cpp的配置类型改为静态库(view-property page-configuration-general-project defaults-configuration type-static library)

然后将test2的项目依赖项设置为test,在test2的附加包含目录中找到test1.h所在的文件夹,调试即可(项目依赖项设置:右键项目-properties-common properties-add new reference)(附加包含目录:右键项目-properties-configuration properties-c/c++-Additional include directories)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值