当前位置:网站首页>Server body 21: pre compilation processing by different compilers (a brief introduction to MSVC and GCC)
Server body 21: pre compilation processing by different compilers (a brief introduction to MSVC and GCC)
2022-07-28 19:10:00 【Xie Baiyu】
List of articles
One 、 background
- Most compilers support precompiling
In most of c/c++ Compilers support precompiled headers , for example :gcc,clang,msvc etc. - Precompile function
Used to optimize c++ Speed of code compilation , After all c++ If the header file contains the template definition , Compilation speed is very slow - Precompiled approach
Most general header files can be placed in one header.h in , Compile other source code before compiling it , Later code can reuse this part of the precompiled header , It can greatly reduce the frequent redundant compilation of header files .
Two 、msvc Precompiled header processing for
Precompiled header in msvc Is very common in projects , I often see something like stdafx.cpp, stdafx.h The file of , For this purpose , and msvc The compiler compiles stdafx.cpp To generate precompiled header files stdafx.pch Of .
1) summary
Generally, under the same project stdafx.cpp Is to create a precompiled header (/Yc), other .cpp Files are using precompiled headers (/Yu), all .h The file doesn't care about this
2) Specific use
Overall process Preview
1) Create precompiled header command
2) Other files use this stdafx.pch Methods
3) link obj Attention
4) Differences with other compilersCreate precompiled header command
$ cl.exe -c -Yc -Fpstdafx.pch -Fostdafx.obj stdafx.cpp
1)-Yc Is to create a precompiled header stdafx.pch
2)-Fp To specify the *.pch Output file path of
3)-Fo Specify compile stdafx.cpp Generate object file
- How to use this for other files stdafx.pch?
By way of stdafx.h Pass in -Yu To tell the compiler , Compile the current code , Ignore #include “stdafx.h”, Directly use the compiled stdafx.pch file .
cl.exe -c -Yustdafx.h -Fpstdafx.pch -Fotest.obj test.cpp
- At the end of the link
Need to put :stdafx.obj, test.obj All connected , This is also related to gcc, clang The compiler is different .
link.exe -out:test test.obj stdafx.obj
- Other considerations
1) notes : Be sure stdafx.obj Also on the link , although stdafx.cpp Only for generating stdafx.pch, But object files are also required .
2) There's another one with gcc, clang The difference is ,msvc Of -Yu Appoint stdafx.h Must be #include "stdafx.h" Header file name in , Not a file path .
3、 ... and 、gcc Precompiled header file processing for
1)gcc Search for stdafx.pch Rules for file paths
1) from stdafx.h In the directory , lookup stdafx.h.pch Does the file exist
2) from -I The header file search path of find find find stdafx.h.pch
2) compile
- Overall process
1) Compile header file generation pch file :
2) Using precompiled header files :
- Compile header file generation pch file :
gcc -c -o stdafx.pch stdafx.h
- Using precompiled header files :
gcc -c -include stdafx.h -o test.o test.cpp
Four 、 remarks (C and C++ about *.h The difference between compilation )
1)gcc、clang about *.h Header file compilation , The default is as c Used by precompiled headers , This one c++ Of pch It's different .
2)*.h The header file compilation of cannot be given c++ The code uses , If you want to generate c++ Usable pch file , You have to tell the compiler , How to compile stdafx.h
- Method
This can be done through -x c+±header Parameters to solve :
gcc -c -x c++-header -o stdafx.pch stdafx.h
- Of course, it can also be solved by modifying the suffix :
gcc -c -o stdafx.pch stdafx.hpp
边栏推荐
- Mongodb database replication table
- 4 年后,Debian 终夺回“debian.community”域名!
- Is zero basic software testing training reliable?
- The switching language of unity causes an error: system FormatException:String was not recognized as a valid DateTime.
- Kali doesn't have an eth0 network card? What if you don't connect to the Internet
- 6-20漏洞利用-proftpd测试
- 2022年牛客多校第2场 J . Link with Arithmetic Progression (三分+枚举)
- Leetcode skimming - super power 372 medium
- Configuration tutorial: how does the organizational structure of the new version of easycvr (v2.5.0) cascade to the superior platform?
- 11 年膨胀 575 倍,微信为何从“小而美”变成了“大而肥”?
猜你喜欢

【物理应用】大气吸收损耗附matlab代码

Example of observer mode of C -- ordering milk

How to use the white list function of the video fusion cloud service easycvr platform?

N32替换STM32,这些细节别忽略!

Applet applet jump to official account page

Zero knowledge proof: zkp with DDH assumption

When the new version of easycvr is linked at the same level, the subordinate platform passes up the cause analysis of the incomplete display of the hierarchical directory

行业落地呈现新进展 | 2022开放原子全球开源峰会OpenAtom OpenHarmony分论坛圆满召开

Why did wechat change from "small and beautiful" to "big and fat" when it expanded 575 times in 11 years?

Xiaobai must see the development route of software testing
随机推荐
From Bayesian filter to Kalman filter (zero)
Regular expressions related to face-to-face orders of major express companies in JS
Is zero basic software testing training reliable?
4、 Interface requests data to update input information interactively
Swiftui swift forward geocoding and reverse geocoding (tutorial with source code)
2022 Hangdian multi school field 2 1011 DOS card (line segment tree)
EasyCVR设备离线后无法再次上线该如何解决?
Overview and working principle of single chip microcomputer crystal oscillator
Is the software testing industry really saturated?
N32 replaces STM32. Don't ignore these details!
2022年最火的十大测试工具,你掌握了几个
What if the content of software testing is too simple?
Redis cache avalanche, penetration, breakdown, bloom filter, detailed explanation of distributed lock
[actual combat] realize page distortion correction with OpenCV
Full analysis of warehouse building on the lake: how to build a lake warehouse integrated data platform | deepnova technology collection series open class phase IV
Introduction and advanced MySQL (III)
The ever-changing pointer ----- C language
DevCon.exe 导出output至指定文件
kotlin:Nothing
Efficiency comparison of JS array splicing push() concat() methods