<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Fortran subroutine in a c++ code in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958466#M94124</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18px;"&gt;I am trying to call fortran subroutine in a c code. I have Microsoft visual studio and intel visual fortran composer XE.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;When I right click on my fortran file&amp;nbsp;then property. I see Item Type: not in the generation. And I don't see any fortran type file.&lt;/P&gt;

&lt;P&gt;How to successfully compile? The intel c + + compiler is required?&lt;/P&gt;

&lt;P&gt;My error is "error LNK2019: symbole externe non résolu _FACT@4 référencé dans la fonction _main" for the file main.obj&lt;/P&gt;

&lt;P&gt;I used an exemple of microsoft website:&amp;nbsp;&lt;/P&gt;

&lt;PRE style="color: rgb(0, 0, 0); font-size: 13px; line-height: 17px;"&gt;
&lt;CODE&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; File CMAIN.C&amp;nbsp;&amp;nbsp; */

#include &amp;lt;stdio.h&amp;gt;

extern int __stdcall FACT (int n);
extern void __stdcall PYTHAGORAS (float a, float b, float *c);

main()
{
 &amp;nbsp;&amp;nbsp; float c;
 &amp;nbsp;&amp;nbsp; printf("Factorial of 7 is: %d\n", FACT(7));
 &amp;nbsp;&amp;nbsp; PYTHAGORAS (30, 40, &amp;amp;c);
 &amp;nbsp;&amp;nbsp; printf("Hypotenuse if sides 30, 40 is: %f\n", c);
}

C&amp;nbsp;&amp;nbsp;&amp;nbsp; File FORSUBS.FOR
C
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTEGER*4 FUNCTION Fact (n)
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTEGER*4 n [VALUE]
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTEGER*4 i, amt
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amt = 1
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DO i = 1, n
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amt = amt * i
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END DO
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Fact = amt
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END

 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUBROUTINE Pythagoras (a, b, c)
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REAL*4 a [VALUE]
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REAL*4 b [VALUE]
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REAL*4 c [REFERENCE]
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c = SQRT (a * a + b * b)
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END

&lt;/CODE&gt;&lt;SPAN style="font-size: 1em; color: rgb(83, 87, 94); line-height: 1.5;"&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/aa293328(v=vs.60).aspx"&gt;source&lt;/A&gt;&lt;/SPAN&gt;&lt;/PRE&gt;

&lt;P style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;"&gt;Please help me!!&lt;/P&gt;

&lt;P style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;"&gt;Thank you in advance.&lt;/P&gt;

&lt;P style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;"&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jan 2014 16:03:35 GMT</pubDate>
    <dc:creator>benjamin_g_</dc:creator>
    <dc:date>2014-01-14T16:03:35Z</dc:date>
    <item>
      <title>Fortran subroutine in a c++ code</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958466#M94124</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18px;"&gt;I am trying to call fortran subroutine in a c code. I have Microsoft visual studio and intel visual fortran composer XE.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;When I right click on my fortran file&amp;nbsp;then property. I see Item Type: not in the generation. And I don't see any fortran type file.&lt;/P&gt;

&lt;P&gt;How to successfully compile? The intel c + + compiler is required?&lt;/P&gt;

&lt;P&gt;My error is "error LNK2019: symbole externe non résolu _FACT@4 référencé dans la fonction _main" for the file main.obj&lt;/P&gt;

&lt;P&gt;I used an exemple of microsoft website:&amp;nbsp;&lt;/P&gt;

&lt;PRE style="color: rgb(0, 0, 0); font-size: 13px; line-height: 17px;"&gt;
&lt;CODE&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; File CMAIN.C&amp;nbsp;&amp;nbsp; */

#include &amp;lt;stdio.h&amp;gt;

extern int __stdcall FACT (int n);
extern void __stdcall PYTHAGORAS (float a, float b, float *c);

main()
{
 &amp;nbsp;&amp;nbsp; float c;
 &amp;nbsp;&amp;nbsp; printf("Factorial of 7 is: %d\n", FACT(7));
 &amp;nbsp;&amp;nbsp; PYTHAGORAS (30, 40, &amp;amp;c);
 &amp;nbsp;&amp;nbsp; printf("Hypotenuse if sides 30, 40 is: %f\n", c);
}

C&amp;nbsp;&amp;nbsp;&amp;nbsp; File FORSUBS.FOR
C
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTEGER*4 FUNCTION Fact (n)
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTEGER*4 n [VALUE]
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INTEGER*4 i, amt
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amt = 1
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DO i = 1, n
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amt = amt * i
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END DO
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Fact = amt
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END

 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUBROUTINE Pythagoras (a, b, c)
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REAL*4 a [VALUE]
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REAL*4 b [VALUE]
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; REAL*4 c [REFERENCE]
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; c = SQRT (a * a + b * b)
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END

