vscode中引用自定义头文件的显示undefined reference to 错误
头文件中只包括函数的声明,函数定义在cpp文件中,在main文件中调用头文件,三者在同一目录下
处理方式:参考了几篇网友博客,已在tasks.json.添加了头文件和cpp文件对应绝对路径,或者添加二者任意一个,或者在c_cpp_properties.json中添加头文件路径,这三种组合方式都试过,还是无法解决问题,相应的具体代码如下图
//main.cpp文件
#include "swap.h"
int main()
{
int a = 100;
int b = 200;
swap(a, b);
system("pause");
return 0;
}
//swap.cpp文件
#include "swap.h"
void swap(int a, int b)
{
int temp = a;
a = b;
b = temp;
cout << "a = " << a << endl;
cout << "b = " << b << endl;
}
//swap.h文件
#include<iostream>
using namespace std;
//实现两个数字交换的函数声明
void swap(int a, int b);