[petsc-users] Makefile for mixed C++ and Fortran code

Danyang Su danyang.su at gmail.com
Fri Jun 1 12:42:37 CDT 2018


On 18-06-01 10:29 AM, Smith, Barry F. wrote:
>    What happens if you add ${DLIB} to the end of the line
>
>> executable: $(SOURCES) chkopts
>>     -${FLINKER} $(FFLAGS) $(FPPFLAGS) $(CPPFLAGS)  -o executable.out $(SOURCES) ${PETSC_LIB}
>    Send all the output from trying this.
>
>     Barry
Thanks, Barry. Still not work after including ${DLIB}
>
>
>
>
>> On Jun 1, 2018, at 12:07 PM, Danyang Su <danyang.su at gmail.com> wrote:
>>
>> Hi All,
>>
>> My code needs to link to an external C++ library (CGAL). The code is written in Fortran and I have already written interface to let Fortran call C++ function. For the sequential version without PETSc, it can be compiled without problem using the following makefile. The parallel version without CGAL can also be compiled successfully. However, when I tried to use PETSc together with CGAL library, I cannot compile the code. My questions is: How can I modify the makefile? Do I need to reconfigure PETSc with special flags? All the makefile samples are shown below.
>>
>> #makefile for sequential version
>>
>> FC = gfortran
>> #FC = ifort
>> CXX = g++ -std=c++11
>>
>> DLIB = -lstdc++ -lm -L/usr/local/lib -rdynamic /usr/local/lib/libmpfr.so /usr/local/lib/libgmp.so /usr/local/lib/libCGAL_ImageIO.so.11.0.1 /usr/local/lib/libCGAL.so.11.0.1 /usr/local/lib/libboost_thread.so /usr/local/lib/libboost_system.so -lpthread -lGLU -lGL -lX11 -lXext -lz /usr/local/lib/libCGAL_ImageIO.so.11.0.1 /usr/local/lib/libCGAL.so.11.0.1 /usr/local/lib/libboost_thread.so /usr/local/lib/libboost_system.so -lpthread -lGLU -lGL -lX11 -lXext -lz /usr/local/lib/libmpfr.so /usr/local/lib/libgmp.so /usr/local/lib/libboost_thread.so /usr/local/lib/libboost_system.so -lpthread -Wl,-rpath,/usr/local/lib
>>
>> FFLAGS = -O3
>> CXXFLAGS = -O3
>>
>> FPPFLAGS =  -DUSECGAL
>>
>> SRC =./../../
>>
>> SOURCES = $(SRC)usg/math_common.o\
>>     $(SRC)usg/geometry_definition.o\
>>     $(SRC)usg/cgal_common.o\
>>
>> ...
>>
>> executable: $(SOURCES)
>>     $(FC) $(FFLAGS) $(FPPFLAGS) -o executable.out $(SOURCES) ${LIS_LIB} $(DLIB)
>> %.o:%.F90
>>     $(FC) $(FFLAGS) $(FPPFLAGS) -c -frounding-math $< -o $@
>> %.o:%.cpp
>>     $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -frounding-math $< -o $@
>>
>>
>> #makefile for parallel version with PETSc, without CGAL
>>
>> #FC = ifort
>> #FC = gfortran
>>
>> DLIB = -lm
>>
>> FFLAGS = -O3
>>
>> FPPFLAGS =  -DUSEPETSC
>>
>> SRC =./../../
>>
>> SOURCES = $(SRC)usg/math_common.o\
>>     $(SRC)usg/geometry_definition.o\
>>     $(SRC)usg/cgal_common.o\
>>
>> ...
>>
>> executable: $(SOURCES) chkopts
>>     -${FLINKER} $(FFLAGS) $(FPPFLAGS) $(CPPFLAGS)  -o executable.out $(SOURCES) ${PETSC_LIB}
>>
>>
>> #makefile for parallel version with PETSc, with CGAL, CANNOT work
>>
>> #FC = ifort
>> #FC = gfortran
>>
>> DLIB = -lm
>>
>> FFLAGS = -O3
>>
>> FPPFLAGS =  -DUSEPETSC -DUSECGAL
>>
>> SRC =./../../
>>
>> SOURCES = $(SRC)usg/math_common.o\
>>     $(SRC)usg/geometry_definition.o\
>>     $(SRC)usg/cgal_common.o\
>>
>> ...
>>
>> executable: $(SOURCES) chkopts
>>     -${FLINKER} $(FFLAGS) $(FPPFLAGS) $(CPPFLAGS)  -o executable.out $(SOURCES) ${PETSC_LIB}
>>
>> %.o:%.F90
>>     $(FC) $(FFLAGS) $(FPPFLAGS) -c -frounding-math $< -o $@
>> %.o:%.cpp
>>     $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -frounding-math $< -o $@
>>
>>
>> Thanks,
>>
>> Danyang
>>



More information about the petsc-users mailing list