Commit 110ebbd8 authored by Michael Sherman's avatar Michael Sherman
Browse files

Added FCPPLIBS variable in makefile to accommodate systems where the fortran...

Added FCPPLIBS variable in makefile to accommodate systems where the fortran compiler needs some extra libraries to link with C++. Also added a Makefile.mac with a possible good library combo.
parent 373637c0
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# This has had only minimal testing, although it has been known to # This has had only minimal testing, although it has been known to
# work. It is likely to work fine for C and C++. For Fortran, you # work. It is likely to work fine for C and C++. For Fortran, you
# may need to add some of the C/C++ libraries: # may need to add some of the C/C++ libraries:
# -lc -lm -lstdc++ -lgcc -lgcc_s # -lc -lm -lstdc++ (or -lstdc++.6) -lgcc -lgcc_s
# but this wasn't required for these examples on Centos 5.2 using # but this wasn't required for these examples on Centos 5.2 using
# gcc 4.1.2. # gcc 4.1.2.
...@@ -24,6 +24,11 @@ OpenMM_INSTALL_DIR=/usr/local/openmm ...@@ -24,6 +24,11 @@ OpenMM_INSTALL_DIR=/usr/local/openmm
CFLAGS = -g CFLAGS = -g
FFLAGS = -g FFLAGS = -g
# Extra libraries required when gfortran links with a C++ module.
# Uncomment this on Mac. If this doesn't work, look in /usr/lib to
# see what versions of libstdc++.so you have and try that.
# FCPPLIBS = -lstdc++.6
LIB_DIR=$(OpenMM_INSTALL_DIR)/lib LIB_DIR=$(OpenMM_INSTALL_DIR)/lib
INCLUDE_DIR=$(OpenMM_INSTALL_DIR)/include INCLUDE_DIR=$(OpenMM_INSTALL_DIR)/include
# assume local directory for C and Fortran wrappers # assume local directory for C and Fortran wrappers
...@@ -55,11 +60,11 @@ HelloSodiumChlorideInC: HelloSodiumChlorideInC.c OpenMM_CWrapper.o ...@@ -55,11 +60,11 @@ HelloSodiumChlorideInC: HelloSodiumChlorideInC.c OpenMM_CWrapper.o
HelloArgonInFortran: HelloArgonInFortran.f90 openmm.mod HelloArgonInFortran: HelloArgonInFortran.f90 openmm.mod
gfortran $(FFLAGS) HelloArgonInFortran.f90 OpenMM_CWrapper.o \ gfortran $(FFLAGS) HelloArgonInFortran.f90 OpenMM_CWrapper.o \
-L$(LIB_DIR) $(LIBS) -o HelloArgonInFortran -L$(LIB_DIR) $(LIBS) $(FCPPLIBS) -o HelloArgonInFortran
HelloSodiumChlorideInFortran: HelloSodiumChlorideInFortran.f90 openmm.mod HelloSodiumChlorideInFortran: HelloSodiumChlorideInFortran.f90 openmm.mod
gfortran $(FFLAGS) HelloSodiumChlorideInFortran.f90 OpenMM_CWrapper.o \ gfortran $(FFLAGS) HelloSodiumChlorideInFortran.f90 OpenMM_CWrapper.o \
-L$(LIB_DIR) $(LIBS) -o HelloSodiumChlorideInFortran -L$(LIB_DIR) $(LIBS) $(FCPPLIBS) -o HelloSodiumChlorideInFortran
# Build C Wrappers (Fortran depends on this too) # Build C Wrappers (Fortran depends on this too)
OpenMM_CWrapper.o: OpenMM_CWrapper.o:
......
## Compiling a Fortran main with C++ can be finicky about libraries.
## Here FCPPLIBS is set the way we had to do it to work on a Mac.
## (Otherwise this is just a copy of 'Makefile')
# ----------------------------------------------------------------------
# Makefile for OpenMM Preview Release 3 workshop "hello world" examples.
# June 24, 2009.
# See https://simtk.org/home/openmm.
# ----------------------------------------------------------------------
# This assumes you have gcc compilers for whatever language you are
# using: g++ for C++ and C, gfortran for Fortran 95.
#
# Note: the C Wrappers and Fortran Module are just prototypes. They are
# incomplete but have enough functionality to get through these examples.
# We would like more complete and better-thought-out interfaces; if you
# have code or ideas please post to the OpenMM forum at the above URL
# (select "Advanced/Public Forums").
#
# This has had only minimal testing, although it has been known to
# work. It is likely to work fine for C and C++. For Fortran, you
# may need to add some of the C/C++ libraries:
# -lc -lm -lstdc++ (or -lstdc++.6) -lgcc -lgcc_s
# but this wasn't required for these examples on Centos 5.2 using
# gcc 4.1.2.
# Check whether this is the right capitalization for your install directory.
OpenMM_INSTALL_DIR=/usr/local/openmm
CFLAGS = -g
FFLAGS = -g
# Extra libraries required when gfortran links with a C++ module.
# Uncomment this on Mac. If this doesn't work, look in /usr/lib to
# see what versions of libstdc++.so you have and try that.
FCPPLIBS = -lstdc++.6
LIB_DIR=$(OpenMM_INSTALL_DIR)/lib
INCLUDE_DIR=$(OpenMM_INSTALL_DIR)/include
# assume local directory for C and Fortran wrappers
WRAPPER_DIR=.
LIBS= -lOpenMM
ALL_CPP_EXAMPLES = HelloArgon HelloSodiumChloride HelloEthane HelloWaterBox
ALL_C_EXAMPLES = HelloArgonInC HelloSodiumChlorideInC
ALL_F95_EXAMPLES = HelloArgonInFortran HelloSodiumChlorideInFortran
ALL_PROGS = $(ALL_CPP_EXAMPLES) $(ALL_C_EXAMPLES) $(ALL_F95_EXAMPLES)
default: HelloArgon
all : $(ALL_PROGS)
# Treat all .cpp source files the same way (except the one that
# implements the C Wrappers).
.cpp :
g++ $(CFLAGS) $< -I$(INCLUDE_DIR) -L$(LIB_DIR) $(LIBS) -o $*
HelloArgonInC: HelloArgonInC.c OpenMM_CWrapper.o
g++ $(CFLAGS) -I$(WRAPPER_DIR) HelloArgonInC.c OpenMM_CWrapper.o \
-L$(LIB_DIR) $(LIBS) -o HelloArgonInC
HelloSodiumChlorideInC: HelloSodiumChlorideInC.c OpenMM_CWrapper.o
g++ $(CFLAGS) -I$(WRAPPER_DIR) HelloSodiumChlorideInC.c OpenMM_CWrapper.o \
-L$(LIB_DIR) $(LIBS) -o HelloSodiumChlorideInC
HelloArgonInFortran: HelloArgonInFortran.f90 openmm.mod
gfortran $(FFLAGS) HelloArgonInFortran.f90 OpenMM_CWrapper.o \
-L$(LIB_DIR) $(LIBS) $(FCPPLIBS) -o HelloArgonInFortran
HelloSodiumChlorideInFortran: HelloSodiumChlorideInFortran.f90 openmm.mod
gfortran $(FFLAGS) HelloSodiumChlorideInFortran.f90 OpenMM_CWrapper.o \
-L$(LIB_DIR) $(LIBS) $(FCPPLIBS) -o HelloSodiumChlorideInFortran
# Build C Wrappers (Fortran depends on this too)
OpenMM_CWrapper.o:
g++ -c $(CFLAGS) -I$(WRAPPER_DIR) -I$(INCLUDE_DIR) \
$(WRAPPER_DIR)/OpenMM_CWrapper.cpp -o OpenMM_CWrapper.o
# Build Fortran 95 Module file
openmm.mod:
gfortran -c $(FFLAGS) $(WRAPPER_DIR)/OpenMM_Module.f90
clean :
rm $(ALL_PROGS) *.o *.mod
...@@ -5,7 +5,7 @@ You must already have the OpenMM binaries installed from SimTK.org/home/OpenMM. ...@@ -5,7 +5,7 @@ You must already have the OpenMM binaries installed from SimTK.org/home/OpenMM.
instructions -- if you are hoping to get GPU acceleration you instructions -- if you are hoping to get GPU acceleration you
may also have to install appropriate vendor libraries and a driver. may also have to install appropriate vendor libraries and a driver.
You may need to slightly edit the Makefile to make it run on your system, depending where you installed OpenMM. You may need to slightly edit the Makefile to make it run on your system, depending where you installed OpenMM and the particular requirements of your version of gcc for mixed Fortran/C++ programming. There is a copy of the Makefile called 'Makefile.mac' which uses a library that worked for us on Mac.
Type "make" (or "make default") to get just one C++ example built Type "make" (or "make default") to get just one C++ example built
(HelloArgon). Make sure it runs. (HelloArgon). Make sure it runs.
......
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