Home > Archive > Fortran > April 2006 > How to call Fortran moules from C++?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to call Fortran moules from C++?
|
|
| Cottonwood 2006-04-14, 7:05 pm |
| 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?
| |
| red floyd 2006-04-14, 7:05 pm |
| 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.
| |
| Markus Schoder 2006-04-14, 7:05 pm |
| 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.
| |
| bubbleman 2006-04-14, 7:05 pm |
|
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.
| |
| Cottonwood 2006-04-15, 8:02 am |
| 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*,int*);
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.cpp expected primary-expression before ','
token
And I get this message (as before):
12:16 F:\C\Dev-Cpp\bin\main.cpp [Warning] character constant too long
for its type
May that cause any problems?
| |
| Cottonwood 2006-04-15, 8:02 am |
| Thanks. Seems to be part of Markus Schroders answer. So I answered
there.
| |
| Cottonwood 2006-04-15, 8:02 am |
| Your name sounds German. So if I'm right you may answer in German also
- as you wish.
| |
| Cottonwood 2006-04-15, 8:02 am |
| 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.
| |
| Cottonwood 2006-04-15, 8:02 am |
| 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.
| |
| Cottonwood 2006-04-15, 8:02 am |
| @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.
| |
| Richard Herring 2006-04-25, 7:10 pm |
| In message <1145097111.139119.140820@j33g2000cwa.googlegroups.com>,
Cottonwood <google@c-d-j.de> writes
>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*,int*);
>extern "C" void qqline(int*,int*);
>extern "C" void qqclose();
>int main()
>{
>int ix, iy;
>
>ix=1201; iy=1001;
>qqopen(ix*,iy*,'.\\qqtest.bmp'*);
What's that supposed to mean? ITYM 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.cpp expected primary-expression before ','
>token
Not surprising. " qqopen(ix*,iy*,'.\\qqtest.bmp'*) ; " isn't valid C++
syntax.
>
>And I get this message (as before):
>
>12:16 F:\C\Dev-Cpp\bin\main.cpp [Warning] character constant too long
>for its type
In C++, string constants are enclosed in double-quotes.
>
>May that cause any problems?
>
Just a few ;-)
--
Richard Herring
|
|
|
|
|