From jombart at biomserv.univ-lyon1.fr  Sun Apr 20 15:41:54 2008
From: jombart at biomserv.univ-lyon1.fr (Thibaut Jombart)
Date: Sun, 20 Apr 2008 15:41:54 +0200
Subject: [Rd] Fortran underscore problem persists on Linux x86/64
	(PR#11206)
In-Reply-To: <480B29A6.7000900@biostat.ku.dk>
References: <20080419181513.6E73D2834154@mail.pubhealth.ku.dk>	<480AFDDF.7060905@biomserv.univ-lyon1.fr>	<alpine.LFD.1.10.0804201023270.31126@gannet.stats.ox.ac.uk>	<480B1D8D.2080808@biomserv.univ-lyon1.fr>
	<alpine.LFD.1.10.0804201141590.3204@auk.stats.ox.ac.uk>
	<480B29A6.7000900@biostat.ku.dk>
Message-ID: <480B4822.7080502@biomserv.univ-lyon1.fr>


>>
>> Thanks, for code-compilation problems we need that level of detail.
>>
>> Your problem appears to be that you are mixing gcc4 and g77 (not 
>> recommended), and g77 does use extra underscores, I believe.  I have
>>
>> /* Define if your Fortran compiler appends an extra_underscore to 
>> external
>>    names containing an underscore. */
>> /* #undef HAVE_F77_EXTRA_UNDERSCORE */
>>
>> /* Define if your Fortran compiler appends an underscore to external 
>> names. */
>> #define HAVE_F77_UNDERSCORE 1
>>
>> in src/include/config.h.  If the first of these is defined, please 
>> try commenting it out and rebuilding R.
>>
>> I've found an old Solaris box that still has g77 on, and I can 
>> reproduce this there.  I will patch the sources after further 
>> testing, but altering src/include/config.h worked for me.
>>
>> I was certainly not expecting Ubuntu 7.07 to be using g77, so we need 
>> the same details from Thomas Petzoldt.
>
> Is this perhaps an installation issue (missing gfortran)?
>
> more `R RHOME`/etc/Makeconf
>
> should tell you which compilers R itself was built with. In my 
> experience, it just doesn't work to mix v.3.x and 4.x compilers (Brian 
> might correct me on that though).
>
Thank you, your hint worked!
I commented out the line:
#define HAVE_F77_EXTRA_UNDERSCORE 1
in the R configure script (line 28098 in R 2.7.0 RC (2008-04-15 r45347))

Contrary to what I thought previously, I have gfortran installed:
 > gfortran-4.0 --version
GNU Fortran 95 (GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5))

And here is the content of the "working" Makeconf:
############## Makeconf
# etc/Makeconf.  Generated from Makeconf.in by configure.
#
# ${R_HOME}/etc/Makeconf

include $(R_SHARE_DIR)/make/vars.mk

