Silverfrost Forums

Welcome to our forums

Creating and calling of DLL subroutine in FTN95 Express

6 Aug 2014 6:16 #14410

Hello,

I'm just getting started with FTN95 Express v5.4.0.0 under Win7 64Bit. Now I got stuck with the following problem.

As a test case I created a Fortran DLL within Debug Win32 mode where I kept all the default project settings and just added the linker option '-exportall'. The DLL consists of the following subroutine:

SUBROUTINE HELLO
!DEC$ ATTRIBUTES DLLEXPORT :: HELLO

WRITE(*,*) 'HELLO WORLD'

RETURN
END SUBROUTINE HELLO

This subroutine should be called by the following Fortran program which I tried to build as well in Debug Win32 mode. Again I kept the default settings and just added the path and file name of the DLL under 'Import libraries'.

PROGRAM MAIN 
!DEC$ ATTRIBUTES DLLIMPORT :: HELLO

CALL HELLO

END PROGRAM MAIN

However the compilation failed with the following error message:

Project Build /////////////

C:\Users\christoph\Documents\Silverfrost FTN95 Express\Projects\FortranEXE\FortranEXE\main.f95

Compiling...

Compiling file: main.f95 FTN95.EXE 'C:\Users\christoph\Documents\Silverfrost FTN95 Express\Projects\FortranEXE\FortranEXE\main.f95' /NO_BANNER /DEBUG /FULL_DEBUG /P6 /IMPORT_LIB C:\Users\christoph\Documents\Silverfrost FTN95 Express\Projects\FortranDLL\FortranDLL\Debug\Win32\FortranDLL.dll /FPP/REF 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll' /REF 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll' /REF 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll' /VS8 /DELETE_OBJ_ON_ERROR /ERROR_NUMBERS /UNLIMITED_ERRORS /BINARY 'Debug\Win32\main.obj' Compiler output: *** More than one source file specified with names C:\Users\christoph\Documents\Silverfrost FTN95 Express\Projects\FortranEXE\FortranEXE\main.f95 and FTN95 1 ERROR [C:\Users\christoph\Documents\Silverfrost FTN95 Express\Projects\FortranEXE\FortranEXE\main.f95 FTN95 5.40.0] - Compilation failed.

There were compile errors, no link performed

FortranEXE build failed.

/////////////////////////////////////

I can't figure out the problem, so any hint would be appreciated.

Thanks and best regards Christoph

6 Aug 2014 9:23 #14413

I don't know exactly what is going wrong but the command line for the main program looks odd.

It references .NET libraries when apparently you are not using .NET. Also IMPORT_LIB should not appear if you are using FTN95 to create the DLL.

7 Aug 2014 5:58 #14422

Perhaps I should remark that I create DLL and main program in different solutions. So I thought I've to tell the compiler where to find the DLL and added its path in the project settings under Source → Import libraries (I just found out that this should be done only for libraries created with CVF ?)

However when I try to build the main program without that the follwing error message appears:

Project Build /////////////

C:\Users\christoph\Documents\Silverfrost FTN95 Express\Projects\FortranEXE\FortranEXE\main.f95

Compiling...

Compiling file: main.f95 FTN95.EXE 'C:\Users\christoph\Documents\Silverfrost FTN95 Express\Projects\FortranEXE\FortranEXE\main.f95' /NO_BANNER /DEBUG /FULL_DEBUG /P6 /FPP/REF 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll' /REF 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll' /REF 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll' /VS8 /DELETE_OBJ_ON_ERROR /ERROR_NUMBERS /UNLIMITED_ERRORS /BINARY 'Debug\Win32\main.obj'

Linking...

Command line for link: slink.exe -OUT:'Debug\Win32\FortranEXE.exe' @'C:\Users\christoph\Documents\Silverfrost FTN95 Express\Projects\FortranEXE\FortranEXE\link.lst' 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll' 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll' 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll' Linker output: WARNING the following symbols are missing: HELLO C:\Users\christoph\Documents\Silverfrost FTN95 Express\Projects\FortranEXE\FortranEXE\Debug\Win32\main.obj (C:\USERS\CHRISTOPH\DOCUMENTS\SILVERFROST FTN95 EXPRESS\PROJECTS\FORTRANEXE\FORTRANEXE\MAIN.F95) Creating executable: Debug\Win32\FortranEXE.exe

FortranEXE build succeeded.

/////////////////////////////////////

After copying the DLL into the directory of the executable and running the program I get the following error message:

Run-time Error *** Error 29, Call to missing routine : _HELLO at 0x00401021.

main - in file main.f95 at line 4 [+0026][recur= 1]

It's not clear for me if / how I have to define the location of the DLL in the project settings.

7 Aug 2014 6:23 #14425

You should be able to put two projects into one 'solution' and make one dependent on the other.

They should both be Win32 or both .NET., not a mix.

8 Aug 2014 5:19 #14429

I created a solution containing both projects and made the main program dependent on the DLL. Both are Debug Win32. Anyway I get the warning messages and the run-time error occurs.

------ Build started: Project: FortranApplicationExtension1, Configuration: Debug Win32 ------ Building project FortranApplicationExtension1... Updating References... Compiling file: hello.f95 Linking... WARNING - Default LibMain being provided Creating dynamic link library: Debug\Win32\FortranApplicationExtension1.dll

Build log saved at: 'file://C:\Users\christoph\Documents\Silverfrost FTN95 Express\Projects\Solution1\FortranApplicationExtension1\Debug\Win32\buildlog.txt' FortranApplicationExtension1 build succeeded. ------ Build started: Project: FortranApplication1, Configuration: Debug Win32 ------ Building project FortranApplication1... Updating References... Compiling file: main.f95 Linking... WARNING the following symbols are missing: HELLO C:\Users\christoph\Documents\Silverfrost FTN95 Express\Projects\Solution1\FortranApplication1\Debug\Win32\main.obj (C:\USERS\CHRISTOPH\DOCUMENTS\SILVERFROST FTN95 EXPRESS\PROJECTS\SOLUTION1\FORTRANAPPLICATION1\MAIN.F95) Creating executable: Debug\Win32\FortranApplication1.exe

Build log saved at: 'file://C:\Users\christoph\Documents\Silverfrost FTN95 Express\Projects\Solution1\FortranApplication1\Debug\Win32\buildlog.txt' FortranApplication1 build succeeded. ========== Build: 2 succeeded or up-to-date, 0 failed, 0 skipped ==========

I also switched the configuration to Debug .Net but that didn't work either.

8 Aug 2014 7:22 #14430

This looks better. Now you need to find a way to reference the DLL when linking the exe.

9 Aug 2014 6:12 #14432

Ok, I think my main mistake was that I didn't add the dll to the references of the main program. Now I'm able to build and run the program.

But when I tried to debug the application the debugging is interrupted and exits without any error message. So I went one step back (building both projects in two different solutions) and the debugging of the 'stand alone application' works without any problems.

Do I have to specify something in the debug options when handling both projects in the same solution? I couldn't find that point in the documentation.

Thanks a lot for your support so far, Paul. I'm aware that are very basic questions.

10 Aug 2014 7:44 #14436

Do I have to specify something in the debug options when handling both projects in the same solution?

Not that I know of.

Please login to reply.