Fortran プログラムから C++ 関数を呼び出す必要があります。私は Visual Studio 2010 を使用しています。この本http://www.amazon.com/Guide-Fortran-Programming-Walter-Brainerd/dp/1848825420の 2003 ISO C バインディングに関する関連する章を読みました。219ページの簡単な例をコンパイルして実行しようとしましたが(以下にコピーしました)、「エラーLNK2019:関数_MAIN__で参照されている未解決の外部シンボル_c」と表示されます。これらは私が従った手順です。
1) Fortran のメイン プログラムとモジュールを使用して Fortran プロジェクトを作成し、それを "スタートアップ プロジェクト" として設定しました。
2)「スタティック ライブラリ」タイプの C++ プロジェクトを作成しました。
3)ここで説明されているように、$(IFORT_COMPILERvv)\compiler\lib\ia32を追加しましたhttp://software.intel.com/en-us/articles/configuring-visual-studio-for-mixed-language-applications
コンパイルすると、そのエラーが発生します。Call C 行にコメントを付けると、完全に実行されるため、C 関数が見つからないだけです。なにか提案を?前もって感謝します。C および Fortran コードは次のとおりです。
module type_def
use, intrinsic :: iso_c_binding
implicit none
private
type, public, bind(c) :: t_type
integer(kind=c_int) :: count
real(kind=c_float) :: data
end type t_type
end module type_def
program fortran_calls_c
use type_def
use, intrinsic :: iso_c_binding
implicit none
type(t_type) :: t
real(kind=c_float) :: x, y
integer(kind=c_int), dimension(0:1, 0:2) :: a
interface
subroutine c(tp, arr, a, b, m) bind(c)
import :: c_float, c_int, c_char, t_type
type(t_type) :: tp
integer(kind=c_int), dimension(0:1, 0:2) :: arr
real(kind=c_float) :: a, b
character(kind=c_char), dimension(*) :: m
end subroutine c
end interface
t = t_type(count=99, data=9.9)
x = 1.1
a = reshape([1, 2, 3, 4, 5, 6], shape(a))
call c(t, a, x, y, "doubling x" // c_null_char)
print *, x, y
print *, t
print *, a
end program fortran_calls_c
#include "stdafx.h"
//#include <iostream>
#include <fstream>
typedef struct {int amount; float value;} newtype;
void c(newtype *nt, int arr[3][2], float *a, float *b, char msg[])
{
printf (" %d %f\n", nt->amount, nt->value);
printf (" %d %d %d\n", arr[0][1], arr[1][0], arr[1][1]);
printf (" %s\n", msg);
*b = 2*(*a);
}