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

Unresolved C external

mhovers
Beginner
2,573 Views

OK, I went back to basics:

IVF code:

program fortran_c_test

implicit none

interface

subroutine c_code_test(index,foo)

!DEC$ ATTRIBUTES C, ALIAS:'_c_code_test' :: c_code_test

integer index

real(8) foo

end subroutine c_code_test

end interface

integer index

real(8) foo

index = 3

call c_code_test(index,foo)

write(*,*) foo

stop

end

MVS C++(C) code

#include

void c_code_test(index,foo)

int index;

double *foo;

{

*foo = 3.21 * index;

}

This is compiled and put into: C:mhoversfortran_c_testDebugc_code_dir.lib

In Project->Linker->Input->Additional Dependencies I have c_code_dir.lib

In Project->Linker->General->Additional Library Directories I have

C:mhoversfortran_c_testDebug

In Tools->Options->Intel Fortran->General->Libraries I have

C:mhoversfortran_c_testDebug

When I build fortran_c_test I get:

error LINK2019: unresolved external symbol _c_code_test referenced in function _MAIN__

Have I screwed up the INTERFACE or what?

0 Kudos
26 Replies
mhovers
Beginner
670 Views

To answer my own question I have found that if I put

!DEC$ ATTRIBUTES NO_ARG_CHECK :: val

In the interface block in the fortran code I can pass the allocated memory and use it in the C code.

I am just not sure if this is a lucky guess or actually the correct thing to do?

thanks,

0 Kudos
Steven_L_Intel1
Employee
670 Views
No, the correct thing to do is change the interface block to say:

COMPLEX(8), DIMENSION(*) :: val

since val is an array. But you'll need to properly index the val array in the C code (your example does not use it.)
0 Kudos
mhovers
Beginner
670 Views

I am trying this from scratch again. I have my fortran project built, but when I right click on the executable, the popup does not have Project Dependencies and Project Build Order, as it does in my old project? What do I have to do to get access to "Dependencies"?

0 Kudos
Steven_L_Intel1
Employee
670 Views
You have two projects in the same solution? You're actually right clicking on the project and not something else? What is in the menu?
0 Kudos
lochbaj
Beginner
670 Views

Good Morning!

Thank you for the posibility to write here my question!

I have a quite big source which is containes one c++ and one fortran project in one solution. Till this time i use Visual studio c++ 6 with compaq visual fortran6 and there was no any program with the link... the fortran part is dynamic linked.

But now,i would like to change to visual studio 2005 and intel fortran 10, buttill this time i had no success. The building of the two projectis running without any error message, but at linker i get the next message every time when a fortran routin is called from the c++ project:

Styps2000b.obj : error LNK2019: unresolved external symbol _STYP2000B@68 referenced in function "protected: void __thiscall CStyps2000b::OnOpti3Calc(void)" (?OnOpti3Calc@CStyps2000b@@IAEXXZ)

may I ask you to tell me if you have any idea how to solve this problem!

Thanks in advance for your help!

0 Kudos
mhovers
Beginner
670 Views

I just realized that I have to create the master project first, then when creating the projects that it will depend on it askes if the new project will be part of a new or existing solution, after clicking existing solution, it worked.

thanks,

0 Kudos
Reply