当前位置:网站首页>[转载] 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 遇到的坑
边栏推荐
- How on one machine (Windows) to install two MYSQL database
- 【idea 报错】 无效的目标发行版:17 的解决参考
- [Interview: Concurrency 37: Multithreading: Thread Pool] Custom Thread Pool
- MySql数据库优化查询工具
- XSS详解
- MySQL table creation statement_Three commonly used MySQL table creation statements
- SSM框架简单介绍
- 正则表达式绕过
- 一、MySQL主从复制原理
- UML图及在drawio中的绘制
猜你喜欢
Vscode: Project-tree plugin
《如何戒掉坏习惯》读书笔记
奉劝那些刚参加工作的学弟学妹们:要想进大厂,这些核心技能是你必须要掌握的!完整学习路线!
The first part of the R language
Locust 1.0版本引入的变化
[MySQL exercises] Chapter 2 Basic operations of databases and data tables
开源|商品识别推荐系统
MySQL 5.7 安装教程(全步骤、保姆级教程)
Install the deployment kubernetes KubeSphere management
PowerCLi 通过自建PXE Server一键esxi7下批量部署常规New-VM
随机推荐
A, MySQL principle of master-slave replication
深度理解递归,手撕经典递归问题(汉诺塔,青蛙跳台阶),保姆级教学。
普通函数的参数校验
【云原生&微服务五】Ribbon负载均衡策略之随机ThreadLocalRandom
The first part of the R language
PowerCLi 一键批量部署OVA 到esxi 7
[Yellow ah code] Introduction to MySQL - 3. I use select, the boss directly drives me to take the train home, and I still buy a station ticket
MySql 5.7.38下载安装教程 ,并实现在Navicat操作MySql
[MySQL exercises] Chapter 3 Common data types in MySQL
模块化规范
CNN--Introduction to each layer
Collation and sharing of related classic papers and datasets in the field of deep learning communication
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
Client navicat installation tutorial
MySQL安装常见报错处理大全
mysql插入新字段方法
免安装版的Mysql安装与配置——详细教程
关于@Autowired
XSS详解
MySQL中InnoDB的多版本并发控制(MVCC)的实现