Build of http://subversion.ffado.org/ffado/branches/libffado-2.0 on (rev 1319) x86-64 with PIC enabled in CFLAGS fails with this:
gcc -o external/libconfig/grammar.o -c -DDEBUG -Wall -g -m64 -DDEBUG -Wall -g -DDBUS_HAS_THREADS_INIT_DEFAULT -m64 -Iexternal/libconfig external/libconfig/grammar.c
gcc -o external/libconfig/libconfig.o -c -DDEBUG -Wall -g -m64 -DDEBUG -Wall -g -DDBUS_HAS_THREADS_INIT_DEFAULT -m64 -Iexternal/libconfig external/libconfig/libconfig.c
g++ -o external/libconfig/libconfigcpp.o -c -DDEBUG -Wall -g -DDBUS_HAS_THREADS_INIT_DEFAULT -m64 -Iexternal/libconfig external/libconfig/libconfigcpp.cpp
gcc -o external/libconfig/scanner.o -c -DDEBUG -Wall -g -m64 -DDEBUG -Wall -g -DDBUS_HAS_THREADS_INIT_DEFAULT -m64 -Iexternal/libconfig external/libconfig/scanner.c
scanner.c:1527: warning: 'input' defined but not used
ar rc external/libconfig/libconfigpp.a external/libconfig/grammar.o external/libconfig/libconfig.o external/libconfig/libconfigcpp.o external/libconfig/scanner.o
ranlib external/libconfig/libconfigpp.a
g++ -o src/libffado.so -shared [ lots of objects ] -Lexternal/libconfig -lconfigpp [ lots of libs ]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.1/../../../../x86_64-pc-linux-gnu/bin/ld: external/libconfig/libconfigpp.a(libconfigcpp.o): relocation R_X86_64_32S against `vtable for libconfig::SettingException?' can not be used when making a shared object; recompile with -fPIC
external/libconfig/libconfigpp.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
scons: *** [src/libffado.so] Error 1
scons: building terminated because of errors.
! Problem Detected !
The trouble originates in the build of external/libconfig/libconfigpp.a as a static library and then trying to incorporate that into a shared library.
SCons disables the -fPIC flag (which is included in environment CFLAGS) for the build of a static library.
When I hack the corresponding SCons config file in external/libconfig to force -fPIC on CFLAGS the build completes fine.
Something like that in external/libconfig/SConscript:
env.AppendUnique?( CCFLAGS=-fPIC? )
This may not be needed on x86, but it is for x86-64 where you should always compile with PIC (this will apply to alpha arch, too, most probably -- yes I still have such a thing and playfully think about trying firewire with it;-).
So, is there a clean way to just make SCons honour the given -fPIC in CFLAGS, even for the static library (that is going to be part of a dynamic library)?
Otherwise I'll have to hack our (Source Mage GNU/Linux) build scripts to patch in the -fPIC for external/libconfig/libconfigpp.a in case we build for a x86-64 box.