- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Mixing Fortran and C
Operating System - HP-UX
1753518
Members
5117
Online
108795
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-25-2000 12:28 AM
тАО09-25-2000 12:28 AM
I have a program code mixing Fortran77 and C. I can compile each source file to an o-file using the aCC and Fortran 90 compiler but the linking of the program fails.
Here the code:
>>>>>>>>>> main.c: <<<<<<<<<<
#include
int main(unsigned int argc,char **argv)
{
extern void halloc(void);
extern void hallof(void);
/* c calls fortran: */
hallof();
/* c calls c: */
halloc();
}
void halloc(void){ printf("hallo cn"); }
>>>>>>>>>> help.f: <<<<<<<<<<
subroutine hallof
print *,"HALLO F"
C.....fortran calls c:
call halloc()
return
end
--------------------------------------------
I tried different ways to compile this test-program. Reading the online-manuals I discover the tip to link with "-lisamstub". This has no effect. Here how I tried to compile and link the program:
----------------------------------------------
f90 -c help.f
aCC -c main.o
aCC -o test main.o help.f -lisamstub
----------------------------------------------
Can anybody help me solving this problem?
Thanking you in advance.
Here the code:
>>>>>>>>>> main.c: <<<<<<<<<<
#include
int main(unsigned int argc,char **argv)
{
extern void halloc(void);
extern void hallof(void);
/* c calls fortran: */
hallof();
/* c calls c: */
halloc();
}
void halloc(void){ printf("hallo cn"); }
>>>>>>>>>> help.f: <<<<<<<<<<
subroutine hallof
print *,"HALLO F"
C.....fortran calls c:
call halloc()
return
end
--------------------------------------------
I tried different ways to compile this test-program. Reading the online-manuals I discover the tip to link with "-lisamstub". This has no effect. Here how I tried to compile and link the program:
----------------------------------------------
f90 -c help.f
aCC -c main.o
aCC -o test main.o help.f -lisamstub
----------------------------------------------
Can anybody help me solving this problem?
Thanking you in advance.
Solved! Go to Solution.
- Tags:
- f90
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-25-2000 02:02 AM
тАО09-25-2000 02:02 AM
Re: Mixing Fortran and C
You havent specificed the error you get when trying to link it. Can you ?
Meanwhile you could try;
aCC -o test main.o help.f -l:isamstub
Im from Palmerston North, New Zealand, but somehow ended up in London...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-25-2000 02:31 AM
тАО09-25-2000 02:31 AM
Solution
The problem with is that you've switched from using a C compiler (cc) to a C++ one (aCC). If you have no genuine C++ code it is probably unecessary to switch this compiler since cc is still a fully supported and current product. Your unresolved symbols should vanish by doing this alone. You may need libraries "-lF90 -lcl" in your link line to support the additional f90 runtime functions if your fortran code makes use of it.
The problem is caused by C++ mangling the real function names when it constructs code. By performing an "nm main.o" we can see what ld is really looking for:
halloc__Fv | 68|extern|entry |$CODE$
hallof__Fv | |undef |code |
As you can see, aCC has attached an "_Fv" denoting a (void) argument list. If you wish to use the functions as if they were C, you must 'extern "C"' them.
That is:
<< main.c >>
#include
extern "C" void halloc(void);
extern "C" void hallof(void);
int main(unsigned int argc,char **argv)
{
/* c calls fortran: */
hallof();
/* c calls c: */
halloc();
}
void halloc(void){ printf("hallo cn"); }
$ f90 -c help.f
help.f
external subroutine HALLOF
6 Lines Compiled
$ aCC -c main.c
$ aCC -o test main.o help.o
$ ./test
HALLO F
hallo cnhallo cn$
For more about this, please see the "Mixing C++ with Other Languages" section of the aCC online programmers guide (run "aCC +help").
The problem is caused by C++ mangling the real function names when it constructs code. By performing an "nm main.o" we can see what ld is really looking for:
halloc__Fv | 68|extern|entry |$CODE$
hallof__Fv | |undef |code |
As you can see, aCC has attached an "_Fv" denoting a (void) argument list. If you wish to use the functions as if they were C, you must 'extern "C"' them.
That is:
<< main.c >>
#include
extern "C" void halloc(void);
extern "C" void hallof(void);
int main(unsigned int argc,char **argv)
{
/* c calls fortran: */
hallof();
/* c calls c: */
halloc();
}
void halloc(void){ printf("hallo cn"); }
$ f90 -c help.f
help.f
external subroutine HALLOF
6 Lines Compiled
$ aCC -c main.c
$ aCC -o test main.o help.o
$ ./test
HALLO F
hallo cnhallo cn$
For more about this, please see the "Mixing C++ with Other Languages" section of the aCC online programmers guide (run "aCC +help").
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP