1

Environment: 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.

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.

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

FaisalM
  • 724
  • 5
  • 18
  • Put the libs into folders for each architecture (eg lib32\ , lib64\). Then either set the library include path for each build or add each library to the project using the full path. – Richard Critten Jul 30 '15 at 07:57

2 Answers2

1

Put them in different directories : 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.

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.

Community
  • 1
  • 1
lucasg
  • 10,734
  • 4
  • 35
  • 57
1

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

Project Properties -> Linker -> General

Additional Library Directories

$(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

$(PlatformTarget)\$(Configuration)

Vlad Feinstein
  • 10,960
  • 1
  • 12
  • 27