undefined references & etc

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:

/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:

/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:

/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

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:

%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

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:

$ ./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

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

Hi Matt,

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

Alex

Hello,

The problem with the “cannot restore segment prot after reloc” is indeed a SELinux issue. A few days ago a new release of SELinux was distributed and this release is causing problems with shared objects in several kinds of programs everywhere. For instance, all my java applications stopped working returning that same error, from web browser applications to file viewers to pgdbg tool. There is a workaround, by simply issuing ‘#setenforce 0’ at prompt as root, although this may pose some security risk.
The point is that, after solving the problem with SELinux, I did manage to recompile my code withouth the “-Bstatic” linker flag, but when I execute the code it stops after a while with the following error:

$ ./MOD_PR04_05.exe
PGFIO-F-209/list-directed read/unit=10/'OLD' specified for file which does not exist.
 In source file MOD_PR05_V2.f, at line number 748

The indicated source code line contains a “READ(handle_trans(1),*)” instruction, but I believe this is not the real issue. The executable code itself has a log feature which is quite verbose, but it just gives “success” returns for all the operations performed until the error occurs.
In PGI user guide page 279, the comment for this kind of error is:

Memory allocation operations occur only in conjunction with namelist I/O. The most probable cause of fixed buffer overflow is exceeding the maximum number of simultaneously open file units.

Any hints on compilation / linking flags that I may be missing, or anything else ?

Thanks,
Alex

Hi Alex,

The text you quote actually applies to Runtime Error Message #210 not #209. Sorry if this is confusing. Our error messages are not always well documented but in this case I believe the thought was that message #209’s text is self-explanatory.

For some reason your program cannot read from the file. First make sure that it does exist and then check that you have read permission. If it does exist and you have permissions, perhaps SELinux is preventing your program from reading files?

  • Mat

The problem is with the SELINUX security level.

In FC4 do the following:

as root, edit the file /etc/selinux/config and type the following:

SELINUX=permissive

then restart selinux or your system… That’s it!!! :-)