Fails to build on FreeBSD

Issue #100 resolved
yurivict created an issue
building 'PETSc' extension
/usr/local/bin/mpicc -O2 -pipe -fstack-protector -fno-strict-aliasing -msse2 -fPIC -fPIC -O2 -pipe -fno-omit-frame-pointer -fstack-protector -fno-strict-aliasing -DPETSC_DIR=/usr/local -I/usr/local/include -Isrc/include -I/usr/local/lib/python2.7/site-packages/numpy/core/include -I/usr/local/include/python2.7 -c src/PETSc.c -o build/temp.freebsd-11.1-STABLE-amd64-2.7/src/PETSc.o
/usr/local/bin/mpicc -O2 -pipe -fstack-protector -fno-strict-aliasing -msse2 -fPIC -fPIC -O2 -pipe -fno-omit-frame-pointer -fstack-protector -fno-strict-aliasing -DPETSC_DIR=/usr/local -I/usr/local/include -Isrc/include -I/usr/local/lib/python2.7/site-packages/numpy/core/include -I/usr/local/include/python2.7 -c src/libpetsc4py.c -o build/temp.freebsd-11.1-STABLE-amd64-2.7/src/libpetsc4py.o
/usr/local/bin/mpicc -L/usr/local/lib -Wl,-rpath=/usr/local/lib/gcc6 -L/usr/local/lib/gcc6 -B/usr/local/bin -fstack-protector -O2 -pipe -fstack-protector -fno-strict-aliasing -msse2 -fPIC cc -shared -fstack-protector build/temp.freebsd-11.1-STABLE-amd64-2.7/src/PETSc.o build/temp.freebsd-11.1-STABLE-amd64-2.7/src/libpetsc4py.o -L/usr/local/lib -L/usr/local/lib -Wl,-rpath=/usr/local/lib -lpetsc -lpython2.7 -o build/lib.freebsd-11.1-STABLE-amd64-2.7/petsc4py/lib/PETSc.so
gcc6: error: cc: No such file or directory

Comments (19)

  1. Lisandro Dalcin

    Your build environment seems to be broken. Are you able to compile a minimal MPI code (look for helloworld.c in mpi4py sources) using the mpicc compiler wrapper?

  2. Lisandro Dalcin

    Oh, now I see the problem. Could you enter the interactive python prompt and tell me the output of the following lines?

    >>> from distutils import sysconfig
    >>> sysconfig.get_config_var('CC')
    >>> sysconfig.get_config_var('LDSHARED')
    
  3. yurivict reporter
    $ python2.7
    Python 2.7.15 (default, May 13 2018, 01:10:00) 
    [GCC 4.2.1 Compatible FreeBSD Clang 4.0.0 (tags/RELEASE_400/final 297347)] on freebsd11
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from distutils import sysconfig
    >>> sysconfig.get_config_var('CC')
    'cc'
    >>> sysconfig.get_config_var('LDSHARED')
    'cc -shared -lpthread -L/usr/local/lib  -fstack-protector'
    >>> 
    
  4. Lisandro Dalcin

    Ups, I was expecting LDFLAGS to not start with CC. Now I have no clue what's going on. At this point I would need your help to debug the issue. All the logics are in conf/baseconf.py. Can you add print(PLD_SHARED) right before the call to compiler.set_executables(...) and tell me the output ?

  5. yurivict reporter

    print(PLD_SHARED) prints

    /usr/local/bin/mpicc  -L/usr/local/lib -Wl,-rpath=/usr/local/lib/gcc6  -L/usr/local/lib/gcc6 -B/usr/local/bin -fstack-protector  -O2 -pipe  -fstack-protector -fno-strict-aliasing -msse2 -fPIC cc -shared  -fstack-protector
    

    cc in the beginning explains the failure. Removing cc from the command line lets the build to succeed.

  6. Lisandro Dalcin

    Can you somehow run that under the Python debugger of add a few more print() lines around to figure out where the bug comes from? The problem may be in this line:

    ldshared = [flg for flg in split_quoted(ldshared) if flg not in ldcmd].

  7. Lisandro Dalcin

    Sorry for the trouble, all this is nasty code, but Python's distutils makes it so damn hard to alter compiler/linker commands... As I don't have access to a FreeBSD box, I really need your assistance to figure out the source of the bug.

  8. yurivict reporter

    ldshared=cc -shared introduces cc through this line: PLD_SHARED = str.join(' ', (PLD, ldshared, ldflags))

    Obviously, LDFLAGS with leading cc brings it in.

  9. Lisandro Dalcin

    Yes, but please look above, an below the commend # distutils linker. After that block, the variable ldshared is supposed to not start with cc. I cannot figure out yet why cc is not removed.

  10. Lisandro Dalcin

    The problem is that anyone out there that builds Python from sources (Apple, Homebrew, Linux distros, Anaconda Python, etc. etc.) all them play tricks with compiler flags and the installed Python makefile from where these flags are taken endup being inconsistent across platforms and distributions and python versions, so it is really a nightmare to get things right for all the cases.

  11. yurivict reporter

    After this line:

            (ldflags, ldshared, so_ext) = get_config_vars(
                'LDFLAGS', 'LDSHARED', 'SO')
    

    ldshared=cc -shared -lpthread -L/usr/local/lib -fstack-protector - same as get_config_vars('LDSHARED')

    After this line:

    ldshared = str.join(' ', ldshared)
    

    ldshared=-shared -- the updated value

    Then this line:

    ldshared = getenv('LDSHARED', ldshared)
    

    sets in to the environment variable LDSHARED, which has the value cc -shared and it stays this way, with cc.

  12. Lisandro Dalcin

    So then you have an environment variable LDSHARED set?? From where does it came from? Did you set it or does it come from some outer buildsystem you are using (e.g. some package builder)?

  13. yurivict reporter

    Port infrastructure sets this variable for all python ports for some reason: LDSHARED?= ${CC} -shared

  14. Log in to comment