Rate This Document
Findability
Accuracy
Completeness
Readability

Specifying a PIC or PIE

Error Information

For some dynamic libraries, when the pic or pie option is not used, an error similar to the following is reported, indicating that the symbol table is missing:

1
undefined reference to `cmsPlugin'

Problem

The pic or pie option is not carried during compilation or linking of the generated dynamic library or PIE executable file. As a result, the symbol table is missing. In this case, a PIC or PIE needs to be specified manually.

Code Example

Check whether a PIC library is available. If yes, textrel is displayed.

1
readelf -a libhello.so |grep -i textrel

Check whether a PIE shared file is available. Run the file command for the check, or use size --format=sysv to check whether the base address is around 0.

Solution

Add -fPIC to compiler options and -pie to link options.

Clang distinguishes compiler and link options. -pie cannot be transferred to the linker using cflags. Otherwise, the following error is reported:

1
clang-10: error: argument unused during compilation: '-pie' [-Werror,-Wunused-command-line-argument]