Community
cancel
Showing results for 
Search instead for 
Did you mean: 
haijunwu
Beginner
85 Views

problems of mixed program with fortran

I called a Fortran subroutine from a c++ project, in which the fortran subroutine is packed in an library created by the IVF. However, the link always fails with an error LNK2019. 

I set up an simple test project to simulate the problem. 

The fortran subroutine is a simple summation of integers:

    subroutine FSum(n,m,sum)
    implicit none
    integer :: n,m,sum
    sum = n+m
    end subroutine FSum

I create an IVF static librarry project Lib1F, set the runtime library->Multithread DLL (/libs:dll /threads) to compatible with the c++ project.

The c++ project contains an simple MyMain.cpp to test the mixed program

extern "C" 	void FSum(int *n, int *m, int *sum);
int main() {
	int n,m,sum;
n = 1; m = 2; 
	FSum(&n,&m,&sum);}

I set the Linker->General->Additional Libraries Directories as the library output folder of the Fortran project Lib1F, and add the the Lib1F.lib to the Linker->Input->Additional Dependencies. 

The c++ projects always produce error:

1>------ Build started: Project: C++ (Intel C++ 14.0), Configuration: Release Win32 ------
1>ipo : warning #11021: unresolved _FSum
1>          Referenced in ipo_8272obj3.obj
1>ipo : error #11023: Not all components required for linking are present on command line
1>  xilink: executing 'link'
1>ipo_8272obj3.obj : error LNK2019: unresolved external symbol _FSum referenced in function _main

I am suing VS2012,Intel® C++ Composer XE 2013 SP1 Update 3,Intel(R) Visual Fortran Composer XE 2013 SP1 Update 3

The test projects are attached. Any comments are appreciated. 

 

 

0 Kudos
2 Replies
haijunwu
Beginner
85 Views

I figure out the subroutine name declared in the c main program should be in upper case.

It works in this form:

extern "C" void FSUM(int *n, int *m, int *sum);

Is it the cause of the problem?

 

TimP
Black Belt
85 Views

Yes, without use iso_c_binding or equivalent legacy directives ifort windows link symbols default to upper case. It's covered in the help files.

Reply