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

"multiply defined symbols": same sub name in different modules

bdforbes
Beginner
736 Views
I am getting this error:
modD.obj : error LNK2005: vfe$0001INNER_SUB$BLK already defined in modC.obj
modD.obj : error LNK2005: vfe$0000INNER_SUB$BLK already defined in modC.obj
Debug/module_namespace_conflict.exe : fatal error LNK1169: one or more multiply defined symbols found

This is because i have identically named inner code blocks in two modules:
[fortran]module m_C
    contains
    
    subroutine the_sub()
        integer(4)::int_a,int_b
        
        call inner_sub()
                
        contains
                            
            subroutine inner_sub()
                write(*,'(i)') int_b                
            end subroutine
            
    end subroutine
            
end module


module m_D
    contains
    
    subroutine the_sub()
        integer(4)::int_a,int_b
        
        call inner_sub()
                
        contains
                            
            subroutine inner_sub()
                write(*,'(i)') int_b                
            end subroutine
            
    end subroutine
            
end module



program main
end program 

[/fortran]
I haven't looked it up in the standard but shouldn't this be allowed?
0 Kudos
3 Replies
mecej4
Honored Contributor III
736 Views
Please report the contents of the files used in the compilation faithfully. If the code that you showed is put into one file and compiled, no error occurs. The linker output that you listed indicates that two object files were given to the linker. What do you have in files modC.f90 and modD.f90?

I do note that with Ifort 11.1 the VFE produces global symbols in the .OBJ file, but with 12.1 the VFE produces local symbols. Thus, if the same VFE were to be seen in two or more source files, multiple definitions would occur with version 11.1 but not with 12.1.
0 Kudos
bdforbes
Beginner
736 Views
Indeed, module m_C is in modC.f90 and module m_D is in modD.f90. The program block is in a separate source file.
My compiler version is 12.0.1.127, and my license may not entitle me to any more updates. If so I'll just work around the problem.
0 Kudos
Steven_L_Intel1
Employee
736 Views
1. VFEs are an extension, so you won't find anything in the standard on this.
2. Yes, it should work. It does work in 12.1 (Composer XE 2011 Update 6)
0 Kudos
Reply