为什么C ++ OBJ文件很重要? [英] Why are C++ OBJ files important?
问题描述
警告我,我是C ++的新手.
Be warned I am new to C++.
当我编译程序时,我注意到为我拥有的每个类都创建了一个.obj.当我查看程序文件中的其他程序时,我意识到这些程序几乎没有任何.obj,因此我想我做错了.
When I compile my program I notice that there is an .obj created for every class that I have. When I looked at other programs in my program files, I realized that these programs barely had any .obj's so I guess that I am doing something wrong.
此外,如果我从发行目录中删除obj文件并尝试再次运行exe,但该exe文件仍然可以像以前一样正常工作,我知道这些文件不是毫无意义的,但是...
Also if I deleted the obj files from the release directory and tried to run the exe again and it still worked exactly as before, I know these files can't be pointless but...
它们的用途是什么?是否应该为每个课程文件使用它们?-如果没有,我该如何解决?
What is their use? Should it make them for every class file? - if not how do I resolve this?
在编译时,如何将它们放在一个名为obj的文件夹之类的目录中?
How do I put them in one directory like a folder called obj when I compile?
推荐答案
.obj
文件(Linux/Unix上的 .o
文件)是已编译的源文件,确实是每个 .cpp
文件的一个,或更正式地是编译单元".它们是在构建项目的编译阶段生产的.
.obj
files (.o
files on Linux/Unix) are compiled source files, there will indeed be one for each .cpp
file, or more formally "compilation unit". They are produced by the compilation phase of building a project.
然后,这些 .obj
文件通过链接器组合到应用程序,通常是Windows上的 .exe
文件,或者是库文件(在Windows上可以是<用于动态库的code> .dll 或用于静态库的 .lib
(基本上是 .obj
文件的集合,打包成一个文件,请参见以下).在类Unix平台上,应用程序通常没有扩展名,动态库具有 .so
扩展名,而静态库具有 .a
扩展名.
These .obj
files are then combined by linker either to an application, usually .exe
file on Windows, or a library file, which on windows can be a .dll
for dynamic library, or .lib
for static library (which is basically a collection of .obj
files in one packed into one file, see below). On Unix-like platform application usually has no extension, and dynamic library has .so
extension, and static library has .a
extension.
您看不到带有程序的 .obj
文件或静态 .lib
文件,因为在运行时不需要它们,它们仅由链接器使用.当您运行构建项目的链接阶段时,链接器将所有需要的 .obj
文件组合到 .exe
和 .dll
文件(或等效文件)中),它们在运行时使用.
You do not see .obj
files or static .lib
files with programs, because they are not needed at runtime, they are used only by linker. When you run the linking phase of building a project, linker combines all the needed .obj
files into .exe
and .dll
files (or equivalent), which are used at runtime.
这篇关于为什么C ++ OBJ文件很重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!