[Scons-users] linker command under windows not working (too long)
Philipp Kraus
philipp.kraus at flashpixx.de
Mon Apr 1 08:38:42 EDT 2013
Hi,
s
Am 01.04.2013 um 03:39 schrieb William Deegan:
> Take a look at this bit of logic.. It's how the path to the temp file is rendered on the command line:
> if (env['SHELL'] and env['SHELL'] == 'sh') :
> native_tmp = native_tmp.replace('\\', r'\\\\')
^^^^^^^
This was a little typo error on copy & past the code, I use replace('\\', r'\\'). I have used the original Scons
code from the platform/__init__.py script. I have added only
if "mingw" in env['platform'] :
args = [i.replace('\\', r'\\') for i in args]
but another difference is the "$TARGET", but I can not get a working solution with the tempfile. The tempfile call
in the linkcom create more linker errors.
Another inconsistence is, that the SHLINKCOM is a Scons.Action object and the LINKCOM a string.
The difference is also, that in the LINKCOM on gcc the part "-o $TARGET" exists, but in the SHLINKCOM not.
If I do str(env["SHLINKCOM"]).replace("$SOURCE", "${TEMPFILE('$SOURCE')} the created statement creates
a linker error, because the -o $TARGET part does not exists. (This problem exists on Scons 2.3.0 devel & 2.2 stable).
My working solution without the tempfile is a manual code
obj = envlib.SharedObject(srclibrary)
resource = "tempfile.res"
with open(resource, "w") as f:
for obj_name in obj:
f.write ("%s\n" %os.path.abspath(str(obj_name)).replace("\\", "/"))
envlib.AppendUnique(LINKFLAGS = ["@"+resource])
lib = envlib.SharedObject("mytarget", [])
Depend(lib, obj)
The tempfile call is IMHO not usable at the moment, because path escaping are creates errors, linker commands are
inconsistent after adding the tempfile (I found the difference after debugging the env object and print the full linker
command to a file)
> rm = env.Detect('rm') or 'del'
> else:
> rm = 'del'
>
> The 'native_tmp" bit..
>
> -Bill
> On Mar 31, 2013, at 6:07 PM, Philipp Kraus <philipp.kraus at flashpixx.de> wrote:
>
>> I have create this configuration
>>
>> envlib["TEMPFILE"] = BuildTempFile
>> envlib["SHLINKCOM"] = "$SHLINK -o $TARGET $SHLINKFLAGS ${TEMPFILE('$SOURCES')} $_LIBDIRFLAGS $_LIBFLAGS"
>>
>>
>> and the temp build class:
>>
>> class BuildTempFile(object):
>> def __init__(self, cmd):
>> self.cmd = cmd
>> def __call__(self, target, source, env, for_signature):
>> if for_signature:
>> return self.cmd
>>
>> cmd = env.subst_list(self.cmd, SCons.Subst.SUBST_CMD, target, source)[0]
>> try:
>> maxline = int(env.subst('$MAXLINELENGTH'))
>> except ValueError:
>> maxline = 2048
>>
>> length = 0
>> for c in cmd:
>> length += len(c)
>> if length <= maxline:
>> return self.cmd
>>
>> (fd, tmp) = tempfile.mkstemp('.lnk', text=True)
>> native_tmp = SCons.Util.get_native_path(os.path.normpath(tmp))
>>
>> if (env['SHELL'] and env['SHELL'] == 'sh') :
>> native_tmp = native_tmp.replace('\\', r'\\\\')
>> rm = env.Detect('rm') or 'del'
>> else:
>> rm = 'del'
>>
>> prefix = env.subst('$TEMPFILEPREFIX')
>> if not prefix:
>> prefix = '@'
>>
>> args = list(map(SCons.Subst.quote_spaces, cmd[1:]))
>> if "mingw" in env['platform'] :
>> args = [i.replace('\\', r'\\') for i in args]
>>
>> os.write(fd, " ".join(args) + "\n")
>> os.close(fd)
>> if SCons.Action.print_actions:
>> print("Using tempfile "+native_tmp+" for command line:\n"+
>> str(cmd[0]) + " " + " ".join(args))
>> return [ cmd[0], prefix + native_tmp + '\n' + rm, native_tmp ]
>>
>> but Scons create the wrong command:
>>
>> g++ -o Irrlicht.dll -Wl,--add-stdcall-alias -Wl,--kill-at -shared source\Irrlicht\C3DSMeshFileLoader.o @c:\users\admini~1\appdata\local\temp\tmpzk1l0n.lnk
>>
>> IMHO all *.o files should be in the temporary file.
>>
>>
>> On 2013-04-01 00:08:56 +0200, Philipp Kraus said:
>>
>> On shared lib I must modifiy SHLINKCOM but on MinGW seems to be an error in
>> correct escaping path names (see the platform/__init__.py script and the class TempFileMunge)
>>
>> the line in the method __call__
>> args = list(map(SCons.Subst.quote_spaces, cmd[1:]))
>>
>> must be a correct path escaping eg
>> if "mingw" in env['platform'] :
>> args = [i.replace('\\', r'\\\\') for i in args]
>>
>> because on MinGW toolset, that is run direct in Windows command line
>> the pathes are stored only with \ but must be \\
>>
>> Phil
>>
>>
>> On 2013-03-31 17:44:05 +0200, Philipp Kraus said:
>>
>> I have set my linker command to
>> envlib["LINKCOM"] = "${TEMPFILE('"+envlib["LINKCOM"]+"')}"
>>
>> the tempfile is set on default to Scons TempFileMunge
>> and the prefix stores the @ char.
>> But my object files are not passed to the file and the linker command
>> is also gcc <o files>, so it is not modified with the tempfile
>>
>> I'm a little bit confused
>>
>> Thx
>>
>> Phil
>>
>>
>> On 2013-03-31 14:34:26 +0200, Philipp Kraus said:
>>
>> Is there an example for the callable class? Because which information must be returned by the callable method?
>>
>>
>> Am 31.03.2013 um 03:17 schrieb Bill Deegan:
>> Won't TEMPFILE work for this?
>>
>> A callable class. You can set an Environment variable to this,
>> then call it with a string argument, then it will perform temporary
>> file substitution on it. This is used to circumvent the long command
>> line limitation.
>>
>> Example usage:
>> env["TEMPFILE"] = TempFileMunge
>> env["LINKCOM"] = "${TEMPFILE('$LINK $TARGET $SOURCES')}"
>>
>> By default, the name of the temporary file used begins with a
>> prefix of '@'. This may be configred for other tool chains by
>> setting '$TEMPFILEPREFIX'.
>>
>> env["TEMPFILEPREFIX"] = '-@' # diab compiler
>> env["TEMPFILEPREFIX"] = '-via' # arm tool chain
>>
>> -Bill
>>
>>
>> On Sat, Mar 30, 2013 at 11:26 AM, Philipp Kraus <philipp.kraus at flashpixx.de> wrote:
>> Hi,
>>
>>
>>
>> thanks for this idea but I don't use the env.Object call, I call env.SharedLibrary direct in the build script, so the *.o file is created by the dependency graph that is build by Scons.
>>
>> So I need to change my script for the MinGW toolset and create the object files first and referenced them via the file. It should be a IMHO a "hacking solution".
>>
>>
>>
>> Thanks a lot, so I can test my build script
>>
>>
>>
>> Phil
>>
>>
>>
>>
>>
>> On 2013-03-30 19:07:42 +0100, Brady Johnson said:
>>
>>
>>
>>
>>
>> You can use response files, (supported by both gcc and msvc) which allows you to list several object files, etc in a file, then refer to that file on the command line prepending it with the '@' symbol. Here is a question/answer on Stack Overflow that addresses this: http://stackoverflow.com/q/15242177/1158895
>>
>>
>>
>> Notice, though that SCons wont read what's in the response file, so dependency checking wont work as expected. I addressed this in my answer to the Stack Overflow question.
>>
>>
>>
>> Hope that helps,
>>
>>
>>
>> Brady
>>
>>
>>
>>
>>
>>
>>
>> On Sat, Mar 30, 2013 at 3:07 PM, Philipp Kraus <philipp.kraus at flashpixx.de> wrote:
>>
>> Hello,
>>
>>
>>
>> I try to build Irrlicht engine with mingw toolset under Scons. The compiler calls works well, but the last linker command to build the shared library creates the error, that the command length is reached.
>>
>> MS describe the probleme here http://support.microsoft.com/kb/830473/en-us
>>
>> The command shows:
>>
>>
>>
>> g++ -shared -o Irrlicht.dll <here all *.o files> -Wl,--out-implib,libIrrlicht.a
>>
>>
>>
>> I don't know how I can solve this problems. The problem exists only with the MinGW toolset under MSVC the problem does not exists.
>>
>>
>>
>> Thanks for help
>>
>>
>>
>> Phil
>>
>>
>>
>>
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org
>> http://four.pairlist.net/mailman/listinfo/scons-users
>>
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org
>> http://four.pairlist.net/mailman/listinfo/scons-users
>>
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org
>> http://four.pairlist.net/mailman/listinfo/scons-users
>>
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org
>> http://four.pairlist.net/mailman/listinfo/scons-users
>>
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org
>> http://four.pairlist.net/mailman/listinfo/scons-users
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> http://four.pairlist.net/mailman/listinfo/scons-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://four.pairlist.net/pipermail/scons-users/attachments/20130401/249aabb8/attachment-0001.html>
More information about the Scons-users
mailing list