c++ - 维护 32/64 位构建的通用源代码并使用正确的库

标签 c++ visual-studio visual-c++ 32bit-64bit

环境:Visual Studio 2008 Professional

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

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

寻找处理此类情况的通用指南。

最佳答案

将它们放在不同的目录中:How to use the correct unmanaged DLL file according CPU architecture? (32 / 64 bits)

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.

After calling SetDllDirectory, the standard DLL search path is:

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.

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.

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.

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

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

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

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

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

关于c++ - 维护 32/64 位构建的通用源代码并使用正确的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31717772/

相关文章:

c++ - 模板忽略 [[nodiscard]] 属性

c++ - 在 C++ 中将类实例添加到对象层次结构的问题

html - Visual Studio 2010 是否支持 HTML 5?

c++ - 有没有工具可以检测 Visual C++ 6.0 上的缓冲区溢出?

c - 如何在 Visual C++ IDE 中将 sizeof enum 设为 C 中的 char 大小

c++ - 将字符串函数复制到非 const char 缓冲区

c++ - 定义一个类并调用它的成员函数

c++ - 如何解析一组c++头文件?

visual-studio - 将 XML 架构添加到 Visual Studio

c++ - MSVC预编译头: Which files need to #include "stdafx.h"?