How to call a subroutine in a project from a different project

How to call a subroutine in a project from a different project

i have a project which has two subprojects in the visual studio.

one project contains the subroutine. another project contains the calling programs that call above subroutines.

When I call the subroutine say maxmin, it gives error saying "...unresolved external symbol _maxmin in the MAIN program"

Any help is highly appreciated.

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hello Suresh,

I'm not complete sure, but I think that in Visual Studio it isn't possible to have "sub-projects" below a "project".
Maybe you are referring to a "solution" with two projects?
If the more versed in Visual Stuio knows different, I'll appreciate the correction.

Anyway, assuming that you have a solution and two projects on it, the first thing is to know what kind of output they will create.
If both reates executables (.exe), than it isn't possible to call a subroutine in one, from another. Again, If I'm mistake, I'll appreciate to learn something new...


If one of the projects create a Lybrary (.lib), than you can add a "use" statment for the module that the subroutine is, in the module/program where you want to call it.
After this, you have to make sure that the library is compiled BEFORE the executable that is calling the routine.
You also have to add the path for the library MOD files (that will be create during the compilation) in the INCLUDE path of the FORTRAN options in the executable, AND add the path for the library itself and the name of library in the LINKER options in the executable...

Of course, if you are creating a DLL instead of a LIBRARY, than it's a bit different...

Hope this will be a start :)


Adding to what Eduardo said, at a top level you need to tell the solution that the executable project depends on the library project. This tells the linker to include the library in the executable and ensures the build process automatically compiles the library ahead of the executable.

In Visual studio, go to the menu: Project: Project dependencies...

yes, I have solution with 2 projects.

1 project has subroutine as shown below

subroutine helloworld (IARRAY, OARRAY, NSIZE)

! Expose subroutine helloworld to users of this DLL
! Variables

It compiles all well. i can see helloworld.dll is getting generated

Other project is the caller of the above subroutine. below code snippet of the 

program Helloworldtest

implicit none

! Variables

! Body of Helloworldtest

I(1) = 7
I(2) = 2
I(3) = 30
I(4) = 4
I(5) = 5

IARG = 0
CALL helloworld(I,O,5)


Now next steps

where should I set the USE statement and where to specify the helloworld.dll in the seconds project?

Your toy DLL project does not generate any MOD files, so there is no reason to have USE in the DLL consumer program.

When the DLL is generated, an import library is also generated. That file, and not the DLL itself, is the file that you add to the linker inputs in the EXE project.

I have added helloworld.lib to the linker-->input under "additional dependencies" and I have also added the directory of helloworld.lib under "Fortran --> General --> additional include directories.

when i build I get Link error "....cannot open helloworld.lib"

im here attaching the project.

helloworld, helloworldtest and IMSLTest. Here helloworld contains a subroutine (dll). helloworldtest is the caller of the subroutine in helloworld project. 

appreciate if you can tell me in the visual studio where to set to use the dll.


Downloadapplication/zip helloworld.zip1.53 MB

Leave a Comment

Please sign in to add a comment. Not a member? Join today