X
18018

How to create a 64-bit C DLL with MSVC 2017 and IDL 8.7 for Windows 10

 

Background:

 

IDL 8.7 is compiled using Microsoft Visual Studio version 2010. Thus, the recommended compiler to create a DLL for IDL 8.7 would be version 2010 of MSVC. However:

 

  • The free version of MSVC 2010 is 32-bit only
  • The SDK library required to compile 64-bit DLL with MSVC 2010 mode (see link below) is no longer supported with Windows 10.

https://www.harrisgeospatial.com/Support/Self-Help-Tools/Help-Articles/Help-Articles-Detail/ArtMID/10220/ArticleID/16074/How-to-compile-a-64-bit-C-DLL-using-MVS-2010-and-run-it-in-IDL

 

 

Available options to create a DLL with MSVC 2010 for Windows 10

 

There are currently 3 options to compile a DLL for IDL 8.7 and Windows 10 using MSVC 2010. However, none is ideal.

 

Option 1:  use the PRO version of MSVC 2010. However, it is not a free version and it requires to buy a MSVC license

 

Option 2: create 32-bit DLL using MSVC 2010. However, it requires to call such DLL in IDL 32-bit, which is not ideal due to memory limitations of 32-bit applications.

 

Option 3: it seems there are some ways to install the SDK library so MSVC 2010 free version may compile 64-bit DLL. However, it requires to modify registry keys which is not possible for many customers - and is potentially not recommended either.

 

 

How to create a 64-bit DLL using MSVC 2017 for IDL 8.7 on Windows 10

 

Another option is to use a higher version of the MSVC compiler such as 2017 which is 64-bit compatible. It is usually not recommended to use a compiler of a different version than the one used to compile IDL:  there could be some library incompatibilities due to the changes between 2 compiler versions which will cause the compilation to fail.

However, the procedure below shows how to configure and use MSVC 2017 to successfully compile a 64-bit DLL to be called in IDL 8.7 on Windows 10.

 

1. Download and install MSVC 2017 free version

 

2. If not yet installed on your Windows 10 system: download and install Windows Kits 10: 

https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk

 

3. Start the MSVC 2017 prompt called: x86_x64 cross Tools Command Prompt for VS 2017. 

This is the only prompt which will allow to build a 64-bit DLL compatible with IDL 8.7

 

4. Launch IDL 8.7 64-bit from the MSVC prompt 

cd "C:\Program Files\Harris\IDL87\bin\bin.x86_64"

idl.exe

 

5. Initialize the working directory where the .c code - to be used to build the DLL- resides. For example:

c_dir="C:\TEMP\test_dll"

cd,c_dir

 

6. Adapt the !MAKE_DLL variable to take into account the changes in library names between MSVC 2010 and MSVC 2017

!make_dll.ld='link /out:%L /nologo /nodefaultlib /dll %O /def:%E "C:\Program Files\Harris\IDL87\bin\bin.x86_64\idl.lib" ucrt.lib vcruntime.lib libcmt.lib kernel32.lib %X'

 

7. Define LIB and INCLUDE environment variables to point to the expected libraries and headers (adapt the path if needed).

SETENV, 'LIB=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64' 

print,GETENV("LIB")

 

SETENV, 'INCLUDE=C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include'

print,GETENV("INCLUDE")

 

8. Build the 64-bit DLL. The below example is based on the testmodule C code example available in the IDL distribution C:\Program Files\Harris\ENVI55\IDL87\external\dlm.

The testmodule.c code and its DLM are previously saved in the working directory defined at step 5: C:\TEMP\test_dll.

make_dll, 'testmodule', 'IDL_Load', input_directory=c_dir, OUTPUT_DIRECTORY=c_dir

 

9. Save a copy of the testmodule.dlm and the testmodule.dll created at step 8 DLM default path. For example: C:\Program Files\Harris\IDL87\bin\bin.x86_64

 

10. Run the DLL

DLM_REGISTER,'C:\Program Files\harris\IDL87\bin\bin.x86_64\testmodule.dlm'

print,testfun()

IDL  should output  :

% Loaded DLM: TESTMODULE

% TESTFUN: This is from a loadable module function.

TESTFUN    

 

 

 

 

-------------------------------------------

Created by BC on 02/11/19 - Reviewd by BenC on 02/15/19