error LNK2005: DllMain already defined in msvcrt.lib(dll_dll

I try to make a DLL with the pgfortran compiler. I first did the example in the manual (page 123), which worked with version 18.4 (I reported the bug in version 18.10 in January, and went back to version 18.4).

Now I want to do my own subroutine. Actually, i have several subroutines, but I want to export only three of them. I.e., a user should be able to call these three subroutines, but the other subroutines (which are only used internally) should be hidden from him. Hence I wrote three sources files like

subroutine sub1(x)
!DEC$ ATTRIBUTES DLLEXPORT :: sub1

end subroutine sub1

etc.

The project also uses libblas.lib and liblapack.lib. I am using Code::Blocks as an IDE.

When I build this project, I get the above error message. However, in no place in my source do I define a function “DllMain”. And this error does not occur with the example in the manual (which contains only a single subroutine and a common block that are exported).

Is this problem related to the fact that the DLL contains several exported subroutines? Or is the problem with the use of the lapack and blas libraries? I include the complete build-lob below.

best regards,
Bernhard

build log:

-------------- Build: Debug in MevelerDLL (compiler: PGI Fortran Compiler)---------------

pgfortran.exe -Mmakedll obj\Debug\src\AbelGuess.o obj\Debug\src\CopyVector.o obj\Debug\src\Entropy4Meveler.o obj\Debug\src\HistoricMEM2.o obj\Debug\src\Legend.o obj\Debug\src\LegendreProject3.o obj\Debug\src\MevelerTools.o obj\Debug\src\Modul_MevelerOptions.o obj\Debug\src\SimLeg.o obj\Debug\src\SimSC2.o obj\Debug\src\FetchOption.o obj\Debug\src\MevelerDLL3.o obj\Debug\src\SetOptions.o -o bin\Debug\MevelerDLL.dll -Mmakedll “…......\Program Files\PGICE\win64\18.4\lib\libblas.lib” “…......\Program Files\PGICE\win64\18.4\lib\liblapack.lib”
libblas.lib(memory.obj) : error LNK2005: DllMain already defined in msvcrt.lib(dll_dllmain_stub.obj)
Creating library bin\Debug\MevelerDLL.lib and object bin\Debug\MevelerDLL.exp
bin\Debug\MevelerDLL.dll : fatal error LNK1169: one or more multiply defined symbols found
Process terminated with status 2 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

You might want to try adding -Mnopgdllmain to your compile line. That option won’t link in the standard module that defines DllMain so you might be able to resolve the multiple-defined symbols error with that. I can try to put together an example later, but I have a feeling it is not related to including multiple subroutines or the blas/lapack libraries.

Let me know if that works.

Dear aglobus,

thank you for this hint. I tried it, but it did not resolve the problem. It seems to me that the problem is relatet to BLAS, I marked the line below is the build-log.

best regards,
Bernhard

-------------- Build: Debug in MevelerDLL (compiler: PGI Fortran Compiler)---------------

pgfortran.exe -Mmakedll obj\Debug\src\AbelGuess.o obj\Debug\src\CopyVector.o obj\Debug\src\Entropy4Meveler.o obj\Debug\src\HistoricMEM2.o obj\Debug\src\Legend.o obj\Debug\src\LegendreProject3.o obj\Debug\src\MevelerTools.o obj\Debug\src\Modul_MevelerOptions.o obj\Debug\src\SimLeg.o obj\Debug\src\SimSC2.o obj\Debug\src\FetchOption.o obj\Debug\src\MevelerDLL3.o obj\Debug\src\SetOptions.o -o bin\Debug\MevelerDLL.dll -Mmakedll -Mnopgdllmain “…......\Program Files\PGICE\win64\18.4\lib\libblas.lib” “…......\Program Files\PGICE\win64\18.4\lib\liblapack.lib”
libblas.lib(memory.obj) : error LNK2005: DllMain already defined in msvcrt.lib(dll_dllmain_stub.obj)
Creating library bin\Debug\MevelerDLL.lib and object bin\Debug\MevelerDLL.exp
bin\Debug\MevelerDLL.dll : fatal error LNK1169: one or more multiply defined symbols found
Process terminated with status 2 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

Dear aglobus,

I made a small test example with three subroutines, two are exported, one is not. This does not produce the error. I used, in one of the subroutines, a call to the BLAS routine ddot, included IO, and allocate memory, but all of this does not create the error. So I have no idea what could cause it in my program. Interestingly, when I switch to GNU-fortran and use my own compilation of the OpenBLAS library, the DLL is built successfully. So perhaps the problem is still with the pg version of BLAS, but does not occur when only DDOT is used. Actually, I am using the Lapack routine DGELSD and the BLAS routine DGEMM.

best regards,
Bernhard

p.s.: is there a way to attach the test code? its only 30 lines, but I can not copy/paste it here?

Hi Bernhard,

Ah, yes. You’re right, I glossed over that. If you could send the reproducer to trs@pgroup.com I can take a peek at it.

I made a funny observation: When I reverse the order of the libraries, the error disappears:

-lblas -llapack : error message, linking aborts.
-llapack -lblas : successful compilation and linking. The program works as expected.

I will try to make an small example and send to the email address.

best regards,
Bernhard

I’m working in ABAQUS, which is linked with the Fortran compiler to write the subroutines. I’m getting the same error. How do I fix this error? Where are these libraries? kindly help me

Hi kkruthika835 and welcome!

Can you provide more detail? Are you getting the multiply defined references to DllMain coming from the BLAS library as seen above or something different?

Are you creating you’re own DLL as a plugin for ABAQUS, and if so, did you try the above suggestion of adding the “-Mnopgdllmain” flag when building the DLL?

Also, what compiler version are you using?

-Mat

Thank you, sir, for the reply.
Subject : Assistance with VUMAT linking error in Abaqus 2023

The error I’m getting is:

Creating library explicitU.lib and object explicitU.exp
explicitU_static.lib(SMAUXpUsubs_XP_IF.obj) : error LNK2005: DllMain already defined in MSVCRT.lib(dll_dllmain_stub.obj)
explicitU.dll : fatal error LNK1169: one or more multiply defined symbols found
Abaqus Error: Problem during linking - Single Precision Abaqus/Explicit User Subroutines.
This error may be due to a mismatch in the Abaqus user subroutine arguments.
These arguments sometimes change from release to release, so user subroutines
used with a previous release of Abaqus may need to be adjusted.
Abaqus/Analysis exited with errors

Please find the requested details below:

  1. Nature of multiply defined DllMain reference
    The multiply defined symbol is reported exactly as:
    SMAUXpUsubs_XP_IF.obj : error LNK2005: DllMain already defined in MSVCRT.lib(dll_dllmain_stub.obj)
    It does not appear to be associated with BLAS or LAPACK libraries in this case. The issue is triggered specifically when linking the VUMAT that contains multiple internal subroutines; my simpler VUMATs compile and run without any errors.

  2. DLL creation
    I am not creating my own DLL plugin for Abaqus. I am only compiling a Fortran VUMAT user subroutine through Abaqus/Explicit. No custom DLL project has been created in Visual Studio.

    Therefore, I have not used the -Mnopgdllmain option so far.

  3. Compiler version
    My current software configuration is:

    • Abaqus 2023

    • Visual Studio 2019

    • I am using Intel oneAPI Fortran Compiler (ifx), Version 2025.3.0, integrated with Abaqus 2023 and Visual Studio 2019. The ifx /logo command returns the compiler banner successfully.

If useful, I can also share:

  • the full .log and .dat files

  • the complete VUMAT source code

  • the abaqus_v6.env file I am currently using

Please let me know what additional information would help diagnose this further.

Thank you again for your support.

Kind regards,
Kruthika

Hi Kruthika,

This forum is for questions about the NVHPC (formerly PGI) compiler suite. I suggest you contact Intel. My guess is that you need to add something similar to our -Mnopgdllmain flag but I’m not familiar enough with the Intel compilers to know for sure.

-Mat

Thank you for the reply. I fixed it by commenting out a few lines in the code.