question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fortran extensions on OSX, issue with defining LDFLAGS

See original GitHub issue

I ran into a problem while trying to build a conda package (https://github.com/praxes/hedm-conda-recipes/tree/master/imaged11) for a project with fortran extensions. python setup.py build works fine, but if`conda build`` simply invokes that same command, I get a string of errors about f2py not finding python symbols:

[...]
compiling Fortran sources
Fortran f77 compiler: /Users/darren/.conda/envs/_build/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -arch x86_64 -fPIC -O3 -funroll-loops
Fortran f90 compiler: /Users/darren/.conda/envs/_build/bin/gfortran -fopenmp -O2 -arch x86_64 -fPIC -O3 -funroll-loops
Fortran fix compiler: /Users/darren/.conda/envs/_build/bin/gfortran -Wall -g -ffixed-form -fno-second-underscore -fopenmp -O2 -arch x86_64 -fPIC -O3 -funroll-loops
creating build/temp.macosx-10.5-x86_64-2.7/fsrc
compile options: '-Ibuild/src.macosx-10.5-x86_64-2.7 -I/Users/darren/.conda/envs/_build/lib/python2.7/site-packages/numpy/core/include -I/Users/darren/.conda/envs/_build/include/python2.7 -c'
gfortran:f90: fsrc/fImageD11.f90
/Users/darren/.conda/envs/_build/bin/gfortran -Wall -g -Wl,-rpath,/Users/darren/.conda/envs/_build/lib -arch x86_64 build/temp.macosx-10.5-x86_64-2.7/build/src.macosx-10.5-x86_64-2.7/fImageD11module.o build/temp.macosx-10.5-x86_64-2.7/build/src.macosx-10.5-x86_64-2.7/fortranobject.o build/temp.macosx-10.5-x86_64-2.7/fsrc/fImageD11.o -L/Users/darren/.conda/envs/_build/lib/gcc/x86_64-apple-darwin11.4.2/4.8.5 -L/Users/darren/.conda/envs/_build/lib -lgomp -lpthread -lgfortran -o build/lib.macosx-10.5-x86_64-2.7/ImageD11/fImageD11.so
Undefined symbols for architecture x86_64:
  "_PyArg_ParseTupleAndKeywords", referenced from:
      _f2py_rout_fImageD11_compute_xlylzl in fImageD11module.o
      _f2py_rout_fImageD11_assign in fImageD11module.o
      _f2py_rout_fImageD11_compute_gv in fImageD11module.o
  "_PyCObject_AsVoidPtr", referenced from:
      _initfImageD11 in fImageD11module.o
      _F2PyCapsule_AsVoidPtr in fortranobject.o
  "_PyCObject_FromVoidPtr", referenced from:
      _fortran_getattr in fortranobject.o
      _F2PyCapsule_FromVoidPtr in fortranobject.o
[...]

What I found was that conda build defines LDFLAGS= -Wl,-rpath,/Users/darren/.conda/envs/_build/lib -arch x86_64, and if I unset LDFLAGS in my conda recipe’s build script, the package will compile. I asked about it on the conda mailing list, and someone replied that it appears f2py does not extend user-defined LDFLAGS, but instead let’s user-defined LDFLAGS overwrite its own (https://lists.macosforge.org/pipermail/macports-users/2010-November/022574.html), which on osx include “-undefined dynamic_lookup -bundle”. As it stands, it appears that anyone who needs to build a conda package on osx that includes fortran extensions will have to add the following to their build scripts:

LDFLAGS="$LDFLAGS -undefined dynamic_lookup -bundle"

Could f2py or numpy distutils extend user’s LDFLAGS with these required settings?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
isurufcommented, Jul 7, 2018

Question: is it just annoying, or does it actually prevent some things you want to do?

At conda-forge, we set some LDFLAGS for external libraries to be found (-L$PREFIX/lib) and flags like -headerpad_max_install_names. This is done for all packages using compilers, not just python packages. Flags in LDFLAGS env var is meant to be appended in every other build system including python’s distutils, so that’s why conda-forge sets it.

0reactions
charriscommented, Dec 16, 2018

Done in #12551 I think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clang linking error MacOS Big Sur | Apple Developer Forums
Hi All, I am trying to build my helloworld.cpp, but I am having problem since I updated to Big Sur. Below a verbose...
Read more >
Visual Studio Code C/C++/Fortran with Multiple Source Files
Tutorial how to setup Visual Studio Code for easy compilation of multiple source files (C/C++/Fortran) and setup of compilers on Mac, Linux, and...
Read more >
Writing R Extensions - The Comprehensive R Archive Network
Installing a source package which contains C, C++ or Fortran code will involve compiling that code. There is also the possibility of 'byte'...
Read more >
Absoft Pro Fortran User Guide
Pro Fortran. User Guide. Mac OS X. With Intel Processors. 2075 West Big Beaver Road, Suite 250. Troy, MI 48084. U.S.A.. Tel (248)...
Read more >
Unable to link BLAS and LAPACK in makefile using gfortran ...
I followed the answer of Mead from this post and ran brew install gfortran and that solved the issue for me.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found