维护32/64位构建的公共源代码并使用正确的库

时间:2022-09-01 10:01:51

Environment: Visual Studio 2008 Professional

环境:Visual Studio 2008 Professional

We are porting our 32 bit windows application to 64 bit. Our application uses a number of Microsoft dlls like htmlhelp.dll. For this we added their import libraries to project.

我们将32位Windows应用程序移植到64位。我们的应用程序使用许多Microsoft dll,如htmlhelp.dll。为此我们将他们的导入库添加到项目中。

Now we have 32 and 64 bit version of htmlhelp.lib (surprisingly both have same name). Why MS gave them the same name. How will an application select the right .lib for the current build platform.

现在我们有32位和64位版本的htmlhelp.lib(令人惊讶的是它们都有相同的名称)。为什么MS给了他们相同的名字。应用程序如何为当前构建平台选择正确的.lib。

Looking for a general guideline to handle this type of situation.

寻找处理此类情况的一般准则。

2 个解决方案

#1


1  

Put them in different directories : How to use the correct unmanaged DLL file according CPU architecture? (32 / 64 bits)

将它们放在不同的目录中:如何根据CPU架构使用正确的非托管DLL文件? (32/64位)

The SetDllDirectory function affects all subsequent calls to the LoadLibrary and LoadLibraryEx functions. It also effectively disables safe DLL search mode while the specified directory is in the search path.

SetDllDirectory函数影响对LoadLibrary和LoadLibraryEx函数的所有后续调用。当指定目录位于搜索路径中时,它还有效地禁用安全DLL搜索模式。

After calling SetDllDirectory, the standard DLL search path is:

调用SetDllDirectory后,标准DLL搜索路径为:

The directory from which the application loaded.
The directory specified by the lpPathName parameter.
The system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is System32.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory

is System. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. The directories that are listed in the PATH environment variable.

是系统。 Windows目录。使用GetWindowsDirectory函数获取此目录的路径。 PATH环境变量中列出的目录。

Each time the SetDllDirectory function is called, it replaces the directory specified in the previous SetDllDirectory call. To specify more than one directory, use the AddDllDirectory function and call LoadLibraryEx with LOAD_LIBRARY_SEARCH_USER_DIRS.

每次调用SetDllDirectory函数时,它都会替换先前SetDllDirectory调用中指定的目录。要指定多个目录,请使用AddDllDirectory函数并使用LOAD_LIBRARY_SEARCH_USER_DIRS调用LoadLibraryEx。

To revert to the standard search path used by LoadLibrary and LoadLibraryEx, call SetDllDirectory with NULL. This also restores safe DLL search mode based on the SafeDllSearchMode registry value.

要恢复为LoadLibrary和LoadLibraryEx使用的标准搜索路径,请使用NULL调用SetDllDirectory。这还可以基于SafeDllSearchMode注册表值恢复安全的DLL搜索模式。

To compile an application that uses this function, define _WIN32_WINNT as 0x0502 or later. For more information, see Using the Windows Headers.

要编译使用此函数的应用程序,请将_WIN32_WINNT定义为0x0502或更高版本。有关更多信息,请参阅使用Windows标头。

I use the same technique for cross-plateforms build scripts :

我使用相同的技术来进行跨平台构建脚本:

# OS-dependant tools and files
ifeq ($(OS), Windows_NT)
    ARCH = win
else
    ARCH = linux
endif

TMP := tmp_$(ARCH)
LIB := lib_$(ARCH)
BIN := bin_$(ARCH)

In VisualStudio, create a Debug and Release build configuration for each architecture, and point the working directory (where you put the dll) accordingly.

在VisualStudio中,为每个体系结构创建一个Debug和Release构建配置,并相应地指向工作目录(放置dll的位置)。

#2


1  

Create common folder for such libraries, like lib, with two subfolders named as your build targets (x86 and x64). Then add

为lib这样的库创建公共文件夹,其中有两个子文件夹,命名为构建目标(x86和x64)。然后加

Project Properties -> Linker -> General

项目属性 - >链接器 - >常规

