﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	blockedby	blocking	notify_on_close	platform	project
2087	Problem with distutils-generated loader flags	tic20@…	Conrad Huang	"{{{
The following bug report has been submitted:
Platform:        Linux-3.10.0-957.12.2.el7.x86_64-x86_64-with-centos-7.6.1810-Core
ChimeraX Version: 0.9 (2019-06-06)
Description
This is perhaps more of a DistUtils bug than a ChimeraX one, but I run into it afresh whenever I try to install into ChimeraX any package that requires compiling and linking. If you look in ChimeraX/lib/python3.7/distutils/unixccompiler.py, at line 212 you'll find the following method:

{{{
    def runtime_library_dir_option(self, dir):
        # XXX Hackish, at the very least.  See Python bug #445902:
        # http://sourceforge.net/tracker/index.php
        #   ?func=detail&aid=445902&group_id=5470&atid=105470
        # Linkers on different platforms need different options to
        # specify that directories need to be added to the list of
        # directories searched for dependencies when a dynamic library
        # is sought.  GCC on GNU systems (Linux, FreeBSD, ...) has to
        # be told to pass the -R option through to the linker, whereas
        # other compilers and gcc on other systems just know this.
        # Other compilers may need something slightly different.  At
        # this time, there's no way to determine this information from
        # the configuration data stored in the Python installation, so
        # we use this hack.
        compiler = os.path.basename(sysconfig.get_config_var(""CC""))
        if sys.platform[:6] == ""darwin"":
            # MacOSX's linker doesn't understand the -R flag at all
            return ""-L"" + dir
        elif sys.platform[:7] == ""freebsd"":
            return ""-Wl,-rpath="" + dir
        elif sys.platform[:5] == ""hp-ux"":
            if self._is_gcc(compiler):
                return [""-Wl,+s"", ""-L"" + dir]
            return [""+s"", ""-L"" + dir]
        else:
            if self._is_gcc(compiler):
                # gcc on non-GNU systems does not need -Wl, but can
                # use it anyway.  Since distutils has always passed in
                # -Wl whenever gcc was used in the past it is probably
                # safest to keep doing so.
                if sysconfig.get_config_var(""GNULD"") == ""yes"":
                    # GNU ld needs an extra option to get a RUNPATH
                    # instead of just an RPATH.
                    return ""-Wl,--enable-new-dtags,-R"" + dir
                else:
                    return ""-Wl,-R"" + dir
            else:
                # No idea how --enable-new-dtags would be passed on to
                # ld if this system was using GNU ld.  Don't know if a
                # system like this even exists.
                return ""-R"" + dir
}}}

The problem here is that if I run `sysconfig.get_config_var('CC')` from within ChimeraX, I get:

'gcc -pipe -fPIC -std=gnu99 -fdebug-prefix-map=/tmp/chx-v0.9.pFsGzN/build=. -fstack-protector-strong  -I/tmp/chx-v0.9.pFsGzN/build/include -L/tmp/chx-v0.9.pFsGzN/build/lib -DUSE_DYLD_GLOBAL_NAMESPACE -pthread'

... which the call to os.path.basename makes a mess of parsing, so the compiler variable ends up with the value:

'lib -DUSE_DYLD_GLOBAL_NAMESPACE -pthread'

... causing the method to default to the final ""No idea how..."" option and return ""-R"" + dir, which in turn causes GCC to crash at the linking stage.

At the moment I just work around it by replacing that branch with the correct return string for my system (-Wl,--enable-new-dtags,-R). 

Same bug is discussed at https://github.com/ContinuumIO/anaconda-issues/issues/6340. Seems if you can strip the -fdebug-prefix-map, -I and -L arguments out (which shouldn't be a problem - looks like these are only relevant to your original build) then it should be fine - it's only the arguments with a ""/"" in them that confuse basename().

Log:
UCSF ChimeraX version: 0.9 (2019-06-06)  
© 2016-2019 Regents of the University of California. All rights reserved.  
How to cite UCSF ChimeraX  

> toolshed show Shell

/opt/UCSF/ChimeraX/lib/python3.7/site-packages/IPython/core/history.py:226:
UserWarning: IPython History requires SQLite, your history will not be saved  
warn(""IPython History requires SQLite, your history will not be saved"")  




OpenGL version: 3.3.0 NVIDIA 415.27
OpenGL renderer: TITAN Xp/PCIe/SSE2
OpenGL vendor: NVIDIA Corporation

}}}
"	defect	closed	normal		Tool Shed		fixed						all	ChimeraX
