- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would like to use DLLs in my programs.
In Visual Studio I compiled a simple main into his project, and in another project I compiled the function into DLL (see attached)
When I compile main I get: I:\FORTRAN_INTEL_TEST\Uso_DLL\BinDbg\DLL1.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2C8
According to me in the properties of the main and the DLL I have not introduced the right data. But I don't know what they are.
You can help me?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dll1 code change:
integer function myfunction(a, b)
!DEC$ ATTRIBUTES DLLEXPORT::myfunction
implicit none
integer, value :: a, b
myfunction = a + b
end function myfunction
In a VS Solution like Dll1 with exe fmain:
<fmain project>->Linker->Input Dll1.lib
<fmain project>->Linker->Additional Library Depencies $(SolutionDir)Dll1\$(OutDir)
<fmain project>->Build Events->PreBuild Event->Command Line copy $(SolutionDir)Dll1\$(OutDir)\Dll1.dll $(SolutionDir)$(ProjectName)\$(OutDir)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are many settings and check boxes in Visual studio; you have not shown us what settings you used. The following commands, executed in an Intel OneAPI command window-X64, will suffice to show that there is no problem with the source files.
ifort /dll fun.f90 /link /export:MYFUNCTION
ifort main.f90 fun.lib
Note that the first command generates not only the DLL that is desired, but also the import library FUN.LIB, and it is that library file that is used in the next step. Based on the error message that you reported, I wonder if you entered "FUN.DLL" where you should have entered "FUN.LIB" in the Visual Studio settings.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks mecej4. I solved my problem with the suggestion of MWind2.
I appreciated your support
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dll1 code change:
integer function myfunction(a, b)
!DEC$ ATTRIBUTES DLLEXPORT::myfunction
implicit none
integer, value :: a, b
myfunction = a + b
end function myfunction
In a VS Solution like Dll1 with exe fmain:
<fmain project>->Linker->Input Dll1.lib
<fmain project>->Linker->Additional Library Depencies $(SolutionDir)Dll1\$(OutDir)
<fmain project>->Build Events->PreBuild Event->Command Line copy $(SolutionDir)Dll1\$(OutDir)\Dll1.dll $(SolutionDir)$(ProjectName)\$(OutDir)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot MWind2 your suggestions solved my problem.
A question: The command is essential: <fmain project>->Build Events->PreBuild Event->Command Line copy $(SolutionDir)Dll1\$(OutDir)\Dll1.dll $(SolutionDir)$(ProjectName)\$(OutDir)
because everything works even without it.
I take advantage of your kindness:
where can I find the contents of the variables $(SolutionDir), $(OutDir) etc
Thanks again for your availability
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Those variables are defined by Visual Studio based on what you have specified in the solution and project properties. For example:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Remember that there are different Platforms whose settings are independently set, too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ConfigurationName is typically Debug or Release, and is selected by you before you build the project. I didn't mean to highlight "User compiler" in that screenshot.
In other words, these variables are taken from project and solution properties.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page