C-01\编译器和链接器以及真正的入口函数
编译器:
| 工具 | 编译器 | 路径 |
|---|---|---|
VC++6.0 |
CL.EXE(一段shell)只负责分析命令行参数,真正功能实现在C1.DLL、C1XX.DLL、C2.DLL |
C:\Program Files (x86)\Microsoft Visual Studio\VC98\Bin |
VS2019 |
CL.EXE(一段shell),真正功能实现在C1.DLL、C1XX.DLL、C2.DLL |
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\Hostx64\x64 |
链接器:
| 工具 | 链接器 | 路径 |
|---|---|---|
VC++6.0 |
LINK.EXE |
C:\Program Files (x86)\Microsoft Visual Studio\VC98\Bin |
VS2019 |
LINK.EXE |
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\Hostx64\x64 |
VC++6.0 : 6.0说的是链接器的版本,不是编译器的版本
注意:vs2019正版会在线更新编译器
在所在目录右键快速打开cmd设置方法(WIN 10):
1.右键:命令行
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCmdHere]
@="在此处打开命令行窗口"
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCmdHere\command]
@="cmd.exe -noexit -command Set-Location -literalPath \"%V\""
2.右键:命令行(管理员)
[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
@="在此处打开命令行窗口(管理员)"
"ShowBasedOnVelocityId"=dword:00639bc8
[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
@="cmd.exe /s /k pushd \"%V\""
编译器常用参数:
/c 只编译不链接 生成 .obj文件(.obj标准为coff标准,可以跨语言平台,其余语言也可以使用)
/W 警告等级,分1~4级,4级最高,默认为1级(/W1~/W4),/W3 不会报变量闲置警告,/W4会报变量闲置警告
/WX 将警告视为错误,一旦有了警告,动作停止,不产生.obj文件,迫使操作员对警告进行处理
/P 生成预处理信息文件 .i(带#的语句都是预处理语句) 可以查看复杂宏的正确性
编译和链接的指令:
编译指令:
cl /c filePath //filePath为要编译的文件路径
链接指令:
link filePath //filePath为要链接的文件路径
#include <> 与#include ""区别:
#include <> // 先根据每个 /I 编译器选项指定的路径查找,然后再根据环境变量 include 命令设置的路径去找
// 然后copy整个文件替换该语句
#include "" // 如果文件名给定的是全路径,则只搜索该路径
// 如果是相对路径,则先在源文件所在的目录查找,然后根据每个 /I 编译器选项指定的路径查找,最后再根据环境变量 include 命令设置的路径去找
// 然后copy整个文件替换该语句
include 不检查扩展名
入口函数所在文件路径:
C:\Program Files (x86)\Microsoft Visual Studio\VC98\CRT\SRC\CRT0.C //VC++6.0

/***
*BaseProcessStartup(PVOID Peb)
*
*Purpose:
* This routine does the C runtime initialization, calls main(), and
* then exits. It never returns.
*
*Entry:
* PVOID Peb - pointer to Win32 Process Environment Block (not used)
* //
*Exit:
* This function never returns. // 该函数没有返回值
*
*******************************************************************************/
// 通过宏 _WINMAIN_ 区分窗口和控制台 存在宏 _WINMAIN_ 就是窗口程序
// 通过宏 WPRFLAG 区分宽字节和多字节 存在宏 WPRFLAG 就是宽字节
// 通过宏 _MT 区分多线程还是单线程
// 窗口宽字节
void wWinMainCRTStartup(void)
{
int mainret; // 主函数返回值
_TUCHAR *lpszCommandLine;
STARTUPINFO StartupInfo;
/*
* Get the full Win32 version
*/
_osver = GetVersion(); // 获取系统版本
// 分离系统版本号
_winminor = (_osver >> 8) & 0x00FF ;
_winmajor = _osver & 0x00FF ;
_winver = (_winmajor << 8) + _winminor;
_osver = (_osver >> 16) & 0x00FFFF ;
#ifdef _MT
if ( !_heap_init(1) ) /* initialize heap */ // 多线程情况下初始化堆
#else /* _MT */
if ( !_heap_init(0) ) /* initialize heap */ // 单线程情况下初始化堆
#endif /* _MT */
fast_error_exit(_RT_HEAPINIT); /* write message and die */
#ifdef _MT
if( !_mtinit() ) /* initialize multi-thread */ // 多线程情况下初始化多线程环境
fast_error_exit(_RT_THREAD); /* write message and die */
#endif /* _MT */
/*
* Guard the remainder of the initialization code and the call
* to user's main, or WinMain, function in a __try/__except
* statement.
*/
__try {
_ioinit(); /* initialize lowio */ // 初始化io
/* get wide cmd line info */
_wcmdln = (wchar_t *)__crtGetCommandLineW(); // 获取命令行信息
/* get wide environ info */
_wenvptr = (wchar_t *)__crtGetEnvironmentStringsW(); // 获取环境变量信息
_wsetargv(); // 格式化命令行信息
_wsetenvp(); // 格式化环境变量信息
// 全局数据初始化和静态数据初始化以及C++全局对象的构造函数的调用
_cinit(); /* do C data initialize */
StartupInfo.dwFlags = 0;
GetStartupInfo( &StartupInfo ); // 获取当前进程的基本环境
lpszCommandLine = _wwincmdln(); // 获取命令行参数
mainret = wWinMain(
GetModuleHandleA(NULL),
NULL,
lpszCommandLine,
StartupInfo.dwFlags & STARTF_USESHOWWINDOW
? StartupInfo.wShowWindow
: SW_SHOWDEFAULT
);
exit(mainret); // 退出进程,里面调用 ExitProcess(mainret),同时处理全局对象的释放工作
}
__except ( _XcptFilter(GetExceptionCode(), GetExceptionInformation()) )
{
/*
* Should never reach here
*/
_exit( GetExceptionCode() );
} /* end of try - except */
}
// 窗口多字节
void WinMainCRTStartup(void)
{
int mainret;
_TUCHAR *lpszCommandLine;
STARTUPINFO StartupInfo;
/*
* Get the full Win32 version
*/
_osver = GetVersion();
_winminor = (_osver >> 8) & 0x00FF ;
_winmajor = _osver & 0x00FF ;
_winver = (_winmajor << 8) + _winminor;
_osver = (_osver >> 16) & 0x00FFFF ;
#ifdef _MT
if ( !_heap_init(1) ) /* initialize heap */
#else /* _MT */
if ( !_heap_init(0) ) /* initialize heap */
#endif /* _MT */
fast_error_exit(_RT_HEAPINIT); /* write message and die */
#ifdef _MT
if( !_mtinit() ) /* initialize multi-thread */
fast_error_exit(_RT_THREAD); /* write message and die */
#endif /* _MT */
/*
* Guard the remainder of the initialization code and the call
* to user's main, or WinMain, function in a __try/__except
* statement.
*/
__try {
_ioinit(); /* initialize lowio */
/* get cmd line info */
_acmdln = (char *)GetCommandLineA();
/* get environ info */
_aenvptr = (char *)__crtGetEnvironmentStringsA();
_setargv();
_setenvp();
_cinit(); /* do C data initialize */
StartupInfo.dwFlags = 0;
GetStartupInfo( &StartupInfo );
lpszCommandLine = _wincmdln();
mainret = WinMain(
GetModuleHandleA(NULL),
NULL,
lpszCommandLine,
StartupInfo.dwFlags & STARTF_USESHOWWINDOW
? StartupInfo.wShowWindow
: SW_SHOWDEFAULT
);
exit(mainret);
}
__except ( _XcptFilter(GetExceptionCode(), GetExceptionInformation()) )
{
/*
* Should never reach here
*/
_exit( GetExceptionCode() );
} /* end of try - except */
}
// 控制台宽字节
void wmainCRTStartup(void)
{
int mainret;
/*
* Get the full Win32 version
*/
_osver = GetVersion();
_winminor = (_osver >> 8) & 0x00FF ;
_winmajor = _osver & 0x00FF ;
_winver = (_winmajor << 8) + _winminor;
_osver = (_osver >> 16) & 0x00FFFF ;
#ifdef _MT
if ( !_heap_init(1) ) /* initialize heap */
#else /* _MT */
if ( !_heap_init(0) ) /* initialize heap */
#endif /* _MT */
fast_error_exit(_RT_HEAPINIT); /* write message and die */
#ifdef _MT
if( !_mtinit() ) /* initialize multi-thread */
fast_error_exit(_RT_THREAD); /* write message and die */
#endif /* _MT */
/*
* Guard the remainder of the initialization code and the call
* to user's main, or WinMain, function in a __try/__except
* statement.
*/
__try {
_ioinit(); /* initialize lowio */
/* get wide cmd line info */
_wcmdln = (wchar_t *)__crtGetCommandLineW();
/* get wide environ info */
_wenvptr = (wchar_t *)__crtGetEnvironmentStringsW();
_wsetargv();
_wsetenvp();
_cinit(); /* do C data initialize */
__winitenv = _wenviron;
mainret = wmain(__argc, __wargv, _wenviron);
exit(mainret);
}
__except ( _XcptFilter(GetExceptionCode(), GetExceptionInformation()) )
{
/*
* Should never reach here
*/
_exit( GetExceptionCode() );
} /* end of try - except */
}
// 控制台多字节
void mainCRTStartup(void);
{
int mainret;
/*
* Get the full Win32 version
*/
_osver = GetVersion();
_winminor = (_osver >> 8) & 0x00FF ;
_winmajor = _osver & 0x00FF ;
_winver = (_winmajor << 8) + _winminor;
_osver = (_osver >> 16) & 0x00FFFF ;
#ifdef _MT
if ( !_heap_init(1) ) /* initialize heap */
#else /* _MT */
if ( !_heap_init(0) ) /* initialize heap */
#endif /* _MT */
fast_error_exit(_RT_HEAPINIT); /* write message and die */
#ifdef _MT
if( !_mtinit() ) /* initialize multi-thread */
fast_error_exit(_RT_THREAD); /* write message and die */
#endif /* _MT */
/*
* Guard the remainder of the initialization code and the call
* to user's main, or WinMain, function in a __try/__except
* statement.
*/
__try {
_ioinit(); /* initialize lowio */
/* get cmd line info */
_acmdln = (char *)GetCommandLineA();
/* get environ info */
_aenvptr = (char *)__crtGetEnvironmentStringsA();
_setargv();
_setenvp();
_cinit(); /* do C data initialize */
__initenv = _environ;
mainret = main(__argc, __argv, _environ);
exit(mainret);
}
__except ( _XcptFilter(GetExceptionCode(), GetExceptionInformation()) )
{
/*
* Should never reach here
*/
_exit( GetExceptionCode() );
} /* end of try - except */
}
补充知识
vs中8字节的是__int64,long int还是4字节,可能为了用户黏性,故意为之,与c标准不一致- 常量后面加
L,表示长整型常量,占8字节 - 3.14是双精度浮点数,加
f才是单精度浮点数 stdin, stdout支持重定向stderr不支持重定向
C-01\编译器和链接器以及真正的入口函数的更多相关文章
- 你好,C++(4)2.1.3 我的父亲母亲:编译器和链接器 2.1.4 C++程序执行背后的故事
2.1.3 我的父亲母亲:编译器和链接器 从表面上看,我是由Visual Studio创建的,而实际上,真正负责编译源代码创建生成可执行程序HelloWorld.exe的却是Visual Studi ...
- C编译器、链接器、加载器详解
摘自http://blog.csdn.net/zzxian/article/details/16820035 C编译器.链接器.加载器详解 一.概述 C语言的编译链接过程要把我们编写的一个c程序(源代 ...
- C++之编译器与链接器工作原理
原文来自:http://blog.sina.com.cn/s/blog_5f8817250100i3oz.html 这里并没不是讨论大学课程中所学的<编译原理>,只是写一些我自己对C++编 ...
- C++编译器与链接器工作原理
http://blog.csdn.net/success041000/article/details/6714195 1. 几个概念 1)编译:把源文件中的源代码翻译成机器语言,保存到目标文件中.如果 ...
- 浅谈C++编译原理 ------ C++编译器与链接器工作原理
原文:https://blog.csdn.net/zyh821351004/article/details/46425823 第一篇: 首先是预编译,这一步可以粗略的认为只做了一件事情,那就 ...
- C++编译器、链接器工作原理
1 几个基本概念 编译:编译器对源文件的编译过程,就是将源文件中的文本形式代码翻译为机器语言形式的目标文件的过程,此过程中会有一系列语法检查.指令优化等,生成目标(OBJ)文件. 编译单元:每一个CP ...
- C入门语言基础一[可移植性、涉及的三种文件、编程7个步骤、编译器、链接器]
Review Questions What dose portability mean in the context of programming? 文中讲到的可移植性是什么意思? C本身是不涉及 ...
- Visual Stdio C++ 编译器、链接器常用命令
概览: cmd常用命令配合使用: del 删除指定文件 同erase cls 清屏 rd 删除空目录文件夹 dir 显示目录 cd 在当前盘符跳转指定目录(不同盘符跳转用盘符号)(分别表示根目录 上一 ...
- 深入探究VC —— 链接器link.exe(4)
在程序编译完成后,生成的文件是以.obj为扩展名的对象文件,link.exe是将这些对象文件与库链接起来以创建可执行文件或动态链接库文件的工具. link.exe的输入文件包括obj文件.lib文件. ...
- Qt Windows下链接子系统与入口函数(终结版)(可同时存在main和WinMain函数)
Qt Windows下链接子系统与入口函数(终结版) 转载自:http://blog.csdn.net/dbzhang800/article/details/6358996 能力所限,本讨论仅局限于M ...
随机推荐
- K3S 安装及配置
K3S安装 curl -sfL https://rancher-mirror.oss-cn-beijing.aliyuncs.com/k3s/k3s-install.sh | INSTALL_K3S_ ...
- zabbix-钉钉报警部署
zabbix-钉钉报警部署 1. 流程说明 申请钉钉机器人 获取Webhook配置安全设置 获取钉钉号 使用脚本(shell/python)调用钉钉接口: python 输入收件人 信息 配置发件人 ...
- ENS框架下一次控制灯的调试记录
正常流程 登录小站,点击管理--磁盘,在硬盘下创建分区并挂载 安全下电,拔掉硬盘和TEC,再上电 硬件端 drv_fault_check_init 初始化 并绑定硬件回调 drv_fault_chec ...
- 【云原生 · Kubernetes】部署博客系统
[云原生 · Kubernetes]Kubernetes运维 接着上次的内容,后续来了! (1)配置NFS服务 master节点安装NFS与RPC服务: # yum install -y nfs-ut ...
- (C++) std::move std::forward及使用
概念 std::ref :针对std::thread,需要把实参显式转换为引用类型: std::move :无条件把参数转换为右值:但是右值赋值给新变量时,实际还要看是否满足右值条件,如const s ...
- day25-Listener监听器
Listener监听器 1.Listener监听器介绍 Listener监听器是JavaWeb三大组件之一.JavaWeb三大组件分别是:Servlet程序,Listener监听器,Filter过滤器 ...
- form enctype="multipart/form-data" ajax 文件上传
<form method="post" enctype="multipart/form-data" id="resource"> ...
- 【文档资料】Linux、Vi/Vim常用命令、文件夹和文件介绍
一.Linux 1.系统信息[左1] 查看磁盘空间使用情况:df+参数 查看当前指定文件或目录的大小:du 查看不同硬件信息:cat/proc/xxx 查看系统和空闲内存:free +参数 SSH退出 ...
- 【Scala】上:学习文档、文章、思维导图
〇.可查阅资料 1.文档 英文文档:https://tool.oschina.net/apidocs/apidoc?api=scala-docs-2.9.2 与java:https://docs.sc ...
- 万字干货|Synchronized关键字详解
作者:小牛呼噜噜 | https://xiaoniuhululu.com 计算机内功.JAVA底层.面试.职业成长相关资料等更多精彩文章在公众号「小牛呼噜噜」 前言 大家好,我是呼噜噜,在之前的文章中 ...