compile fails: lib-audio-devices needs -fPIC SOLVED?

Attempting to compile Audacity from a git clone, I got the following error:

[ 29%] Built target lib-registries
Consolidate compiler generated dependencies of target lib-xml
[ 30%] Built target lib-xml
Consolidate compiler generated dependencies of target lib-audio-devices
[ 30%] Building CXX object libraries/lib-audio-devices/CMakeFiles/lib-audio-devices.dir/AudioIOBase.cpp.o
[ 30%] Building CXX object libraries/lib-audio-devices/CMakeFiles/lib-audio-devices.dir/DeviceChange.cpp.o
[ 30%] Building CXX object libraries/lib-audio-devices/CMakeFiles/lib-audio-devices.dir/DeviceManager.cpp.o
[ 30%] Building CXX object libraries/lib-audio-devices/CMakeFiles/lib-audio-devices.dir/Meter.cpp.o
[ 31%] Linking CXX shared library …/…/shared/Release/lib-audio-devices.so
/usr/bin/ld: …/…/lib-src/portmixer/libportmixer.a(px_mixer.c.o): relocation R_X86_64_32 against .text' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: ../../lib-src/portmixer/libportmixer.a(px_unix_oss.c.o): relocation R_X86_64_32S against .rodata’ can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: …/…/lib-src/portmixer/libportmixer.a(px_linux_alsa.c.o): relocation R_X86_64_32 against `.rodata.str1.1’ can not be used when making a shared object; recompile with -fPIC
collect2: error: ld returned 1 exit status
make[2]: *** [libraries/lib-audio-devices/CMakeFiles/lib-audio-devices.dir/build.make:156: shared/Release/lib-audio-devices.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:1596: libraries/lib-audio-devices/CMakeFiles/lib-audio-devices.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

CMakeError.log is unrevealing, as it only has an error related to the version of nasm.

CMakeOutput.txt is likewise unrevealing.

However, adding this line at about line 408 allowed the compile to finish:

set(CMAKE_POSITION_INDEPENDENT_CODE ON) at about line 408.

This, per the post here: https://stackoverflow.com/questions/38296756/what-is-the-idiomatic-way-in-cmake-to-add-the-fpic-compiler-option).

The library lib-audio-devices.so shows up here:

~/audacity/build/bin/Release/lib64/audacity/

sudo make install also completed.

Any comments to educate me greatly appreciated!

Sigh… I omitted that “However, adding this line at about line 408 allowed the compile to finish:” should reference the file ~/audacity/CMakeLists.txt>

The best place to ask about build problems is here: https://discord.gg/2ueFdhpg
(Remember to say which version of Fedora / RHEL you are using, and which exact version of Audacity source code.)

Audacity source code version 3.1.0. Fedora 34 x86_64.
Thank you!

So you would want to supply this information when you describe your issue on the #linux channel - COMPILING AUDACITY after you join Audacity-Dev on discord as Steve suggested.

I also have the same exact issue on FreeBSD 13 amd64 and adding that set(CMAKE_POSITION_INDEPENDENT_CODE ON) on line 408 also solved the compilation error.