纯小白 尝试用vs code debug c/c++程序
2024-02-29
vs code太高级了,搞了半天也没明白它的工作原因。现在hello world的门槛都这么高了吗?
我使用的vs code版本:version 1.87.0
第一步:
新建一个目录hello作为工程目录。File -> Open Folder... 打开hello目录。
在新工程根目录下新建文件main.c File -> New File...
1 2 3 4 5 6 | #include <stdio.h> int main(){ printf ( "sdf" ); return 3; } |
如果只是想看运行结果,直接在main.c文件中右击选中Run Code就可以看到运行结果
如果想debug打断点,继续往下看。
然后直接点运行.
我这里的报错是:
这时候系统已经帮我们生成
c_cpp_properties.json
launch.json
settings.json
3个配置文件了。直接点开Open 'launch.json'文件。
Terminal -> Configure Default Build Task 生成默认的tasks.json文件。
运行task任务
报错: Cannot build and debug because the active file is not a C or C++ source file.
未发现c源文件。
我就修改了两处${file}换成了main.c options下的cwd换成了当前工程目录,然后点保存(很重要),再次运行任务task成功了。
记住这个生成可执行文件的路径是:d:/c/hello/build/Debug/outDebug
然后回到launch.json文件
把里面的
"program": "d:/c/hello/build/Debug/outDebug",
改成
---------------------------------------------------------------------------------------------------
中间出现一个小插曲:
明面上是说MiDebuggerPath的参数不对。看默认是
链接:https://pan.baidu.com/s/10BdhTWWS0VO2LDf9_llQrg
提取码:qkpw
因为胳膊拧不过大腿,vs code里面的launch.json中的program总是被系统自动改成build/Debug/outDebug这个目录了,
为什么了统了,我们也修改一下tasks.json里面的生成路径吧
有时候,为了编译和运行一步搞定,可以把launch.json中指定任务
2024-07-02
Starting build...
cmd /c chcp 65001>nul && D:/soft/MinGW/bin/gcc.exe -fdiagnostics-color=always -g -I D:\c\ffmpeg_win\include D:\c\ffmpeg_win/*.c -LD:\c\ffmpeg_win\dll -lavutil-59 -lswscale-8 -lavcodec-61 -lavdevice-61 -lavfilter-10 -lavformat-61 -lpostproc-58 -lswresample-5 -o D:\c\ffmpeg_win\main.exe
C:\Users\���\AppData\Local\Temp\cc8qKxs3.o: In function `main_C':
D:/c/ffmpeg_win/main.c:8: undefined reference to `main_ffprobe'
D:/soft/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
Build finished with error(s).
原来这个错误是编译软件找不到main方法,加一个main方法就好。
--------------------------------------------------------------------------------------------------------------------------------------
如果重复引用同一个文件,会报错: multiple definition of `main'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". During startup program exited with code 0xc0000135.
这个报错,是因为我在编译task的时候, 有把dll动态库文件放到dll目录下,但是在执行exe的时候,exe只让当前目录下的dll才有效。解决办法。
在launch.json中加environment字段,里面填path地址
posted on 2024-02-29 11:47 angelshelter 阅读(1464) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
2020-02-29 切WKWebView