首页 > 编程语言 >C++Beginner(3)-Compile

C++Beginner(3)-Compile

时间:2022-08-22 22:33:37浏览次数:136  
标签:code Beginner object dynamic library Compile static C++ file

compiling

source code file(.cpp,.cxx,.cc,.C,.c++) -> object files(.o,.obj) -> link object files together into an executable (app.exe, app), static library(.lib, .a), or dynamic library(.dll, .so)

If any of the source code files changed, we recompile them to generate a new object file and then run the linker with all the unchanged object files too.

object file

a binary file that is specific to a particular version of a particular compiler configured with particular settings

If the compiler, version, or settings change, all the code needs to be rebuilt.

diff between a static library and a dynamic library

dynamic library: a library of machine code, just like an executable. it can be loaded and unloaded by an executable or other dynamic library at runtime.

static library: can only be loaded at compile time and can never be unloaded.
Because static libraries are available at build time, the linker builds them directly into the resulting executable.

Critically for performance, all calls into functions in the static library are just normal function calls. This means there’s no indirection through a pointer that is set at runtime when a dynamic library is loaded. It also means that the linker can perform “link time optimizations” such as inlining these functions.

The main downsides stem from needing the static libraries to be present at compile time. This makes them unsuitable for tasks such as loading user-created plugins. Perhaps most importantly for large projects, they must be linked in every build even if just one small source file was changed. Link times grow proportionally and can hinder rapid iteration. As a result, sometimes dynamic libraries will be used in development builds and static libraries will be used in release builds.

directives

ifndef MATH_H == if (!defined MATH_H)

pragma once

标签:code,Beginner,object,dynamic,library,Compile,static,C++,file
From: https://www.cnblogs.com/francisforeverhappy/p/16614491.html

相关文章

  • c++ 智能指针
    智能指针,是模板类,意在避免在使用动态内存时,出现异常等意外,或忘记使用delete,而造成内存泄漏。这个智能指针,在指针变量结束声明周期后,调用对象的析构函数,并自动去释放这个指......
  • 【C++-笔记】访问说明符public、protected和private的用途和区别
    在C++当中,访问说明符主要在如下两个场景中使用:成员访问说明符当我们在定义/声明一个类时,需要使用成员访问说明符来说明成员的访问权限,public、protected和private的区别......
  • 从C过渡到C++——换一个视角深入数组[真的存在高效吗?](2)
    从C过渡到C++——换一个视角深入数组[真的存在高效吗?](2)C风格高效的数组遍历在过渡到C++之前我还是想谈一谈如何书写高效的C的代码,这里的高效指的是C代码的高效,也就是在不......
  • rk3566 linux编译运行librga C++程序
    本文使用的是linuxaarch64版librga.so(1.3.2),来自https://github.com/airockchip/librga 运行环境:rk3566linux系统编译环境:ubuntu20.04gcc/g++9.4工具链:gcc-buildroot......
  • c++ 跑酷小游戏之用户体验plus
    #undefUNICODE#undef_UNICODE#include<iostream>#include<iomanip>#include<string>#include<cstdlib>#include<ctime>#include<windows.h>#include<conio.h>#inc......
  • 学习MFC遇到的问题(VC++深入详解)
    1.关于动态链接库dll编写:VS2015中用C++创建MFCDLL动态库2.【C++】Debug模式和Release模式的区别:3.也是一个靓仔实现的window的txt,使用CEditView:MFC单文档框架建立4.w......
  • effective c++注意点
    item2: item3:  只有被const修饰过的成员函数才能操作const变量......
  • C++ 炼气期之结构体
    1.前言随着计算机向着不同领域的延伸,数据的概念已经不仅局限于数值型数据,计算机需要处理大量的非数值、且复杂的类型数据。为了能抽象地描述这些非数值、复杂类型的数据......
  • 关于C/C++的Warning解释
    关于C/C++的Warning解释如何发现更多Warning在编译时加上命令-Wall和-Wextra即g++a.cpp-oa.out-Wall-WextraWarning是极为有用的,可以提醒你一些意想不到的问题......
  • 《《关于我把好好的c++小游戏改的很ex》》
    #undefUNICODE#undef_UNICODE#include<iostream>#include<iomanip>#include<string>#include<cstdlib>#include<ctime>#include<windows.h>#include<conio.h>#inc......