And sometimes you might need to list these additional libraries/options after PETSc libraries - in the link command. One way: balay@ pj01: ~/test$ cat makefile include ${PETSC_DIR}/lib/petsc/conf/variables include ${PETSC_DIR}/lib/petsc/conf/rules
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
 
ZjQcmQRYFpfptBannerEnd
And sometimes you might need to list these additional libraries/options after PETSc libraries - in the link command. One way:

balay@pj01:~/test$ cat makefile

include ${PETSC_DIR}/lib/petsc/conf/variables
include ${PETSC_DIR}/lib/petsc/conf/rules
LDLIBS += -foobar

balay@pj01:~/test$ make ex2
mpicxx -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -Wno-lto-type-mismatch -Wno-psabi -fstack-protector -fvisibility=hidden -g -O0  -I/home/balay/petsc/include -I/home/balay/petsc/arch-linux-c-debug/include     ex2.cpp  -Wl,-rpath,/home/balay/petsc/arch-linux-c-debug/lib -L/home/balay/petsc/arch-linux-c-debug/lib -Wl,-rpath,/software/mpich-4.1.1/lib -L/software/mpich-4.1.1/lib -Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/13 -L/usr/lib/gcc/x86_64-redhat-linux/13 -lpetsc -llapack -lblas -ltriangle -lm -lX11 -lmpifort -lmpi -lgfortran -lm -lgfortran -lm -lgcc_s -lquadmath -lstdc++ -lquadmath -foobar -o ex2
g++: error: unrecognized command-line option ‘-foobar’
make: *** [<builtin>: ex2] Error 1

Satish

On Tue, 9 Jul 2024, Satish Balay wrote:

> It depends on your makefile - and how you are over-riding the targets. 1. Why add -rpath to CXXFLAGS, and not LDFLAGS? The following work for me with the default makefile format used by petsc examples
> balay@ pj01: ~/test$ ls ex2. cpp makefile
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
>  
> ZjQcmQRYFpfptBannerEnd
> 
> It depends on your makefile - and how you are over-riding the targets.
> 
> 1. Why add -rpath to CXXFLAGS, and not LDFLAGS?
> 
> The following work for me with the default makefile format used by petsc examples
> 
> balay@pj01:~/test$ ls
> ex2.cpp  makefile
> balay@pj01:~/test$ cat makefile 
> 
> include ${PETSC_DIR}/lib/petsc/conf/variables
> include ${PETSC_DIR}/lib/petsc/conf/rules
> 
> balay@pj01:~/test$ make ex2
> mpicxx -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -Wno-lto-type-mismatch -Wno-psabi -fstack-protector -fvisibility=hidden -g -O0  -I/home/balay/petsc/include -I/home/balay/petsc/arch-lin
> ux-c-debug/include     ex2.cpp  -Wl,-rpath,/home/balay/petsc/arch-linux-c-debug/lib -L/home/balay/petsc/arch-linux-c-debug/lib -Wl,-rpath,/software/mpich-4.1.1/lib -L/software/mpich-4.1.1/lib -Wl,-rpath,/usr
> /lib/gcc/x86_64-redhat-linux/13 -L/usr/lib/gcc/x86_64-redhat-linux/13 -lpetsc -llapack -lblas -ltriangle -lm -lX11 -lmpifort -lmpi -lgfortran -lm -lgfortran -lm -lgcc_s -lquadmath -lstdc++ -lquadmath -o ex2
> balay@pj01:~/test$ make clean
> balay@pj01:~/test$ make ex2 LDFLAGS=-foobar
> mpicxx -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -Wno-lto-type-mismatch -Wno-psabi -fstack-protector -fvisibility=hidden -g -O0  -I/home/balay/petsc/include -I/home/balay/petsc/arch-lin
> ux-c-debug/include    -foobar ex2.cpp  -Wl,-rpath,/home/balay/petsc/arch-linux-c-debug/lib -L/home/balay/petsc/arch-linux-c-debug/lib -Wl,-rpath,/software/mpich-4.1.1/lib -L/software/mpich-4.1.1/lib -Wl,-rpa
> th,/usr/lib/gcc/x86_64-redhat-linux/13 -L/usr/lib/gcc/x86_64-redhat-linux/13 -lpetsc -llapack -lblas -ltriangle -lm -lX11 -lmpifort -lmpi -lgfortran -lm -lgfortran -lm -lgcc_s -lquadmath -lstdc++ -lquadmath 
> -o ex2
> g++: error: unrecognized command-line option ‘-foobar’
> make: *** [<builtin>: ex2] Error 1
> balay@pj01:~/test$ make ex2 CXXFLAGS=-foobar
> mpicxx -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -Wno-lto-type-mismatch -Wno-psabi -fstack-protector -fvisibility=hidden -g -O0 -foobar -I/home/balay/petsc/include -I/home/balay/petsc/a
> rch-linux-c-debug/include     ex2.cpp  -Wl,-rpath,/home/balay/petsc/arch-linux-c-debug/lib -L/home/balay/petsc/arch-linux-c-debug/lib -Wl,-rpath,/software/mpich-4.1.1/lib -L/software/mpich-4.1.1/lib -Wl,-rpa
> th,/usr/lib/gcc/x86_64-redhat-linux/13 -L/usr/lib/gcc/x86_64-redhat-linux/13 -lpetsc -llapack -lblas -ltriangle -lm -lX11 -lmpifort -lmpi -lgfortran -lm -lgfortran -lm -lgcc_s -lquadmath -lstdc++ -lquadmath 
> -o ex2
> g++: error: unrecognized command-line option ‘-foobar’
> make: *** [<builtin>: ex2] Error 1
> balay@pj01:~/test$ 
> 
> Satish
> 
> On Tue, 9 Jul 2024, Qiyue Lu wrote:
> 
> > Hello,
> > I am trying to compile a *.cpp code under PETSc environment. An additional
> > flag is needed to link the metis partition library.
> > ##############
> > # This line is necessary for linking, remember need this flag in both
> > compiler options and linking options
> > LDFLAGS= -fopenmp -lpmix -lmetis
> > 
> > # This line is required for using some 'helper' function like
> > cudaErrorCheck from samples suite
> > CXXFLAGS +=
> > -Wl,-rpath,/sw/spack/deltas11-2023-03/apps/linux-rhel8-zen/gcc-8.5.0/metis-5.1.0-v5iddu2/lib
> > # This two lines are required for using PETSc
> > include ${PETSC_DIR}/lib/petsc/conf/variables
> > include ${PETSC_DIR}/lib/petsc/conf/rules
> > ##############
> > 
> > However, adding "CXXFLAGS += -Wl,-rpath, path_to_lib" in the makefile under
> > the same directory, is not working. And CPPFLAGS and CXXPPFLAGS won't work
> > either. No errors while compiling, but cannot find the metis.o while
> > running the binary. Another confusing point is, in the compilation flash
> > screen, LDFLAGS options can be found, but CXXFLAGS cannot.
> > 
> > Could you please inform me how to add additional flags in the makefile?
> > 
> > Thanks,
> > Qiyue Lu
> > 
> 
> 

Reply via email to