C++ 如何将 .obj 文件包含到项目中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7946513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 17:46:04  来源:igfitidea点击:

How to include .obj files into the project

c++

提问by Artem Moskalev

I have the following question: I was given the task - to build an application. There was a ready file counter.h and some other file - counter.obj. It turned out that in the counter.h there were only declarations of the functions - how can I include .obj file into the .cpp file so that it compiles? I am using Microsoft Visual Studio 2010 - and in which folder should the file itself go?

我有以下问题:我被赋予了任务 - 构建应用程序。有一个准备好的文件 counter.h 和一些其他文件 - counter.obj。事实证明,在 counter.h 中只有函数的声明 - 如何将 .obj 文件包含到 .cpp 文件中以便编译?我正在使用 Microsoft Visual Studio 2010 - 文件本身应该放在哪个文件夹中?

回答by anatolyg

Add the obj-file to the Solution just as you would do with cpp-files (i usually do this by drag-and-drop, that is, drag the file from the Windows Explorer and drop it on a project in the Solution Exporer window).

将 obj 文件添加到解决方案中,就像使用 cpp 文件一样(我通常通过拖放来完成此操作,即将文件从 Windows 资源管理器中拖放到解决方案资源管理器窗口中的项目上)。

You can put the obj-file together with cpp-files; it doesn't really matter.

您可以将 obj 文件与 cpp 文件放在一起;没关系。

回答by Alok Save

You do cannot include object file in to a cpp file.
The compiler compiles the cpp file and generates the obj files, for each cpp file, these files are further linked together to create an libray or an executable.

您不能将目标文件包含在 cpp 文件中。
编译器编译 cpp 文件并生成 obj 文件,对于每个 cpp 文件,这些文件进一步链接在一起以创建库或可执行文件。

Usually, you would link libraries(.libor .dll) to an Application, Check if those are with you.

通常,您会将库(.lib.dll)链接到应用程序,检查它们是否与您同在。

If not,

如果不,

You can try linking the object file to your application by:
Go to project properties then from "Property Page"select the node "C/C++"their you will get "Additional Include Directories"add the name of your object file.Keep your obj file in the directory where your source code is or you can add the directory from:
Tools->Options->Projects and Solutions->VC++Directories.

您可以尝试通过以下方式将目标文件链接到您的应用程序:
转到项目属性,然后从"Property Page"选择"C/C++"他们将获得的节点"Additional Include Directories"添加目标文件的名称。将 obj 文件保存在源代码所在的目录中,或者您可以添加目录来自:
Tools->Options->Projects and Solutions->VC++Directories

I have never tried the second method except for academic projects,which was years ago, So not sure about it, Please check information on MSDN.

除了几年前的学术项目,我从未尝试过第二种方法,所以不确定,请查看MSDN上的信息。