1

I'm trying to build cx_Freeze on a 64-bit Mac with OS 10.9 and running 64 bit Python. The python I am running is the Anaconda python distribution for mac (64 bit). I have changed this to the default python.

The following error occurs when going into the cx_freeze source dir and running python setup.py build:

Creating build/lib.macosx-10.5-x86_64-2.7/cx_Freeze/bases
gcc -arch x86_64 build/temp.macosx-10.5-x86_64-2.7/source/bases/Console.o -L/Users/JJ/anaconda/lib -o build/lib.macosx-10.5-x86_64-2.7/cx_Freeze/bases/Console -s
ld: warning: option -s is obsolete and being ignored
Undefined symbols for architecture x86_64:
  "_PyDict_New", referenced from:
      _main in Console.o
  "_PyDict_SetItemString", referenced from:
      _main in Console.o
  "_PyErr_Print", referenced from:
      _main in Console.o
  "_PyEval_EvalCode", referenced from:
      _main in Console.o
  "_PyEval_GetBuiltins", referenced from:
      _main in Console.o
  "_PyImport_ImportModule", referenced from:
      _main in Console.o
  "_PyObject_CallMethod", referenced from:
      _main in Console.o
  "_PyString_FromString", referenced from:
      _main in Console.o
  "_PySys_SetArgv", referenced from:
      _main in Console.o
  "_Py_FatalError", referenced from:
      _main in Console.o
  "_Py_Finalize", referenced from:
      _main in Console.o
  "_Py_FrozenFlag", referenced from:
      _main in Console.o
  "_Py_IgnoreEnvironmentFlag", referenced from:
      _main in Console.o
  "_Py_Initialize", referenced from:
      _main in Console.o
  "_Py_IsInitialized", referenced from:
      _main in Console.o
  "_Py_NoSiteFlag", referenced from:
      _main in Console.o
  "_Py_SetProgramName", referenced from:
      _main in Console.o
  "_Py_SetPythonHome", referenced from:
      _main in Console.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'gcc' failed with exit status 1

What could be the issue here?

mr_js
  • 949
  • 12
  • 29
  • That's not nearly enough information to go on. How are you building it? What's the rest of the output (which would show us, among other things, what it's trying to link together when it gets this error)? Are you using Apple's Python or a third-party Python (and, if the latter, which one, and how did you install it)? – abarnert Nov 25 '14 at 20:23
  • Have updated the question with more info. – mr_js Nov 25 '14 at 20:35
  • All those missing functions are part of the standard C API. So clearly it's trying to build something (presumably an executable, given no flags for building libs, and the existence of a `_main`) that depends on the libpython .dylib/.framework/.a, but no such library is being linked in. (In other words, there should be a `-lpython` on that `gcc` command line.) As for why that's happening, I have no idea. – abarnert Nov 25 '14 at 20:56
  • Actually, one thing: What version of Anaconda do you have? How recent is it? Have you done anything to modify its standard distutils configuration? Because it's hard to imagine any recent Python distribution for the Mac would be set up to explicitly specify `gcc`. – abarnert Nov 25 '14 at 20:57
  • Anaconda is completely up to date. I have installed XCode, which may have influenced gcc. gcc -v gives:Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) Target: x86_64-apple-darwin13.1.0 – mr_js Nov 26 '14 at 05:11
  • The following answer explains why gcc is being invoked: http://stackoverflow.com/questions/5944228/python-build-using-wrong-version-of-gcc-on-os-x – mr_js Nov 26 '14 at 05:23
  • But that answer implies your Python was built with a very old version of Xcode, which is exactly why I was surprised that Anaconda would be distributing such a build today. (Xcode 5 and later install a fake `gcc` that's just a front-end to `clang`, and that should work on almost anything written for gcc 4.0, so that's not directly the problem. It's just that something else about your setup is weird, and that might be related to your weird setup.) – abarnert Nov 26 '14 at 20:01
  • A couple things to try: from the shell, do `python-config --libs` (making sure it's your Anaconda Python, of course). The first one should contain either `-lpython`, `-lpython2.7`, or `-framework Python`, probably along with the `-L` part you see in your output. If none of those are there, from Python, try `import distutils.sysconfig; print {k: distutils.sysconfig.get_config_var(k) for k in ('LIBRARY', 'LDLIBRARY', 'PYTHONFRAMEWORKDIR', 'LDFLAGS')}`. – abarnert Nov 26 '14 at 20:08
  • When I do python-config --libs I get: -ldl -framework CoreFoundation -lpython2.7. When I execute the python snippet I get: {'LDLIBRARY': 'libpython2.7.dylib', 'PYTHONFRAMEWORKDIR': 'no-framework', 'LIBRARY': 'libpython2.7.a', 'LDFLAGS': '-L/Users/JJ/anaconda/lib -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk'} – mr_js Nov 27 '14 at 19:21
  • I also adding the -lpython2.7 to the build by adding the following line to setup.py: extensions[1].extra_link_args=['-lypthon2.7']. Now it comes up with ld: library not found for -lypthon2.7. – mr_js Nov 27 '14 at 19:36
  • Spelling counts. Unless you're trying to build code for an interpreter named Ypthon, `-lypthon2.7` isn't going to work. – abarnert Dec 01 '14 at 20:09
  • Adding the flag `-lpython2.7` seemed to do the trick. But there appear to be path issues with cx-freeze: http://stackoverflow.com/questions/27256937/strange-error-using-cx-freeze-to-build-a-pyside-program-osx – mr_js Dec 02 '14 at 19:02

1 Answers1

2

One of the comments alluded to the fact that the gcc command should have a flag '-lpython' in it. This put me on the right track. I was able to fix the problem by adding the flags '-lpython2.7' when the Console.o and ConsoleKeepPath.o were being built. I achieved this by adding the following lines to the setup.py file in the downloaded cx_Freeze-4.3.3 directory:

extensions[1].extra_link_args=['-lpython2.7']
extensions[2].extra_link_args=['-lpython2.7']

There are 3 elements in extension so I used extension[x].name to find the right ones. With this done, I was able to build and install using the standard python distutils.

mr_js
  • 949
  • 12
  • 29
  • You shouldn't _need_ to do this, unless either cx_Freeze's setup or Anaconda's config settings are wrong. The latter seems much more likely, especially since the website claims the current installers are for 10.7+ but yours has distutils settings clearly aimed at 10.5+. You might want to work on fixing that. But if this workaround is good enough for you, I guess that's fine. – abarnert Dec 02 '14 at 19:28