[Scons-users] scons adds option -KPIC also for gcc/g++ on platform solarisx86

Mats Wichmann mats at wichmann.us
Fri May 21 09:29:21 EDT 2021


On 5/21/21 2:49 AM, ajusic at gmx.de wrote:
> Dear scons maintainer,
> I didn't find any workarounds or hints or bug entires for scons on 
> stackoverflow or openhub or somewhere else regarding the problem that 
> scons adds -KPIC compiler option even for gcc/g++ compiler which leads 
> to the error with message
> "g++: error: unrecognized command line option '-KPIC'
> -KPIC was introduced with scons 0.96.91 and is valid for sun compiler 
> suncc, but not for gcc.
> My flags are:
> env['CCFLAGS']   += ' -m64 -DSOLARIS -D_M_IX86 -D_REENTRANT 
> -D_POSIX_PTHREAD_SEMANTICS -mfpmath=387 -fPIC -std=c99 '
> env['CXXFLAGS']  += ''
> env['LINKFLAGS']   = ' -lsocket -m64 -fPIC '
> env['SHLINKFLAGS'] = ' -shared -m64 '
> env['SHCXXFLAGS']  = ' -shared -m64 '
> env['SHCXX']       = ' g++ '
> Platform is solaris x86 with Oracle Corporation SunOS 5.10 Generic Patch 
> January 2005
> gcc 5.5.0
> scons v2.5.1.rel_2.5.1
> ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.1514
> Please let me know if there is any workaround.

Can you just rewrite SHCCFLAGS and SHCXXFLAGS after the environment is 
created? You seem to be doing SHCXXFLAGS already from the above.

You can print them out to see what they get set to as a debugging step, 
if you haven't already, Would expect these to look like:

SHCCFLAGS: ['$CCFLAGS', '-KPIC']
SHCXXFLAGS: ['$CXXFLAGS', '-KPIC']

You can just *set* them, you don't have to add to the existing, but do 
use the parametereized versions of CCFLAGS and CXXFLAGS so those will be 
correctly expanded and you don't have to repeat what was assigned to the 
not-shared versions. You can assign directly like you do above or use 
env.Replace, e.g.:

env.Replace(SHCCFLAGS=['$CCFLAGS', '-fPIC'])

(or whatever value you actually need)

or replace actually in the list, perhaps like:

try:
     idx = env['SHCCFLAGS'].index('-KPIC')
except ValueError:
     pass
else:
     env['SHCCFLAGS'][idx] = '-fPIC'


(if the above look a little more complicated than might be needed: the 
CCFLAGS type variables are initialized using an internal type, 
SCons.Util.CLVar, which is not mentioned in the documentation (sigh), 
it's a list but with special rules for strings with spaces on creation 
and addition so those are turned into lists and don't get type clashes). 
That's why the sun* tools do this kind of thing if you look in the 
source code:

env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS -KPIC')


More information about the Scons-users mailing list