Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

problems of mixed program with fortran

haijunwu
Beginner
326 Views

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
326 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?

 

0 Kudos
TimP
Honored Contributor III
326 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.

0 Kudos
Reply