---
title: Fortran和C/C++混合编程
description: 为了保证链接成功，需要在C代码中为混合编程中进行交换信息的全局变量和函数名后缀“_”或者使用编译选项-fno-underscoring，否则会出现链接报错。
url: "https://www.hikunpeng.com/document/detail/zh/kunpenggrf/codeprtr/kunpengtaishanporting_12_0111.html"
---

# Fortran和C/C++混合编程

为了保证链接成功，需要在C代码中为混合编程中进行交换信息的全局变量和函数名后缀“_”或者使用编译选项-fno-underscoring，否则会出现链接报错。

代码实例：

```
Fortran主程序：
program test
external ctest
ii=20
x=200.0
call ctest(ii,x) //调用C函数接口
end
C代码：
void ctest_(int *ii,float *x) {
//实现
}
```
