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

Danyang Su danyang.su at gmail.com
Sat Jun 2 13:36:06 CDT 2018


Hi Barry,

For the code without PETSc, the rules used to compile the code with CGAL is

DLIB = -lstdc++ -lmetis -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 -I$(LIS_INC)
CXXFLAGS = -std=c++11 -O3 -I$(LIS_INC)

However, after adding these to the makefile using PETSc, I got error 
telling me that all the petsc include files cannot be found.

../../solver/solver_snes_common.F90:27:0: fatal error: petscversion.h: 
No such \
file or directory
  #include <petscversion.h>

../../solver/solver_snes_common.F90:27:0: fatal error: petscversion.h: 
No such \
file or directory
  #include <petscversion.h>

Similar for other head files. However, If I change the file path to the 
the full path, the code cannot compiled. Does the rule I use destroy the 
PETSc relative path/

The make commands I use is

executable: $(SOURCES) chkopts
     -${FLINKER} $(FFLAGS) $(FPPFLAGS) $(CPPFLAGS)  -o executable.out 
$(SOURCES) ${PETSC_LIB} ${LIS_LIB} ${DLIB}
%.o:%.F90
     $(FLINKER) $(FFLAGS) $(FPPFLAGS) -c -frounding-math $< -o $@
%.o:%.cpp
     $(CLINKER) $(CXXFLAGS) $(CPPFLAGS) -c -frounding-math $< -o $@

Thanks,

Danyang

On 18-06-01 10:41 AM, Smith, Barry F. wrote:
>     You need to determine exactly what flags are passed to the C++ compiler for your compile that works and make sure those same flags are used in "PETSc version" of the makefile. You could add the flags directly to the rule
>
>> %.o:%.cpp
>>     $(CLINKER) $(CXXFLAGS) $(CPPFLAGS) -c -frounding-math $< -o $@
>    Barry
>
>
>> On Jun 1, 2018, at 12:37 PM, Danyang Su <danyang.su at gmail.com> wrote:
>>
>> Follow up:
>>
>> With following command
>>
>> executable: $(SOURCES) chkopts
>>     -${FLINKER} $(FFLAGS) $(FPPFLAGS) $(CPPFLAGS)  -o executable.out $(SOURCES) ${PETSC_LIB}
>>
>> %.o:%.F90
>>     $(FLINKER) $(FFLAGS) $(FPPFLAGS) -c -frounding-math $< -o $@
>> %.o:%.cpp
>>     $(CLINKER) $(CXXFLAGS) $(CPPFLAGS) -c -frounding-math $< -o $@
>>
>> The compiler return error: no match function.
>>
>> ../../usg/cgal_triangulation_2d.cpp: In function ‘void outputTriangulation2d(in\
>> t, const char*, int, const char*)’:
>> ../../usg/cgal_triangulation_2d.cpp:485:20: error: no matching function for cal\
>> l to ‘std::basic_ofstream<char>::open(std::string&)’
>>     out.open(strfile);
>>
>> Thanks,
>>
>>
>> Danyang
>>
>> On 18-06-01 10:07 AM, Danyang Su 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