Additional Library Directories

其他图书馆目录

$(PlatformTarget)

$(PlatformTarget)

for all configurations. In case you have different versions for Debug and Release, create such subfolders too, like lib\x64\Debug, and add to your directories to

适用于所有配置。如果你有不同的Debug和Release版本,也要创建这样的子文件夹,比如lib \ x64 \ Debug,并添加到你的目录中

$(PlatformTarget)\$(Configuration)

$(PlatformTarget)\ $(配置)

#1


1  

Put them in different directories : How to use the correct unmanaged DLL file according CPU architecture? (32 / 64 bits)

将它们放在不同的目录中:如何根据CPU架构使用正确的非托管DLL文件? (32/64位)

The SetDllDirectory function affects all subsequent calls to the LoadLibrary and LoadLibraryEx functions. It also effectively disables safe DLL search mode while the specified directory is in the search path.

SetDllDirectory函数影响对LoadLibrary和LoadLibraryEx函数的所有后续调用。当指定目录位于搜索路径中时,它还有效地禁用安全DLL搜索模式。

After calling SetDllDirectory, the standard DLL search path is:

调用SetDllDirectory后,标准DLL搜索路径为:

The directory from which the application loaded.
The directory specified by the lpPathName parameter.
The system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is System32.
The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory

is System. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. The directories that are listed in the PATH environment variable.

是系统。 Windows目录。使用GetWindowsDirectory函数获取此目录的路径。 PATH环境变量中列出的目录。

Each time the SetDllDirectory function is called, it replaces the directory specified in the previous SetDllDirectory call. To specify more than one directory, use the AddDllDirectory function and call LoadLibraryEx with LOAD_LIBRARY_SEARCH_USER_DIRS.

每次调用SetDllDirectory函数时,它都会替换先前SetDllDirectory调用中指定的目录。要指定多个目录,请使用AddDllDirectory函数并使用LOAD_LIBRARY_SEARCH_USER_DIRS调用LoadLibraryEx。

To revert to the standard search path used by LoadLibrary and LoadLibraryEx, call SetDllDirectory with NULL. This also restores safe DLL search mode based on the SafeDllSearchMode registry value.

要恢复为LoadLibrary和LoadLibraryEx使用的标准搜索路径,请使用NULL调用SetDllDirectory。这还可以基于SafeDllSearchMode注册表值恢复安全的DLL搜索模式。

To compile an application that uses this function, define _WIN32_WINNT as 0x0502 or later. For more information, see Using the Windows Headers.

要编译使用此函数的应用程序,请将_WIN32_WINNT定义为0x0502或更高版本。有关更多信息,请参阅使用Windows标头。

I use the same technique for cross-plateforms build scripts :

我使用相同的技术来进行跨平台构建脚本:

# OS-dependant tools and files
ifeq ($(OS), Windows_NT)
    ARCH = win
else
    ARCH = linux
endif

TMP := tmp_$(ARCH)
LIB := lib_$(ARCH)
BIN := bin_$(ARCH)

In VisualStudio, create a Debug and Release build configuration for each architecture, and point the working directory (where you put the dll) accordingly.

在VisualStudio中,为每个体系结构创建一个Debug和Release构建配置,并相应地指向工作目录(放置dll的位置)。

#2


1  

Create common folder for such libraries, like lib, with two subfolders named as your build targets (x86 and x64). Then add

为lib这样的库创建公共文件夹,其中有两个子文件夹,命名为构建目标(x86和x64)。然后加

Project Properties -> Linker -> General

项目属性 - >链接器 - >常规

Additional Library Directories

其他图书馆目录

$(PlatformTarget)

$(PlatformTarget)

for all configurations. In case you have different versions for Debug and Release, create such subfolders too, like lib\x64\Debug, and add to your directories to

适用于所有配置。如果你有不同的Debug和Release版本,也要创建这样的子文件夹,比如lib \ x64 \ Debug,并添加到你的目录中

$(PlatformTarget)\$(Configuration)

$(PlatformTarget)\ $(配置)