[petsc-users] How do I supply the compiler PIC flag via CFLAGS, CXXXFLAGS, and FCFLAGS
Jed Brown
jed at jedbrown.org
Tue May 28 14:05:43 CDT 2019
No love with:
cc: Sun C 5.12 Linux_i386 2011/11/16
Note that all of these compilers (including Sun C, which doesn't define
the macro) recognize -fPIC. (Blue Gene xlc requires -qpic.) Do we
still need to test the other alternatives?
"Smith, Barry F." <bsmith at mcs.anl.gov> writes:
> 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> wrote:
>>
>>
>>
>> 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/
More information about the petsc-users
mailing list