&lt;/CODE&gt;&lt;SPAN style="font-size: 1em; color: rgb(83, 87, 94); line-height: 1.5;"&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/aa293328(v=vs.60).aspx"&gt;source&lt;/A&gt;&lt;/SPAN&gt;&lt;/PRE&gt;

&lt;P style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;"&gt;Please help me!!&lt;/P&gt;

&lt;P style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;"&gt;Thank you in advance.&lt;/P&gt;

&lt;P style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2014 16:03:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958466#M94124</guid>
      <dc:creator>benjamin_g_</dc:creator>
      <dc:date>2014-01-14T16:03:35Z</dc:date>
    </item>
    <item>
      <title>You don't require Intel C++,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958467#M94125</link>
      <description>&lt;P&gt;You don't require Intel C++, but you must match the calling ABI. &amp;nbsp;stdcall was obsoleted over a decade ago, but (for 32-bit mode), ifort option /iface:cvf provides some compatibility (should work if your build procedure assumed the DEC or Compaq Windows Fortran). &amp;nbsp;&lt;/P&gt;

&lt;P&gt;The usual reason for /iface:cvf is for compatibility with win32 ABI calls; if you don't use those, the default ABI of MSVC and ifort would be preferable. &amp;nbsp;You appear to have observed the ifort default of uppercase symbols without underscoring, so it looks like your build may follow CVF convention.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2014 17:26:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958467#M94125</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2014-01-14T17:26:00Z</dc:date>
    </item>
    <item>
      <title>If you want to use the 32-bit</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958468#M94126</link>
      <description>&lt;P&gt;If you want to use the 32-bit Stdcall convention to call Fortran subroutines from C, compile the Fortran sources with the /iface:cvf option.&lt;/P&gt;

&lt;P&gt;There is an entire chapter on mixed language programming in the Intel Fortran user manual.&lt;/P&gt;

&lt;P&gt;[plain]ifort /MD /c /iface:cvf fsub.f&lt;/P&gt;

&lt;P&gt;cl /MD cmain.c fsub.obj&lt;/P&gt;

&lt;P&gt;[/plain]&lt;/P&gt;

&lt;P&gt;You may use the Microsoft Visual C compiler or the Intel C compiler for the C part of your code.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2014 17:29:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958468#M94126</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2014-01-14T17:29:00Z</dc:date>
    </item>
    <item>
      <title>You need to create separate</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958469#M94127</link>
      <description>&lt;P&gt;You need to create separate projects for your C and Fortran files. It's OK to use MSVC, it doesn't need to be Intel C++. So an MS C/C++ project and an Intel Visual Fortran project. For this simple C/Fortran example, it's easier to start from empty projects.&lt;/P&gt;

&lt;P&gt;There is more information in the Fortran Users Guide, see the section on Mixed Language Programming / Platform Specifics / Building Intel(R) Fortran/C Mixed-Language Programs (Windows* OS)&lt;/P&gt;

&lt;P&gt;With the Intel Visual&amp;nbsp;Fortran Compiler, it's simpler not to declare the Fortran functions as __stdcall on the C side. If you use the Fortran project for linking, then both C and Fortran libraries should be linked in automatically.&lt;/P&gt;

&lt;P&gt;You can also practice by building the little MS example you quote from the command line. You can then easily run Dumpbin/symbols on the object files, to make sure that the symbols match.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2014 19:00:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958469#M94127</guid>
      <dc:creator>Martyn_C_Intel</dc:creator>
      <dc:date>2014-01-14T19:00:45Z</dc:date>
    </item>
    <item>
      <title>See also the "C_calls_Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958470#M94128</link>
      <description>&lt;P&gt;See also the "C_calls_Fortran" solution from MixedLanguage.zip in the Samples/en_US/Fortran directory in the product.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2014 20:57:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958470#M94128</guid>
      <dc:creator>Martyn_C_Intel</dc:creator>
      <dc:date>2014-01-14T20:57:19Z</dc:date>
    </item>
    <item>
      <title>Thank you to everyone.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958471#M94129</link>
      <description>&lt;P&gt;Thank you to everyone.&lt;/P&gt;

&lt;P&gt;The goal is to run a program made of fortran and c++ file. The program already run but in another OS ubuntu and another IDE eclipse.&lt;/P&gt;

&lt;P&gt;I'll try with the included file in the Fortran directory. And I come back to you if I succeed or I stuck again&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2014 14:12:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Fortran-subroutine-in-a-c-code/m-p/958471#M94129</guid>
      <dc:creator>benjamin_g_</dc:creator>
      <dc:date>2014-01-15T14:12:22Z</dc:date>
    </item>
  </channel>
</rss>

