Visual Studio Code clang错误:Mac上的链接器命令失败,退出代码为1 [英] Visual Studio Code clang error: linker command failed with exit code 1 on Mac

查看:170
本文介绍了Visual Studio Code clang错误:Mac上的链接器命令失败,退出代码为1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手,想尝试VS Code进行C ++开发.我遇到此错误,无法在线找到解决方法:

I'm new to programming and wanted to try out VS Code for C++ development. I'm getting this error and I can't find a solution online how to fix:

clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)终端进程终止于退出代码:1

clang: error: linker command failed with exit code 1 (use -v to see invocation) The terminal process terminated with exit code: 1

我得到了一个包含函数定义的cpp文件和一个包含类和声明的头文件,还有一个int主测试文件.

I got a cpp file with the function definitions and a header file with the class and declarations in it and also a int main test file.

所以这是一个链接器问题.VSC将我定向到c_cpp_properties.json,我不知道下一步该怎么解决.我也在Mac上.

So its a linker issue. VSC directed me to c_cpp_properties.json and I have no idea what to do next to fix it. I'm also on Mac btw.

有人可以帮我吗?

推荐答案

我想我找到了答案!

好像我一直在找错误的地方.您假设要编辑task.json选项,在其中要求命令",然后添加您正在使用的每个翻译单元或cpp文件名.就像我的

Seems like I was looking in the wrong place the whole time. You're suppose to edit the task.json option where it asks for "command" then add every single translational unit or cpp file name you're using. Like mine would be

"g ++ -g main.cpp func.cpp -o main"

"g++ -g main.cpp func.cpp -o main"

这告诉编译器同时编译main.cpp和func.cpp文件,然后允许链接程序执行其工作.

This tells the compiler to compile both the main.cpp and func.cpp file and then allows the linker to do its job.

这篇关于Visual Studio Code clang错误:Mac上的链接器命令失败,退出代码为1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