- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
On Linux OS:
I see that COMMAND_ARGUMENT_COUNT and functions like that don't work when the main program is in C. My guess is that when -nofor-main option is used, the Fortran runtime library needs to be specifically included. Below is an example.
Main C program:-
#include <stdio.h> extern void ForMethod(); int main() { ForMethod(); return 0; }
The Fortran subroutine is:-
Module OM Use ISO_C_BINDING Implicit None Contains Subroutine ForMethod() Bind(C,Name='ForMethod') Integer :: nArg, mArg nArg = COMMAND_ARGUMENT_COUNT() Write(*,*) nArg mArg = NARGS() Write(*,*) mArg End Subroutine ForMethod End Module OM
The compile and link steps are:-
icc -c main.c
ifort -c ForSub.f90
ifort -nofor-main -o test main.o ForSub.o
Running /test something will return nArg = -1 and mArg = 0
On Windows (and without using -nofor-main), the values are 1 and 2.
Abhi
p.s. if I use icc to link then I will get (as expected) undefined symbols for for_write_seq_lis (which is, I believe, due to the write statement.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you declare "int main()" instead of "int main(int argc, char *argv[])", even your C main program has no access to argc and argv[].
Just as the C start-up code has responsibility to put values into argc and argv and call the user's main(), and do other initial setup tasks, so does the Fortran start-up code. If you use -nofor-main, the Fortran start-up code does not get called, so COMMAND_ARGUMENT_COUNT will be undefined. Similarly for related functions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
-nofor-main isn't needed on Windows. You do have to link with the ifort run-time libraries. On Linux that doesn't happen automatically the way it does on Windows.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve
Thanks for your response.
>>> nofor-main isn't needed on Windows. You do have to link with the ifort run-time libraries. On Linux that doesn't happen automatically the way it does on Windows.
Agreed (as acknowledged in my post) on three statements. What I am looking for is "how" do so ? That is how to link with ifort run-time-libraries === what is the command line going to looking.... probably a dumb question. I am wondering if it would be something like:
ifort -nofor-main -lLIBRARYNAME -o test ......
Abhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In other words, what is the name of the fortran runtime library that should be linked.
Abhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I see that the following (explicit setting of fortran run-time environment) works:-
#include <stdio.h> extern void ForMethod(); extern void for_rtl_init_(int *, char **); extern int for_rtl_finish_( ); int main(int argc, char ** argv) { int io_status; for_rtl_init_ (&argc, argv); ForMethod(); int for_rtl_finish_( ); io_status = for_rtl_finish_( ); return 0; }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hmm - the Intel documentation used to tell you how to do this, but I am having difficulty finding it now. Generally the recommendation is to use the ifort command to do the linking.
Yes, calling for_rtl_init_ and for_rtl_finish_ is often needed on Linux when the main program is not Fortran.
![](/skins/images/C4F7392A5C68ACA60290C9576F107044/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page