如何从C ++调用Fortran moules? [英] How to call Fortran moules from C++?

查看:100
本文介绍了如何从C ++调用Fortran moules?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从GNU-C ++源代码调用GNU-Fortran库。那是

可能吗?如果是的话,链接程序需要做什么?


我收到一条错误消息,指出无法找到模块MAIN_

图书馆fortran模块在项目中是众所周知的。如果我尝试使用
为项目添加更多Fortran库,Dev-Cpp完全中止




编辑:16: 56

我试着再试一次。因为我无法保存项目,所以我打开了一个新的
。奇怪的是,但现在我在编译时得到了错误消息所以

我必须添加extern void声明。

这里的程序:


#include< windows.h>

#include< conio.h>

extern void qqopen(int,int,char);

extern void qqpoint(int,int);

extern void qqline(int, int);

extern void qqclose();

int main()

{

int ix,iy ;


ix = 1201; iy = 1001;

qqopen(ix,iy,''。\\qqtest.bmp'');

ix = 10; iy = 10;

qqpoint(ix,iy);

ix = 1190; iy = 990;

qqline(ix,iy);

qqclose();

}


现在我得到了链接消息,这意味着库模块找不到
。由于这个原因,我暂时没有收到MAIN_

的消息。但我认为它会回来。这里是modlib的toc:


qqbord.o

qqcircle.o

qqclose.o

qqfill.o

qqline.o

qqopen.o

qqor.o

qqplot.o < br $>
qqpoint.o

qqrandom.o

qqwhite.o


这里有实际的消息:


F:\C\Dev-Cpp \ bin \ main.o函数`main'':

[链接错误] undefined引用

`qqopen(int,int,char)''

[链接器错误]未定义引用

`qqpoint(int,int )''

[链接器错误]未定义引用

`qqline(int,int)''

[链接器错误]未定义引用

`qqclose()''

F:\ C\Dev-Cpp \ bin \ main.o ld返回1退出状态

F:\ C\Dev-Cpp \ Makefile.win [构建错误] [QQPlot.exe]错误1


我做错了什么?

解决方案

Cottonwood写道:

我想从GNU-C ++源代码调用GNU-Fortran库。这有可能吗?如果是的话,该怎么做才能链接该计划?



我做错了什么?




你做错了就是问错了。我怀疑你能否在新闻组中获得更好的帮助gnu.g ++。帮助


你所拥有的是一个关于a的问题特别的实现,不是关于语言本身的问题,所以它不是clc ++中的热门话题。然而,

人超过gnu.g ++。帮助了解g ++的所有内容,应该能够帮助你。


Cottonwood写道:< blockquote class =post_quotes>我想从GNU-C ++源代码调用GNU-Fortran库。这有可能吗?如果是,那么链接程序需要做什么?

我收到一条错误消息,指出无法找到模块MAIN_
具有fortran模块的库在项目。如果我尝试在项目中添加更多的Fortran库,Dev-Cpp就会完全中止。

编辑:16:56

我试过再次测试。因为我无法保存项目,所以我打开了一个新项目。奇怪的是,但现在我在编译时得到了错误消息,所以我必须添加extern void。这个程序:

#include< windows.h>
#include< conio.h>
extern void qqopen(int,int, char);
extern void qqpoint(int,int);
extern void qqline(int,int);
extern void qqclose();



尝试类似


extern" C" void qqopen(int *,int *,char *);


Fortran肯定不会使用C ++名称修改,也不会按值传递

参数。


要成功链接,您可能需要一个Fortran运行时库。他们的

应该是GNU g77包的一部分,通常称为libg2c.a

或类似的。



Cottonwood写道:

我想从GNU-C ++源代码调用GNU-Fortran库。这有可能吗?如果是,那么链接程序需要做什么?

我收到一条错误消息,指出无法找到模块MAIN_
具有fortran模块的库在项目。如果我尝试在项目中添加更多的Fortran库,Dev-Cpp就会完全中止。

编辑:16:56

我试过再次测试。因为我无法保存项目,所以我打开了一个新项目。奇怪的是,但现在我在编译时得到了错误消息,所以我必须添加extern void。这个程序:

#include< windows.h>
#include< conio.h>
extern void qqopen(int,int, char);
extern void qqpoint(int,int);
extern void qqline(int,int);
extern void qqclose();
int main()
{
int ix,iy;

ix = 1201; iy = 1001;
qqopen(ix,iy,''。\\qqtest.bmp'');
ix = 10; iy = 10;
qqpoint(ix,iy) ;
ix = 1190; iy = 990;
qqline(ix,iy);
qqclose();
}
现在我收到链接消息意味着库模块无法找到了。由于这个原因,我暂时没有收到MAIN_
缺失的消息。但我认为它会回来。这里是modlib的toc:

qqbord.o
qqcircle.o
qqclose.o
qqfill.o
qqline.o
qqopen.o
qqor.o
qqplot.o
qqpoint.o
qqrandom.o
qqwhite.o

这里实际消息:

F:\ C\Dev-Cpp \ bin \ main.o在函数`main''中:
[链接器错误]未定义引用
`qqopen(int,int,char)''
[链接器错误]未定义引用
`qqpoint(int,int)''
[链接器错误]未定义引用
`qqline(int,int)''
[链接器错误]未定义引用
`qqclose()''
F:\C\Dev-Cpp \ bin \ main .o ld返回1退出状态
F:\C\Dev-Cpp \ Makefile.win [Build Error] [QQPlot.exe]错误1

我做错了什么?




