在Linux / Mac上但不在Windows中编译 - 使用C,C ++和Fortran的C ++

时间:2015-02-13 13:28:35

标签: c++ c linux windows fortran

这是一个简单的主要C ++程序,里面有C,C ++和Fortran 函数。

只能在Linux上编译代码,但不能在Windows上编译

代码在Linux上按预期运行,但在Windows中程序编译正常但冻结时显示简单的Fortran输出。

你能告诉我可能导致这个错误的原因吗?

每个C,C ++和Fortran函数只是将变量a和b设置为特定值:

ffunction.f:

  subroutine ffunction(a,b)
  a=3.0
  b=4.0
  end

cfunction1.c:

void cfunction1(float *a, float *b) {
    *a=7.0;
    *b=8.0;
}

cppfunction1.c:

void cppfunction1(float *a, float *b) {
    *a=7.0;
    *b=8.0;
 }

cppprogram.C:

#include <iostream>
using namespace std;

extern "C" {
  void ffunction_(float *a, float *b);
}

extern "C" {
  void cfunction1(float *a, float *b);
}

void cppfunction1(float *a, float *b);

int main() {
  float a=1.0, b=2.0;

  cout << "Before running Fortran function:" << endl;
  cout << "a=" << a << endl;
  cout << "b=" << b << endl;

  ffunction_(&a,&b);

  cout << "After running Fortran function:" << endl;
  cout << "a=" << a << endl;
  cout << "b=" << b << endl;

  cout << "Before running C function:" << endl;
  cout << "a=" << a << endl;
  cout << "b=" << b << endl;

  cfunction1(&a,&b);

  cout << "After running C function:" << endl;
  cout << "a=" << a << endl;
  cout << "b=" << b << endl;

  cout << "Before running C++ function:" << endl;
  cout << "a=" << a << endl;
  cout << "b=" << b << endl;

  cppfunction1(&a,&b);

  cout << "After running C++ function:" << endl;
  cout << "a=" << a << endl;
  cout << "b=" << b << endl;

  return 0;
}

0 个答案:

没有答案