当前位置:网站首页>[转载] Virtual Studio 让系统找到需要的头文件和库
[转载] Virtual Studio 让系统找到需要的头文件和库
2022-07-31 07:52:00 【氵文大师】
接着我上一篇,VS2019 安装之后还有一些破事,添加 cl.exe 的路径:
https://blog.csdn.net/HaoZiHuang/article/details/125795675
本文大部分转载自:
https://www.daimajiaoliu.com/daima/56a4dc5a9eb1806/windows
尽管 cl.exe
可以再环境变量中找到,然而现在写个cpp程序,依旧无法编译成功
发现连iostream都找不到,这提醒我们编译器还没有找到对应的头文件和库。如果不想每次手动链接,请继续阅读。
#include <iostream>
using namespace std;
int main(){
cout<<"hello, CSDN"<<endl;
return 0;
}
cl hello.cpp /EHsc & hello.exe
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.29.30145 版
版权所有(C) Microsoft Corporation。保留所有权利。
hello.cpp
hello.cpp(1): fatal error C1034: iostream: 不包括路径集
'hello.exe' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
这里新建一个环境变量LIB
:
然后把lib路径添加进去:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\lib\x64
再新建一个 INCLUDE
:
然后把 include 路径添加进去:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include
做完这一切后,请点击确定,让系统配置生效。这时编译器可以找到iostream等基本的头文件,但因为缺少一些库还是不能运行。
再次编译:
cl hello.cpp /EHsc & hello.exe
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.29.30145 版
版权所有(C) Microsoft Corporation。保留所有权利。
hello.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\yvals.h(12): fatal error C1083: 无法打开包 括文件: “crtdbg.h”: No such file or directory
'hello.exe' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
对于我这个版本的VS,经过查阅资料,库和头文件并不全位于上述路径,其他的文件位于与Microsoft Visual Studio同目录的Windows Kits下。
为了验证该结论,我们可以在其中查找上面缺少的crtdbg.h
文件,发现位于Windows Kits/10/Include路径下。
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt
将这第一个路径也扔到刚刚的环境变量 INCLUDE
中,用分号分开
新开一个终端,再次编译:
cl hello.cpp /EHsc & hello.exe
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.29.30145 版
版权所有(C) Microsoft Corporation。保留所有权利。
hello.cpp
Microsoft (R) Incremental Linker Version 14.29.30145.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:hello.exe
hello.obj
LINK : fatal error LNK1104: 无法打开文件“kernel32.lib”
'hello.exe' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
是的要把lib文件目录添加到 LIB
的环境变量中
是的现在只需要搜索一下 kernel32.lib
文件在哪
尴尬的是,有这么多
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\arm64
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\arm
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x86
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x64
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\arm
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\arm64
我猜这是VS为做跨平台编译而整的?
我看了一眼,前四修改日期是2020年,而后4个修改日期是2015年
可能分别对应我的VS2019和VS2015吧?
我的电脑是64位,所以就把:
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64
添加到LIB
路径中吧
再次编译:
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.29.30145 版
版权所有(C) Microsoft Corporation。保留所有权利。
hello.cpp
Microsoft (R) Incremental Linker Version 14.29.30145.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:hello.exe
hello.obj
LINK : fatal error LNK1104: 无法打开文件“libucrt.lib”
'hello.exe' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
。。。。。。还有完没完啊。。。。。。
搜索libucrt.lib
的路径:
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x64
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x86
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\arm
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\arm64
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x86
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\arm
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\arm64
也是分成前4个后4个两组,依旧将
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x64
添加到LIB
环境变量中
再次编译:
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.29.30145 版
版权所有(C) Microsoft Corporation。保留所有权利。
hello.cpp
Microsoft (R) Incremental Linker Version 14.29.30145.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:hello.exe
hello.obj
hello, CSDN
终于OK了
最终确认一下:
这些include目录其实可以都添加到 环境变量 INCLUDE
中,这是我编译 Ninja 遇到的坑
边栏推荐
- Unreal基础概念
- [MySQL exercises] Chapter 5 · SQL single table query
- 48页智慧城市规划蓝图 解决方案
- 一文搞定代码中的命名
- XSS靶场prompt.ml过关详解
- "C language" frog jumping steps recursion problem
- 一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
- How on one machine (Windows) to install two MYSQL database
- Pygame Surface对象
- [Cloud native] Introduction and use of Feign of microservices
猜你喜欢
使用PageHelper实现分页查询(详细)
Machine Learning - Notes and Implementation of Linear Regression, Logistic Regression Problems
[MySQL exercises] Chapter 2 Basic operations of databases and data tables
【黄啊码】MySQL入门—3、我用select ,老板直接赶我坐火车回家去,买的还是站票
【小程序项目开发--京东商城】uni-app之自定义搜索组件(上)-- 组件UI
云服务器部署 Web 项目
如何使用mysql binlog 恢复数据
一文搞定代码中的命名
[Interview: Concurrency 38: Multithreading: Thread Pool] Basic concepts of the ThreadPoolExecutor class
【MySQL功法】第3话 · MySQL中常见的数据类型
随机推荐
R语言 第一部分
实用生物信息学2:多组学数据整合和挖掘
使用PageHelper实现分页查询(详细)
【MySQL功法】第2话 · 数据库与数据表的基本操作
个人报错问题 持续总结
【面试题】从输入URL到游览器渲染完成,经历了什么
ros little turtle drawing
深度学习随机数设置,保证实验的可重复性
MySQL安装教程
关于Error EPERM operation not permitted, mkdir...几种解决办法的比较
SQL 嵌套 N 层太长太难写怎么办?
Vue项目通过node连接MySQL数据库并实现增删改查操作
7/28-7/29 Expectation + thinking + suffix array + ST table
【MySQL中auto_increment有什么作用?】
SQL语句知识大全
MySQL中InnoDB的多版本并发控制(MVCC)的实现
正则表达式绕过
XSS详解
力扣 593. 有效的正方形
linux redis6.2.6配置文件