函数份文件编写,多个cpp文件没有同时编译

Undefined symbols for architecture x86_64:
  "swap_test(int, int)", referenced from:
      _main in main-323346.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

其实原因是vscode默认设置是值编译了当前文件,而未编译其他引用文件,所以swap_test函数未编译。

解决方案

1. 编辑runcode的配置文件

打开Code>>首选项>>配置,搜索run code,找到Code-runner Executor Map,如下图
在这里插入图片描述

2. 编辑runcode配置文件

点击在settings.json中编辑,得到以下默认配置
在这里插入图片描述
这里$fileName只是当前文件进行了编译
所以我们只需要编译所有文件即可。
在这里插入图片描述

保存运行,即可

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