解决方法 项目目录 文件内容 头文件使用vscode编写C代码,导入自定义.c文件中的函数时,报错:
undefined reference to `a_val‘collect2.exe: error: ld returned 1 exit status
// Test1.h # pragma once void fun1();
// Test2.h # pragma once void fun2();源文件
// test1.c #include#include #include "../header/Test1.h" void fun1() { printf("%dn",2); }
// test2.c #include#include #include "../header/Test2.h" void fun2() { printf("%dn",2); }
// main.c #include修改配置 1)文件->首选项->设置 2)输入code runner,找到Executor Map,打开json配置文件 3)找到c将其中的$fileName改为*.c#include #include "../header/Test1.h" #include "../header/Test2.h" int main() { fun1(); fun2(); return 0; }
PS:如果有需要,c++对应的cpp也可以一起更改
如果喜欢的话,关注我吧,公众号:编码魔坊



