PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

can't read arguments using getarg()

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
nov



Joined: 11 Apr 2006
Posts: 3

PostPosted: Tue Apr 11, 2006 5:07 pm    Post subject: can't read arguments using getarg() Reply with quote

Hi,

I am trying to compile some Fortran code. The compiling options I used are:

FC=pgf90
LD=pgf90
FFLAGS= -c -byteswapio -DLinux -O
LDFLAGS = -lg2c
LDOPTIONS =
LINKFLAGS = -lg2c


In the Fortran code, there are some places call iargc() and getarg(). But the program seems couldn't read the arguments from the command line such as:

*.exe input.file1 input.file2

When I tried to print out the value of iargc(), it gave me –1.

Then I tried to write some Fortran code very simple which also calls those functions. And it worked fine until I added -lg2c when compiling. So I guess it’s –lg2c gave me trouble, and I tried to delete -lg2c in my Makefile. However it ended up with giving me lots of undefined reference error to some Gempak library which was compiled by gcc and g77.

Any suggestions on how to fix it?

Thanks
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6208
Location: The Portland Group Inc.

PostPosted: Tue Apr 11, 2006 7:57 pm    Post subject: Reply with quote

Hi nov,

The easy solution is to use the PGI flag "-g77libs" instead of "-lg2c". "-g77libs" includes either -lg2c or -lf2c depending upon your system, but does so after the PGI runtime libraries. This causes the linker to use the PGI instead of the GNU versions of these routines.

- Mat
Back to top
View user's profile
nov



Joined: 11 Apr 2006
Posts: 3

PostPosted: Tue Apr 11, 2006 9:32 pm    Post subject: Hi Mat, Reply with quote

It works! Thanks, Mat!

But I still don't quite understand why –lg2c didn’t work?

Also I am wondering if there is a good source of general information about compiling and linking? Every time when I try to compile codes from other people, I get puzzled quite easily.

Nov
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6208
Location: The Portland Group Inc.

PostPosted: Tue Apr 11, 2006 10:45 pm    Post subject: Reply with quote

Hi nov,

When different libraries contain the same symbol name, the linker only uses the first symbol it finds. When you use "-lg2c", the g2c library is put in front of the PGI fortran runtime library, and the GNU version of these functions are used. When using "-g77libs", the g2c library is added after the PGI runtime and the PGI version is used.

Off-hand I don't know of a good source for general information. Maybe someone else does? The PGI user's guide will give you a good understanding of the various optimization and flags, but doesn't sound like what your looking for.

- Mat
Back to top
View user's profile
nov



Joined: 11 Apr 2006
Posts: 3

PostPosted: Tue Apr 11, 2006 11:16 pm    Post subject: Reply with quote

Hi Mat,

This is much clear to me now. Thanks!

Nov
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group