obsproject / obs-plugintemplate

GNU General Public License v2.0
285 stars 133 forks source link

Build plugin support library with PIC on Linux and BSD #100

Closed royshil closed 9 months ago

royshil commented 9 months ago

Description

Adding -fPIC on Linux when compiling the libplugin-support.a static lib, otherwise some Linux OSs build complain e.g.

/usr/bin/ld: libplugin-support.a(plugin-support.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: failed to set dynamic section sizes: bad value

Motivation and Context

Fixing Linux build for OSs such as Fedora.

How Has This Been Tested?

Built on Mac, Windows and Linux (Ubuntu).

Types of changes

Effectively a bugfix?

Checklist:

PatTheMav commented 9 months ago

Using an OBJECT library would probably be better, but alas CMake doesn't support them with universal (x86_64 and arm64) macOS targets, so we are kinda stuck with static libraries.

For some reason gcc does not assume PIC automatically for static x86_64 builds, so this seems correct.

royshil commented 9 months ago

Thanks @PatTheMav !

PatTheMav commented 9 months ago

One last thing, I'd prefer if the PR title and commit title would read something like:

Build plugin support library with PIC on Linux and BSD

It's more generic from a project POV (calling it "position-independent code" would be even better but probably run afoul of commit message limits).

PatTheMav commented 9 months ago

Please squash your changes into logical units and ensure correct naming for all commits. Otherwise the PR looks good.