[petsc-users] How do I supply the compiler PIC flag via CFLAGS, CXXXFLAGS, and FCFLAGS

Zhang, Junchao jczhang at mcs.anl.gov
Tue May 28 16:25:45 CDT 2019


Also works with PathScale EKOPath Compiler Suite installed on MCS machines.

$ pathcc -c check-pic.c -fPIC
$ pathcc -c check-pic.c
check-pic.c:2:2: error: "no-PIC"
#error "no-PIC"
 ^
1 error generated.

--Junchao Zhang


On Tue, May 28, 2019 at 1:54 PM Smith, Barry F. via petsc-users <petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>> wrote:

  Works for Intel and PGI compiles (the version I checked)

bsmith at es:~$ pgcc check-pic.c  -PIC
pgcc-Error-Unknown switch: -PIC
bsmith at es:~$ pgcc check-pic.c  -fPIC
bsmith at es:~$ pgcc check-pic.c
PGC-F-0249-#error --  "no-PIC" (check-pic.c: 2)
PGC/x86-64 Linux 19.3-0: compilation aborted
bsmith at es:~$ icc check-pic.c
check-pic.c(2): error: #error directive: "no-PIC"
  #error "no-PIC"
   ^

compilation aborted for check-pic.c (code 2)
bsmith at es:~$ icc check-pic.c -PIC
icc: command line warning #10006: ignoring unknown option '-PIC'
check-pic.c(2): error: #error directive: "no-PIC"
  #error "no-PIC"
   ^

compilation aborted for check-pic.c (code 2)
bsmith at es:~$ icc check-pic.c -fPIC
bsmith at es:~$


You are the man!


> On May 28, 2019, at 12:29 PM, Lisandro Dalcin via petsc-users <petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>> wrote:
>
>
>
> On Tue, 28 May 2019 at 18:19, Jed Brown <jed at jedbrown.org<mailto:jed at jedbrown.org>> wrote:
> Lisandro Dalcin via petsc-users <petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>> writes:
>
> > On Tue, 28 May 2019 at 17:31, Balay, Satish via petsc-users <
> > petsc-users at mcs.anl.gov<mailto:petsc-users at mcs.anl.gov>> wrote:
> >
> >> Configure.log shows '--with-pic=1' - hence this error.
> >>
> >> Remove '--with-pic=1' and retry.
> >>
> >>
> > Nonsense. Why this behavior? Building a static library with PIC code is a
> > perfectly valid use case.
>
> And that's what will happen because Inge passed -fPIC in CFLAGS et al.
>
> Do you know how we could confirm that PIC code is generated without
> attempting to use shared libraries?
>
>
> I know how to do it with the `readelf` command for ELF objects. I even know how to do it compile-time for GCC and clang. Maybe Intel also works this way. I do not know about a general solution, though.
>
> $ cat check-pic.c
> #ifndef __PIC__
> #error "no-PIC"
> #endif
>
> $ gcc -c check-pic.c -fPIC
>
> $ clang -c check-pic.c -fPIC
>
> $ gcc -c check-pic.c
> check-pic.c:2:2: error: #error "no-PIC"
>     2 | #error "no-PIC"
>       |  ^~~~~
>
> $ clang -c check-pic.c
> check-pic.c:2:2: error: "no-PIC"
> #error "no-PIC"
>  ^
> 1 error generated.
>
> --
> Lisandro Dalcin
> ============
> Research Scientist
> Extreme Computing Research Center (ECRC)
> King Abdullah University of Science and Technology (KAUST)
> http://ecrc.kaust.edu.sa/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190528/2e0c972d/attachment.html>


More information about the petsc-users mailing list