PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

undefined references & etc
Goto page 1, 2  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
acorreia



Joined: 19 Apr 2005
Posts: 14

PostPosted: Fri Jun 10, 2005 12:58 pm    Post subject: undefined references & etc Reply with quote

Hello,

I'm a newbie trying to compile a fairly complicated code under Fedora Core 3 using pgi 6.0-2 set of compilers. Part of the code was compiled with gcc, and part with pgf90. At first all compiling went smoothly, but then the linking with pgf90 did not pass:

Code:

/usr/pgi/linux86/6.0/bin/pgf90  -g77libs <many object files> -L/MODIS/Mapi/STORE/shared_lib/mapi/mapi2.3.4/lib -lmapi -L/MODIS/TOOLKIT/lib/linux -lPGSTK -lm -L/MODIS/TOOLKIT/hdfeos/lib/linux -lhdfeos -L/MODIS/TOOLKIT/hdf5/linux/hdf5-1.6.4/lib -lhdf5shared  -L/MODIS/TOOLKIT/hdf/linux/HDF4.2r1/lib -lmfhdf -ldf -ljpeg -lz -o MOD_PR04_05.exe -v

/usr/bin/ld /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc/i386-redhat-linux/3.4.3/crtbegin.o /usr/pgi/linux86/6.0/lib/f90main.o -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 <many object files> -L/MODIS/Mapi/STORE/shared_lib/mapi/mapi2.3.4/lib -L/MODIS/TOOLKIT/lib/linux -L/MODIS/TOOLKIT/hdfeos/lib/linux -L/MODIS/TOOLKIT/hdf5/linux/hdf5-1.6.4/lib -L/MODIS/TOOLKIT/hdf/linux/HDF4.2r1/lib -L/usr/pgi/linux86/6.0/lib -L/usr/lib -L/usr/lib/gcc/i386-redhat-linux/3.4.3 -L/usr/lib/gcc/i386-redhat-linux/3.4.3 -rpath /usr/pgi/linux86/6.0/lib -lmapi -lPGSTK -lm -lhdfeos -lhdf5shared -lmfhdf -ldf -ljpeg -lz -lpgf90 -lpgf90_rpm1 -lpgf902 -lpgf90rtl -lpgftnrtl -lg2c -lc -lnspgc -lpgc -lm -lgcc -lc -lgcc /usr/lib/gcc/i386-redhat-linux/3.4.3/crtend.o /usr/lib/crtn.o

/usr/pgi/linux86/6.0/lib/f90main.o(.text+0x77): In function `main':
: undefined reference to `MAIN_'
MOD_PR04_PR05_V2.o(.text+0x1b3): In function `MAIN__':
: undefined reference to `pgs_pc_getreference__'
MOD_PR04_PR05_V2.o(.text+0x21b): In function `MAIN__':
: undefined reference to `pgs_pc_getreference__'
MOD_PR04_PR05_V2.o(.text+0x909): In function `MAIN__':
: undefined reference to `pgs_met_getpcattr_s__'

<many other undefined references>


I did manage to get rid of the several undefined references in the end. They were the consequence of a second underscore added by gcc during compiling, so I recompiled the object files with a -fno-second-underscore flag. Then only the first undefined reference remained:
Code:
/usr/pgi/linux86/6.0/lib/f90main.o(.text+0x77): In function `main':
: undefined reference to `MAIN_'


Searching this forum, I believe I found a solution to this issue by adding -Mnomain just after -g77libs in the linking line. But then I get another error:
Code:
/usr/lib/crt1.o(.text+0x18): In function `_start':
: undefined reference to `main'
pgf90-Fatal-linker completed with exit code 1


I have some questions, maybe a little too simplistic for this forum, but anyway:

1) is it ok to have these errors pointing only to "system" files? I mean, after I solved the issue with the files in the code I am compiling, I find a bit odd to have the compiler complaining about the f90main.o and crt1.o files...

2) is it ok to solve the "undefined reference to `MAIN_'" issue by using that -Mnomain flag? Isn't it going to cause other problems ahead like the problem in (3)?

3) any ideas on how to solve the last "undefined reference to `main' in file crt1.o?

Any inputs on these issues would be really appreciated.
Thanks,
Alex
Back to top
View user's profile
mkcolg



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

PostPosted: Fri Jun 10, 2005 3:48 pm    Post subject: Reply with quote

Hi Alex,

You've most likely compiled your main Fortran program with gcc which in turn uses g77. g77 will use two underscores for MAIN even with the "-fno-second-underscore" option.

Example:
Code:
%g77 -c hello.f -fno-second-underscore
% nm hello.o
                 U do_lio
                 U e_wsle
0000000000000000 d __g77_cilist_0.0
0000000000000000 T MAIN__
                 U s_stop
                 U s_wsle


Since pgf90 only expects one underscore, this the is reason your getting the undefined reference to "MAIN_". Compiling the main fortran program as well as your other fortran code with pgf90 (or pgcc) instead of gcc should remove this error as well as give you a performance boost.

The "-Mnomain" flag is used when your using a C main program but linking with pgf90/pgf77.

Hope this helps,

Mat


Last edited by mkcolg on Wed Jun 15, 2005 12:38 pm; edited 1 time in total
Back to top
View user's profile
acorreia



Joined: 19 Apr 2005
Posts: 14

PostPosted: Wed Jun 15, 2005 12:01 pm    Post subject: Reply with quote

Hello Matt,

Tanks for the answer. I recompiled everything using only pgcc and pgf90 with flags -fast and -tp=p7 and I got no severe errors. The linking went ok, using only the -g77libs flag. However, when I try to execute the code, I get this error message:

Code:
$ ./MOD_PR04_05.exe
./MOD_PR04_05.exe: error while loading shared libraries: /usr/pgi/linux86/6.0/lib/libpgc.so: cannot restore segment prot after reloc: Permission denied


Any ideas?

Thanks,
Alex
Back to top
View user's profile
mkcolg



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

PostPosted: Wed Jun 15, 2005 1:22 pm    Post subject: Reply with quote

Hi Alex,

I have not seen this error before but in searching the web for "cannot restore segment prot after reloc", it appears that this is a permissions error generated by SELinux. Unfortunately, I don't know enough about security enhanced linux to tell you how to get it to allow libpgc.so to run. You might be able to find more information at the Fedora Core 3 SELinux FAQ Page.

What happens if you link with "-Bstatic"? This will tell the linker to use the static pgc library instead of the dynamic library.

- Mat
Back to top
View user's profile
acorreia



Joined: 19 Apr 2005
Posts: 14

PostPosted: Wed Jun 15, 2005 1:36 pm    Post subject: Reply with quote

Hi Matt,

I linked with -Bstatic and apparently now the code seems to run ok.
Thank you for your support!

Alex
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
Goto page 1, 2  Next
Page 1 of 2

 
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