473,660 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to call Fortran moules from C++?

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.wi n [Build Error] [QQPlot.exe] Error 1

What am I doing wrong?

Apr 14 '06 #1
11 2966
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.
Apr 14 '06 #2
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.

Apr 14 '06 #3

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.wi n [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.

Apr 14 '06 #4
Thanks. I did. Here is the new source:
#include <windows.h>
#include <conio.h>
extern "C" void qqopen(int*,int *,char*);
extern "C" void qqpoint(int*,in t*);
extern "C" void qqline(int*,int *);
extern "C" 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();

}
But now I get messages like this:

12 F:\C\Dev-Cpp\bin\main.cp p expected primary-expression before ','
token

And I get this message (as before):

12:16 F:\C\Dev-Cpp\bin\main.cp p [Warning] character constant too long
for its type

May that cause any problems?

Apr 15 '06 #5
Thanks. Seems to be part of Markus Schroders answer. So I answered
there.

Apr 15 '06 #6
Your name sounds German. So if I'm right you may answer in German also
- as you wish.

Apr 15 '06 #7
Thanks. At the moment I just have a C++ specific question to this
problem. As soon as it is answered I will create a new thread there.
If I have problems any longer.

Apr 15 '06 #8
Thanks. At the moment I just have a C++ specific question to this
problem. As soon as it is answered I will create a new thread there.
If I have problems any longer.

Apr 15 '06 #9
@red floyd: Sorry, but I'm not able to answer to your answer directly.
I tried, but it was shown at the wrong place. So please excuse that.
Here's my answer:

Thanks. At the moment I just have a C++ specific question to this
problem. As soon as it is answered I will create a new thread there.
If I have problems any longer.

Apr 15 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
3394
by: Carl | last post by:
"Nine Language Performance Round-up: Benchmarking Math & File I/O" http://www.osnews.com/story.php?news_id=5602 I think this is an unfair comparison! I wouldn't dream of developing a numerical application in Python without using prebuilt numerical libraries and data objects such as dictionaries and lists. I have been experimenting with numerical algorithms in Python with a heavy use of the Numeric module. My experience is that Python...
15
2089
by: Nick Coghlan | last post by:
Thought some folks here might find this one interesting. No great revelations, just a fairly sensible piece on writing readable code :) The whole article: http://www.acmqueue.com/modules.php?name=Content&pa=showpage&pid=271&page=1 The section specifically on white space: http://www.acmqueue.com/modules.php?name=Content&pa=showpage&pid=271&page=3 Cheers,
1
2682
by: Bob Helber | last post by:
I've got a perl script with a system command, within a for loop, that calls a FORTRAN program. For one of the iterations of the for loop the FORTRAN program quits with an error due to bad input. This then exits the for loop and does not continue the loop, which I would like it to do, even if the FORTRAN program crashes. How can I "catch" this error and continue the loop. Do I have to fix the FORTRAN program to exit more cleanly? ...
3
2875
by: Dennis Kernighan | last post by:
On Microsoft's pages there is an example of making Fortran call from C++, see http://tinyurl.com/2692f . If I put C code in the test.c and Fortran code in FORSUBS.FOR and press F5 in C++, I get following errors: ------- error statement -------- fortrantester error LNK2019: unresolved external symbol "void __stdcall PYTHAGORAS(float,float,float *)" (?PYTHAGORAS@@YGXMMPAM@Z) referenced
4
3306
by: Cyde Weys | last post by:
I'm currently working on converting a simulator program from Visual Basic 6.0 to Visual C++ .NET. I've figured out most of the stuff, but there's still one thing I haven't gotten to and I've never really had to deal with it before. I'm programming a front-end for what is a compiled Fortran program. The VB source does the following to call the Fortran: 'Defines the subroutine. Declare Sub Cycle_DW Lib "cycdw.dll" Alias "CYCDW" (ByRef...
81
7294
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there be any advantage in having strcat and strcpy return a pointer to the "end" of the destination string rather than returning a
21
2753
by: Cottonwood | last post by:
I want to call a C module from a Fortran program. Whatever I tried - the linker could not find the C module. I know about the leading underscore and switched even that off. I abstracted everything possible. When I replace the C module by a Fortran subroutine linking works. Here the Fortran subroutine that replaced the C module for testing: subroutine qqcprint return end
1
2691
by: hanhaner | last post by:
hey, there I am new to Python and C++. Now I am trying to call some fortran subroutines in python code. I was told the good way is to write a c++ interface. I am not quite sure how to do it. For example, in the following case: I want to call fortran subroutine "realadd" from python , i wrote the following codes, it seems it far from working. Is there anyone can help me out? thanks a lot!
8
2081
by: Luna Moon | last post by:
Hi all, As a C/C++ programmer, there are a few reasons to use Fortran: (1) Fortran is very similar to Matlab and easy to port; (2) Fortran has support of complex numbers and vectorized numbers and the operations in Fortran are naturally element-wise, operating on a whole vector. (3) There are many scientific codes are in Fortran.
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8754
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.