您的''extern''声明应该是externc空隙"为了避免C ++将要做的名称损坏,Fortran没有。这可能是你问题的一部分。


I want to call a GNU-Fortran-library from a GNU-C++ source. Is that
possible at all? If yes, what is to be done to link the program?

I get an error message that says that the module MAIN_ cannot be found.
The library withe the fortran modules is known in the project. If I try
to add more Fortran libraries to the project the Dev-Cpp aborts
completely.

Edit: 16:56

I tried to test again. Because I couldn''t save the project, I opened a
new one. Strange to say but now I got error messages at compile time so
that I had to add the "extern void" statements.
Here the program:

#include <windows.h>
#include <conio.h>
extern void qqopen(int,int,char);
extern void qqpoint(int,int);
extern void qqline(int,int);
extern void qqclose();
int main()
{
int ix, iy;

ix=1201; iy=1001;
qqopen(ix,iy,''.\\qqtest.bmp'');
ix=10;iy=10;
qqpoint(ix,iy);
ix=1190; iy=990;
qqline(ix,iy);
qqclose();
}

Now I get linkage messages meaning that the library modules couldn''d be
found. From this reason I dont get the message with the missing MAIN_
atthis time. But it will come back I think. Here the toc of the modlib:

qqbord.o
qqcircle.o
qqclose.o
qqfill.o
qqline.o
qqopen.o
qqor.o
qqplot.o
qqpoint.o
qqrandom.o
qqwhite.o

And here the actual messages:

F:\C\Dev-Cpp\bin\main.o In function `main'':
[Linker error] undefined reference to
`qqopen(int, int, char)''
[Linker error] undefined reference to
`qqpoint(int, int)''
[Linker error] undefined reference to
`qqline(int, int)''
[Linker error] undefined reference to
`qqclose()''
F:\C\Dev-Cpp\bin\main.o ld returned 1 exit status
F:\C\Dev-Cpp\Makefile.win [Build Error] [QQPlot.exe] Error 1

What am I doing wrong?

解决方案

Cottonwood wrote:

I want to call a GNU-Fortran-library from a GNU-C++ source. Is that
possible at all? If yes, what is to be done to link the program?

[redacted]

What am I doing wrong?



What you''re doing wrong is asking in the wrong group. I suspect you''d
be able to get a lot better help in the newsgroup gnu.g++.help

What you have is a question about a particular implementation, not about
the lanugage itself, so it''s not topical in c.l.c++. However, the
people over gnu.g++.help know all about g++, and should be able to help you.


Cottonwood wrote:

I want to call a GNU-Fortran-library from a GNU-C++ source. Is that
possible at all? If yes, what is to be done to link the program?

I get an error message that says that the module MAIN_ cannot be found.
The library withe the fortran modules is known in the project. If I try
to add more Fortran libraries to the project the Dev-Cpp aborts
completely.

Edit: 16:56

I tried to test again. Because I couldn''t save the project, I opened a
new one. Strange to say but now I got error messages at compile time so
that I had to add the "extern void" statements.
Here the program:

#include <windows.h>
#include <conio.h>
extern void qqopen(int,int,char);
extern void qqpoint(int,int);
extern void qqline(int,int);
extern void qqclose();



Try something like

extern "C" void qqopen(int*,int*,char*);

Fortran certainly does not use C++ name mangling and does not pass
parameters by value.

To successfully link you probably need a Fortran runtime library. Their
should be one as part of the GNU g77 package normally called libg2c.a
or similar.



Cottonwood wrote:

I want to call a GNU-Fortran-library from a GNU-C++ source. Is that
possible at all? If yes, what is to be done to link the program?

I get an error message that says that the module MAIN_ cannot be found.
The library withe the fortran modules is known in the project. If I try
to add more Fortran libraries to the project the Dev-Cpp aborts
completely.

Edit: 16:56

I tried to test again. Because I couldn''t save the project, I opened a
new one. Strange to say but now I got error messages at compile time so
that I had to add the "extern void" statements.
Here the program:

#include <windows.h>
#include <conio.h>
extern void qqopen(int,int,char);
extern void qqpoint(int,int);
extern void qqline(int,int);
extern void qqclose();
int main()
{
int ix, iy;

ix=1201; iy=1001;
qqopen(ix,iy,''.\\qqtest.bmp'');
ix=10;iy=10;
qqpoint(ix,iy);
ix=1190; iy=990;
qqline(ix,iy);
qqclose();
}

Now I get linkage messages meaning that the library modules couldn''d be
found. From this reason I dont get the message with the missing MAIN_
atthis time. But it will come back I think. Here the toc of the modlib:

qqbord.o
qqcircle.o
qqclose.o
qqfill.o
qqline.o
qqopen.o
qqor.o
qqplot.o
qqpoint.o
qqrandom.o
qqwhite.o

And here the actual messages:

F:\C\Dev-Cpp\bin\main.o In function `main'':
[Linker error] undefined reference to
`qqopen(int, int, char)''
[Linker error] undefined reference to
`qqpoint(int, int)''
[Linker error] undefined reference to
`qqline(int, int)''
[Linker error] undefined reference to
`qqclose()''
F:\C\Dev-Cpp\bin\main.o ld returned 1 exit status
F:\C\Dev-Cpp\Makefile.win [Build Error] [QQPlot.exe] Error 1

What am I doing wrong?



Your ''extern'' declarations should be "extern "c" void" to avoid the
name mangling that C++ will do, that Fortran does not. This is
probably part of your problem.


这篇关于如何从C ++调用Fortran moules?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