c_cpp Fortran FLTK

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp Fortran FLTK相关的知识,希望对你有一定的参考价值。

@echo off

gfortran -c do_fortran.f90
bash -c 'g++ -o fortran_cb fortran_cb.cxx do_fortran.o `fltk-config --cxxflags --ldflags`'
bash -e ./fortran_cb
subroutine do_fortran ( num )
implicit none
integer :: num
num = num + 1
end
/*
Fortran callback demo (fortran_cb.cxx)

This demo program shows how you can call a Fortran
subroutine in a callback from a FLTK (c++) main program.

Compile and run using:
gfortran -c do_fortran.f90
g++ -o fortran_cb fortran_cb.cxx do_fortran.o `fltk-config --cxxflags --ldflags`
./fortran_cb

do_fortran.f90:
subroutine do_fortran ( num )
implicit none
integer :: num
num = num + 1
end
*/
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Input.H>
extern "C" {
void do_fortran_ (int *);
}
/*
This is the callback function. It calls the Fortran
subroutine and assigns a new value to the input widget.
*/
void button_cb (Fl_Widget *, void *i) {
int my_number;	 // number to increment
char buf[20];
Fl_Input *input = (Fl_Input *)i;	// the input widget
my_number = atoi(input->value());	// get the current value
for (int i=0; i<500; i++) {
do_fortran_(&my_number);	 // increment my_number
}
sprintf (buf,"%d",my_number);
input->value(buf);	 // store the value
}

int main (int argc, char **argv) {
Fl_Window *window = new Fl_Window(200,140);
Fl_Button *button = new Fl_Button(20,20,160,50,"Count (+500)");
Fl_Input *input = new Fl_Input(80,100,60,20,"Value: ");
input->value("0");
window->end();
button->callback(button_cb,input);	// attach the callback
window->show(argc, argv);
return Fl::run();
}
/* end of file */

以上是关于c_cpp Fortran FLTK的主要内容,如果未能解决你的问题,请参考以下文章

找不到 FLTK(缺少:FLTK_INCLUDE_DIR)

FLTK双窗口和FLTK单窗口的区别

根据构建目标,在 fltk-rs 中使用 fltk::osxMenuBar 或 MenuBar

Windows下使用VS2017搭建FLTK开发环境

使用命名空间 fltk 在我的 FLTK 程序中不起作用

FLTK 中的线程