C++和Fortran混合编程时cpp文件调用数学函数的问题

类别:编程语言 点击:0 评论:0 推荐:

------------------------------file:a.cpp-------------
#include <iostream.h>
#include <math.h>
extern "C"
{
 void _stdcall TESTA(int *);
}
void main()
{
    double  a = sin(1.00);
    cout<<"a="<<a;
    int ii=1;
    TESTA(&ii);
}

------------------------------file:b.f-------------
SUBROUTINE TESTA(IA)
WRITE(*,*) "IA=", IA
RETURN
END

编译提示错误:
Linking...
dfor.lib(matherr.obj) : error LNK2005: __matherr already defined in LIBCD.lib(matherr.obj)
LINK : warning LNK4098: defaultlib "libc.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/StaggeredGrid.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

经过分析发现是因为在main函数里面调用了sin数学函数,解决的方法是添加文件头:
#pragma comment (lib, "dfor")

本文地址:http://com.8s8s.com/it/it22544.htm