Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29246 Discussions

Visual Studio 2010 / OOP: Two Projects using the same object?

stutzbach
Beginner
400 Views

Hello,

compiling the listed code I get an error I do not understand. Perhaps someone knows why? I am using the Visual Fortran Compiler 12.0.3470.2010 in Visual Studio 2010 Professional.

There are two projects in my solution. The first project is called "Test", while the second one's called "Test2"

"Test" contains Test.f90:

program Test

use testzweimodule

implicit none

real :: a = 34

type(abc) :: thisabc

CALL thisabc%set_a(a)

write(*,*) 'Test.f90'

read(*,*)

end program Test

"Test2" contains Test2.f90:

program Test2

use testzweimodule

implicit none

real :: a = 34

type(abc) :: thisabc

CALL thisabc%set_a(a)

end program Test2

and Test2Module.f90:

MODULE testzweimodule

implicit none

type, public :: abc

real :: a

contains

procedure set_a=>set_a_sub

end type

private :: set_a_sub

contains

subroutine set_a_sub(this, a)

implicit none

class(abc) :: this

real :: a

this%a = a

write(*,*) a

read(*,*)

end subroutine set_a_sub

END MODULE testzweimodule

Okay, thank your for reading so far. Now the problem, when I try to build project "Test" I get the following error: error LNK2001: unresolved external symbol_TESTZWEIMODULE_mp_SET_A_SUB.

Project "Test2" runs without producing an error. Always. When in Test.f90 CALL thisabc%set_a(a)

is commented out (like: !CALL thisabc%set_a(a)), this project also is build without an error and runs fine.

In Project Dependencies of course, "Test" depends on "Test2".

I am not so deep in OOP, but isn't it possible to use objects from other projects? Using subroutines and functions from other modules in other projects never produces an error.

Would be nice, if someone can help me...I am sitting here for a few hours....

Greetings

Moritz

0 Kudos
1 Reply
Steven_L_Intel1
Employee
400 Views
It looks as if both projects are executable projects. If so, then making one a dependent on the other affects build order only - it will not cause linking in of objects from the dependent project. That happens only if the dependent project is a "library" project, and this is usually the correct choice for a module.

What I suggest is putting TESTZWEIMODULE into its own static library project and making Test1 and Test2 dependent on it.
0 Kudos
Reply