Commit 1eb425e3 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

just confirmed that linking Fortran 77 against C++ works

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 3412
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 01bc38fe
......@@ -26,6 +26,7 @@ INCINSTALLPATH=$(LOCINCLUDEDIR)/fapidxx
LIBINSTALLPATH=$(LOCLIBDIR)
HEADERS=$(wildcard *.h)
CCSRC=$(wildcard *.cc)
FSRC=$(wildcard *.f)
SRC=$(CCSRC)
README=README
......@@ -38,7 +39,7 @@ CPPFLAGS+=-I$(LOCINCLUDEDIR) $(FLAGS)
#----------------------------------------------------------------------
flist: Makefile $(HEADERS) $(README) $(SRC) doxydoc.cfg
flist: Makefile $(HEADERS) $(README) $(SRC) doxydoc.cfg $(FSRC)
echo $^ | tr ' ' '\n' | sort > $@
.PHONY: edit
......@@ -47,7 +48,7 @@ edit: flist; vim $<
.PHONY: clean
clean: ;
-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
-/bin/rm -vf flist
-/bin/rm -vf flist *.o fapidtest
#======================================================================
# dependencies
......@@ -121,7 +122,7 @@ LIBOBS=$(patsubst %.cc,%.o,$(SRC))
libfapidxx.a: $(INSTHEADER) $(LIBOBS)
ar rcv $@ $(LIBOBS)
ranlib $@
/bin/mv -vpf $@ $(LIBINSTALLPATH)
/bin/mv -vf $@ $(LIBINSTALLPATH)
#======================================================================
# documentation part
......@@ -167,5 +168,10 @@ doxydoc: $(DOXYWWWPATH)/html/index.html
doxyview: $(DOXYWWWPATH)/html/index.html
$(TF_BROWSER) file:$< &
#======================================================================
# test code
fapidtest: fapidtest.o libfapidxx.a
$(FC) -o $@ $< -lfapidxx -ltf -L$(LOCLIBDIR) -lstdc++
# ----- END OF Makefile -----
......@@ -17,4 +17,81 @@
* ============================================================================
*/
/*! \mainpage
The aim of this library is to provide Fortran 77 code written to be linked
against libsff.a with the full functionality in libdatreadxx.a and
libdatwritexx.a
Issues covered by this documentation:
\li \ref page_interlanguage_programming
*/
/*======================================================================*/
/*! \page page_interlanguage_programming Interlanguage programming
In the case of this library Fortran programs will call C++ functions.
A simple example is given here.
\section sec_pip_code The code
The C++ header file \c cxxfunc.h contains:
\code
#include <string>
namespace fapidxx {
int cxxfunction(const std::string& s);
} // namespace fapidxx
\endcode
The corresponding definition of the function is provided in
\c cxxfunc.cc:
\code
#include <cxxfunc.h>
namespace fapidxx {
int cxxfunction(const std::string& s)
{
int retval=s.size();
return(retval);
} // int cxxfunction(const std::string& s)
} // namespace fapidxx
\endcode
The Fortran interface function is declared in \c cxxiface.h:
\code
extern "C" int interfacesub_(float *value);
\endcode
The body of the function is defined in \c cxxiface.cc:
\code
#include <cxxfunc.h>
#include <cxxiface.h>
int interfacesub_(float *value)
{
int retval=0;
std::string chars="hi there 12345678";
*value=int(fapidxx::cxxfunction(chars));
return(retval);
} // int interfacesub_(float *value)
\endcode
In the Fortran main program \c fprog.f this function is called:
\code
program fapidtest
real a
call interfacesub(a)
print *,a
stop
end
\endcode
\section sec_pip_compiling Compiling and linking the code
Compiling the library:
\verbatim
P> g++ -c -o cxxfunc.o cxxfunc.cc
P> g++ -c -o cxxiface.o cxxiface.cc
P> ar rc libiface.a cxxfunc.o cxxiface.o
P> gfortran -ff2c -Wall -c -o fprog.o fprog.f
P> gfortran -o fprog fprog.o -liface ­lstdc++
\endverbatim
Calling \c fprog will produce the output:
\verbatim
P> fprog
17.000000
\endverbatim
*/
/* ----- END OF README ----- */
......@@ -25,7 +25,7 @@ DOXYFILE_ENCODING = UTF-8
# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
# by quotes) that should identify the project.
PROJECT_NAME = Fortran SFF API to data I/O streams in C++
PROJECT_NAME = "Fortran SFF API to data I/O streams in C++"
# The PROJECT_NUMBER tag can be used to enter a project or revision number.
# This could be handy for archiving the generated documentation or
......
......@@ -14,9 +14,11 @@ c
program fapidtest
c
character*(*) version
parameter(version='FAPIDTEST V1.0 this is a program to test several steps of fapid development')
parameter(version=
& 'FAPIDTEST V1.0 this is a program to test several steps of fapid development')
character*(*) FAPIDTEST_CVS_ID
parameter(FAPIDTEST_CVS_ID='$Id$')
parameter(FAPIDTEST_CVS_ID=
& '$Id$')
c
c commandline
integer maxopt, lastarg, iargc
......@@ -27,6 +29,8 @@ c commandline
logical optset(maxopt), opthasarg(maxopt)
c debugging
logical debug, verbose
c
real a
c here are the keys to our commandline options
data optid/2h-d, 2h-v/
data opthasarg/2*.FALSE./
......@@ -44,8 +48,6 @@ c
print *,' or: fapidtest -help'
if (argument(1:5).ne.'-help')
& stop 'ERROR: wrong number of arguments'
print *,' '
print *,'j'
print *,' '
print *,FAPIDTEST_CVS_ID
stop
......@@ -62,6 +64,8 @@ c
c------------------------------------------------------------------------------
c go
c
call interfacesub(a)
print *,a
stop
end
c
......
......@@ -21,10 +21,24 @@
#define TF_FILEUNIT_CC_CVSID \
"$Id$"
#include <fileunit.h>
#include <fapidxx/fileunit.h>
namespace tf {
namespace fapidxx {
}
int cxxfunction(const std::string& s)
{
int retval=s.size();
return(retval);
} // int cxxfunction(const std::string& s)
} // namespace fapidxx
int interfacesub_(float *value)
{
int retval=0;
std::string chars="hi there 12345678";
*value=int(fapidxx::cxxfunction(chars));
return(retval);
} // int interfacesub_(float *value)
/* ----- END OF fileunit.cc ----- */
......@@ -25,9 +25,14 @@
#define TF_FILEUNIT_H_CVSID \
"$Id$"
namespace tf {
#include<string>
namespace fapidxx {
}
int cxxfunction(const std::string& s);
} // namespace fapidxx
extern "C" int interfacesub_(float *value);
#endif // TF_FILEUNIT_H_VERSION (includeguard)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment