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

Lisandro Dalcin dalcinl at gmail.com
Tue May 28 12:29:17 CDT 2019


On Tue, 28 May 2019 at 18:19, Jed Brown <jed at jedbrown.org> wrote:

> Lisandro Dalcin via petsc-users <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> 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/6b9e76e5/attachment.html>


More information about the petsc-users mailing list