Link error building a project under Win32

@ferrad ,

Have you attempted a simple check first on your system, presumably running 64-bit Windows OS, that you are able to execute 32-bit targets ok? If not, you may want to try that out.

Click for quick test code

See this link from Microsoft:

  • C++ DllMain.cpp file
#include "windows.h"

BOOL WINAPI DllMain(
    HINSTANCE hinstDLL,  // handle to DLL module
    DWORD fdwReason,     // reason for calling function
    LPVOID lpvReserved )  // reserved
{
    int msgboxID;

    // Perform actions based on the reason for calling.
    switch( fdwReason ) 
    { 
        case DLL_PROCESS_ATTACH:
         // Initialize once for each new process.
         // Return FALSE to fail DLL load.
            msgboxID = MessageBox(
                NULL,
                (LPCSTR)"DllMain invoked",
                (LPCSTR)"Test DLL",
                MB_OK );
            break;

        case DLL_THREAD_ATTACH:
         // Do thread-specific initialization.
            break;

        case DLL_THREAD_DETACH:
         // Do thread-specific cleanup.
            break;

        case DLL_PROCESS_DETACH:
        
            if (lpvReserved != nullptr)
            {
                break; // do not do cleanup if process termination scenario
            }
            
         // Perform any necessary cleanup.
            break;
    }
    return TRUE;  // Successful DLL_PROCESS_ATTACH.
}
  • silly Fortran “library” code: m.f90
module m
contains
   function f( n ) result(r)
      integer, intent(in) :: n
      integer :: r
      r = n + 42
   end function 
end module 
  • Microsoft-recommended DLL definition file, m.def
LIBRARY m
EXPORTS
    M_mp_F        @1

Build steps:on a command-line window toward 32-bit target

C:\temp>cl /c /W3 /EHsc dllmain.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.34.31937 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

dllmain.cpp

C:\temp>ifort /c /standard-semantics /Qm32 m.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on IA-32, Version 2021.8.0 Build 20221119_000000
Copyright (C) 1985-2022 Intel Corporation.  All rights reserved.


C:\temp>link m.obj dllmain.obj user32.lib /dll /def:m.def /out:m.dll
Microsoft (R) Incremental Linker Version 14.34.31937.0
Copyright (C) Microsoft Corporation.  All rights reserved.

   Creating library m.lib and object m.exp

C:\temp>ifort /c /standard-semantics /Qm32 p.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on IA-32, Version 2021.8.0 Build 20221119_000000
Copyright (C) 1985-2022 Intel Corporation.  All rights reserved.


C:\temp>link p.obj m.lib /subsystem:console /out:p.exe
Microsoft (R) Incremental Linker Version 14.34.31937.0
Copyright (C) Microsoft Corporation.  All rights reserved.


C:\temp>
  • Program execution that proves success:

image

image

If the above works, then you can proceed to your Visual Studio solution and project file and where the DLL gets placed, etc. and fix any loose ends to resolve your problem. The above test should provide all the things to check.

But if not, you have to look at your OS config and how you are building the 32-bit target.