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

时间:2023-02-05 12:51:10

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?

我有一个问题:我的任务是构建一个应用程序。有一个现成的文件计数器。h和一些其他文件。结果是在柜台上。只有函数的声明—如何将.obj文件包含到.cpp文件中以便编译?我使用的是Microsoft Visual Studio 2010——文件应该放在哪个文件夹中?

2 个解决方案

#1


12  

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).

将objc文件添加到解决方案中,就像使用cpps文件一样(我通常通过拖拽来完成这个操作,即从Windows资源管理器中拖出文件,并将其放到解决方案Exporer窗口中的一个项目中)。

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

可以将目标文件与cppfile放在一起;它并不重要。

#2


3  

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文件,这些文件进一步链接在一起创建一个libray或一个可执行文件。

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

通常,您会链接库(。库或。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.

您可以尝试将对象文件链接到您的应用程序:转到项目属性,然后从“属性页”选择节点“C/C++ +”,您将得到“附加包含目录”,添加对象文件的名称。将obj文件保存在源代码所在的目录中,或者可以添加目录:Tools->选项->项目和解决方案-> +目录。

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上的信息。

#1


12  

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).

将objc文件添加到解决方案中,就像使用cpps文件一样(我通常通过拖拽来完成这个操作,即从Windows资源管理器中拖出文件,并将其放到解决方案Exporer窗口中的一个项目中)。

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

可以将目标文件与cppfile放在一起;它并不重要。

#2


3  

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文件,这些文件进一步链接在一起创建一个libray或一个可执行文件。

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

通常,您会链接库(。库或。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.

您可以尝试将对象文件链接到您的应用程序:转到项目属性,然后从“属性页”选择节点“C/C++ +”,您将得到“附加包含目录”,添加对象文件的名称。将obj文件保存在源代码所在的目录中,或者可以添加目录:Tools->选项->项目和解决方案-> +目录。

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上的信息。