AR = ar
BLAS_LIBS = -L$(R_HOME)/lib$(R_ARCH) -lRblas
C_VISIBILITY = -fvisibility=hidden
CC = gcc -std=gnu99
CFLAGS = -g -O2
CPICFLAGS = -fpic
CPPFLAGS = -I/usr/local/include
CXX = g++
CXXCPP = g++ -E
CXXFLAGS = -g -O2
CXXPICFLAGS = -fpic
DYLIB_EXT = .so
DYLIB_LD = gcc -std=gnu99
DYLIB_LDFLAGS = -shared
DYLIB_LINK = $(DYLIB_LD) $(DYLIB_LDFLAGS) $(LDFLAGS)
ECHO = echo
ECHO_C =
ECHO_N = -n
ECHO_T =
F77 = g77
F77_VISIBILITY =
FC = g77
FCFLAGS = -g -O2
FFLAGS = -g -O2
FLIBS =  -L/usr/lib/gcc/x86_64-linux-gnu/3.4.6 -lg2c -lm
FCPICFLAGS = -fpic
FPICFLAGS = -fpic
FOUNDATION_CPPFLAGS =
FOUNDATION_LIBS =
JAR = /usr/bin/jar
JAVA = /usr/local/jre/bin/java
JAVAC =
JAVAH =
JAVA_HOME = /usr/local/jre1.5.0_07
JAVA_LD_LIBRARY_PATH = 
$(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/../lib/amd64:/usr/local/lib64
JAVA_LIBS = -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64 
-L$(JAVA_HOME)/../lib/amd64 -L/usr/local/lib64 -ljvm
JAVA_CPPFLAGS = ~autodetect~
LAPACK_LIBS = -L$(R_HOME)/lib$(R_ARCH) -lRlapack
## we only need this is if it is external, as otherwise link to R
LIBINTL=
LIBM = -lm
LIBR =
LIBS =  -ldl -lm
## needed by R CMD config
LIBnn = lib64
LIBTOOL = $(SHELL) $(R_HOME)/bin/libtool
LDFLAGS = -L/usr/local/lib64
## needed to build applications linking to static libR
MAIN_LD = gcc -std=gnu99
MAIN_LDFLAGS = -Wl,--export-dynamic
MAIN_LINK = $(MAIN_LD) $(MAIN_LDFLAGS) $(LDFLAGS)
OBJC =
OBJCFLAGS =
OBJC_LIBS =
OBJCXX =
R_ARCH =
RANLIB = ranlib
SAFE_FFLAGS = -g -O2 -ffloat-store
SED = /bin/sed
SHELL = /bin/sh
SHLIB_CFLAGS =
SHLIB_CXXFLAGS =
SHLIB_CXXLD = g++
SHLIB_CXXLDFLAGS = -shared
SHLIB_EXT = .so
SHLIB_FCLD = g77
SHLIB_FCLDFLAGS = -shared
SHLIB_FFLAGS =
SHLIB_LD = gcc -std=gnu99
SHLIB_LDFLAGS = -shared
SHLIB_LIBADD =
SHLIB_LINK = $(SHLIB_LD) $(SHLIB_LDFLAGS) $(LDFLAGS)
STRIP_LIBS = strip --strip-unneeded
STRIP_STATIC_LIBS = strip --strip-debug
TCLTK_CPPFLAGS = -I/usr/include/tcl8.4
TCLTK_LIBS = -L/usr/lib -ltcl8.4 -L/usr/lib -ltk8.4 -lX11

## for linking to libR.a
STATIC_LIBR = # $(R_HOME)/lib$(R_ARCH)/libR.a $(BLAS_LIBS) $(FLIBS)  
$(LIBINTL) -lreadline  $(LIBS)


R_XTRA_CFLAGS =
R_XTRA_CPPFLAGS =  -I$(R_INCLUDE_DIR)
R_XTRA_CXXFLAGS =
R_XTRA_FFLAGS =

ALL_CFLAGS = $(R_XTRA_CFLAGS) $(PKG_CFLAGS) $(CPICFLAGS) $(SHLIB_CFLAGS) 
$(CFLAGS)
ALL_CPPFLAGS = $(R_XTRA_CPPFLAGS) $(PKG_CPPFLAGS) $(CPPFLAGS) 
$(CLINK_CPPFLAGS)
ALL_CXXFLAGS = $(R_XTRA_CXXFLAGS) $(PKG_CXXFLAGS) $(CXXPICFLAGS) 
$(SHLIB_CXXFLAGS) $(CXXFLAGS)
ALL_OBJCFLAGS = $(PKG_OBJCFLAGS) $(CPICFLAGS) $(SHLIB_CFLAGS) $(OBJCFLAGS)
ALL_OBJCXXFLAGS = $(PKG_OBJCXXFLAGS) $(CXXPICFLAGS) $(SHLIB_CXXFLAGS) 
$(OBJCXXFLAGS)
ALL_FFLAGS = $(R_XTRA_FFLAGS) $(PKG_FFLAGS) $(FPICFLAGS) $(SHLIB_FFLAGS) 
$(FFLAGS)
ALL_LIBS = $(PKG_LIBS) $(SHLIB_LIBADD) $(LIBR)# $(LIBINTL)

.SUFFIXES:
.SUFFIXES: .c .cc .cpp .C .d .f .f90 .f95 .m .mm .M .o

.c.o:
        $(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c $< -o $@
.c.d:
        @echo "making $@ from $<"
        @gcc -std=gnu99 -MM $(ALL_CPPFLAGS) $< > $@
.m.d:
        @echo > $@
.cc.o:
        $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c $< -o $@
.cpp.o:
        $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c $< -o $@
.C.o:
        $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c $< -o $@
.cc.d:
        @echo "making $@ from $<"
        @$(CXX) -M $(ALL_CPPFLAGS) $< > $@
.cpp.d:
        @echo "making $@ from $<"
        @$(CXX) -M $(ALL_CPPFLAGS) $< > $@
.C.d:
        @echo "making $@ from $<"
        @$(CXX) -M $(ALL_CPPFLAGS) $< > $@
.m.o:
        $(OBJC) $(ALL_CPPFLAGS) $(ALL_OBJCFLAGS) -c $< -o $@
.mm.o:
        $(OBJCXX) $(ALL_CPPFLAGS) $(ALL_OBJCXXFLAGS) -c $< -o $@
.M.o:
        $(OBJCXX) $(ALL_CPPFLAGS) $(ALL_OBJCXXFLAGS) -c $< -o $@
.f.o:
        $(F77) $(ALL_FFLAGS) -c $< -o $@
.f95.o:
        $(FC) $(PKG_FCFLAGS) $(FCPICFLAGS) $(FCFLAGS) -c  $< -o $@
.f90.o:
        $(FC) $(PKG_FCFLAGS) $(FCPICFLAGS) $(FCFLAGS) -c  $< -o $@
################# end Makeconf

Not surprisingly, this also fixed the issue with deSolve:
 > library(deSolve)
 > getNativeSymbolInfo("iniaqua", PACKAGE = "deSolve")$address
<pointer: 0x2aaaaeb3c4d0>
attr(,"class")
[1] "NativeSymbol"


Best regards,

Thibaut.

-- 
######################################
Thibaut JOMBART
CNRS UMR 5558 - Laboratoire de Biom?trie et Biologie Evolutive
Universite Lyon 1
43 bd du 11 novembre 1918
69622 Villeurbanne Cedex
T?l. : 04.72.43.29.35
Fax : 04.72.43.13.88
jombart at biomserv.univ-lyon1.fr
http://lbbe.univ-lyon1.fr/-Jombart-Thibaut-.html?lang=en
http://adegenet.r-forge.r-project.org/



[Rd] Fortran underscore problem persists on Linux x86/64 (PR#11206)
Thibaut Jombart