但我不希望我的COM库有.lib或.exp文件!

时间:2021-08-30 21:16:56

When generating a COM dll with VisualStudio, all I really need is the DllCanUnloadNow symbol (and three related ones) to be exported from the dll itself. Nobody is going to link against my library, so I'm not (at all) interested in a .lib file, nor in an .exp file.

使用VisualStudio生成COM dll时,我真正需要的是从dll本身导出的DllCanUnloadNow符号(以及三个相关的符号)。没有人会链接到我的库,所以我(根本没有)对.lib文件或.exp文件感兴趣。

However, I don't manage to inhibit creation of these files. (note: I do know how it's possible to remove them in a post-build step)

但是,我无法禁止创建这些文件。 (注意:我确实知道在构建后的步骤中如何删除它们)

These are my linker arguments:

这些是我的链接器参数:

/OUT:"u:/cada-nt/bin/PData.dll" 
/INCREMENTAL:NO 
/NOLOGO 
/DLL 
/MANIFEST:NO 
/DEF:"PData.def" 
/DEBUG 
/PDB:"u:/cada-nt/pdb/PData.pdb" 
/ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib 
                    advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib 
                    odbc32.lib odbccp32.lib

The question:

问题是:

  • Has anyone succeeded in not generating the .lib and .exp files?
  • 有没有人成功不生成.lib和.exp文件?
  • Does anyone know why these files are generated?
  • 有谁知道为什么生成这些文件?

4 个解决方案

#1


15  

Visual Studio's linker has an /IMPLIB option that allows you to specify the output location for your .lib and .exp files.

Visual Studio的链接器有一个/ IMPLIB选项,允许您指定.lib和.exp文件的输出位置。

You can modify this option in a project's properties:

您可以在项目的属性中修改此选项:

Configuration Properties > Linker > Advanced > Import Library

You might set it to the following, for example:

您可以将其设置为以下内容,例如:

$(Configuration)\$(TargetName).lib

The linker will create the .exp file using the same name as the .lib.

链接器将使用与.lib相同的名称创建.exp文件。

#2


2  

Not sure how to turn them off, but you can make a post-build step to remove them, like this:

不确定如何关闭它们,但您可以进行构建后步骤以删除它们,如下所示:

del $(OutDir)\$(ProjectName).lib
del $(OutDir)\$(ProjectName).exp

(on VS2008 it's [Project]->[Properties], then Configuration Properties->Build Events->Post-Build Events)

(在VS2008上它是[Project] - > [Properties],然后是Configuration Properties-> Build Events-> Post-Build Events)

(note I realise you know how to do this, but this answer may help the next googler...)

(注意我意识到你知道如何做到这一点,但这个答案可能有助于下一个Google员工...)

#3


1  

There some functions inside COM library declared with as __declspec(dllexport). It means that they are exported (may be used by GetProcAdress function) and linker thinks that there is a need to link with this dynamic library (no matter it is exe or dll - in general the structure is the same) and creates *.lib and *.exp file.

COM库中的一些函数用__declspec(dllexport)声明。这意味着它们被导出(可能被GetProcAdress函数使用)并且链接器认为需要链接到这个动态库(无论是exe还是dll - 通常结构是相同的)并创建* .lib和* .exp文件。

to avoid creation of these files you need to remove all __declspec(dllexport) from functions declarations

要避免创建这些文件,您需要从函数声明中删除所有__declspec(dllexport)

#4


-1  

why is it a problem to generate these files? Surely if people aren't going to link directly to them all you need to do is not distribute those files and simply distribute the DLL only.

为什么生成这些文件有问题?当然,如果人们不打算直接链接到他们所有你需要做的就是不分发这些文件,只是简单地分发DLL。

#1


15  

Visual Studio's linker has an /IMPLIB option that allows you to specify the output location for your .lib and .exp files.

Visual Studio的链接器有一个/ IMPLIB选项,允许您指定.lib和.exp文件的输出位置。

You can modify this option in a project's properties:

您可以在项目的属性中修改此选项:

Configuration Properties > Linker > Advanced > Import Library

You might set it to the following, for example:

您可以将其设置为以下内容,例如:

$(Configuration)\$(TargetName).lib

The linker will create the .exp file using the same name as the .lib.

链接器将使用与.lib相同的名称创建.exp文件。

#2


2  

Not sure how to turn them off, but you can make a post-build step to remove them, like this:

不确定如何关闭它们,但您可以进行构建后步骤以删除它们,如下所示:

del $(OutDir)\$(ProjectName).lib
del $(OutDir)\$(ProjectName).exp

(on VS2008 it's [Project]->[Properties], then Configuration Properties->Build Events->Post-Build Events)

(在VS2008上它是[Project] - > [Properties],然后是Configuration Properties-> Build Events-> Post-Build Events)

(note I realise you know how to do this, but this answer may help the next googler...)

(注意我意识到你知道如何做到这一点,但这个答案可能有助于下一个Google员工...)

#3


1  

There some functions inside COM library declared with as __declspec(dllexport). It means that they are exported (may be used by GetProcAdress function) and linker thinks that there is a need to link with this dynamic library (no matter it is exe or dll - in general the structure is the same) and creates *.lib and *.exp file.

COM库中的一些函数用__declspec(dllexport)声明。这意味着它们被导出(可能被GetProcAdress函数使用)并且链接器认为需要链接到这个动态库(无论是exe还是dll - 通常结构是相同的)并创建* .lib和* .exp文件。

to avoid creation of these files you need to remove all __declspec(dllexport) from functions declarations

要避免创建这些文件,您需要从函数声明中删除所有__declspec(dllexport)

#4


-1  

why is it a problem to generate these files? Surely if people aren't going to link directly to them all you need to do is not distribute those files and simply distribute the DLL only.

为什么生成这些文件有问题?当然,如果人们不打算直接链接到他们所有你需要做的就是不分发这些文件,只是简单地分发DLL。