Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mac] Make cefpython work with the Python.org pkg installer #378

Closed
cztomczak opened this issue Jul 30, 2017 · 2 comments
Closed

[Mac] Make cefpython work with the Python.org pkg installer #378

cztomczak opened this issue Jul 30, 2017 · 2 comments

Comments

@cztomczak
Copy link
Owner

cztomczak commented Jul 30, 2017

There are issues running cefpython when using Python.org binaries (the .pkg installer) for Mac, the CEF browser loads, but the window is blank. This issue was originally reported on the Forum in this topic. It might be caused (this still needs to be investigated further and confirmed) because these binaries are built with gcc 4.2 and cefpython module is built with clang and links against stdlib libc++. The solution might be to build the cefpython module with gcc compiler instead of clang/libc++. The required modifications would need to be done in the build.py and cython_setup.py tools.

In build.py here:

        # Compile against libc++ otherwise error "symbol not found"
        # with cef::logging::LogMessage symbol. Also include -lc++
        # and -lc++abi libraries.
        os.environ["CEF_CCFLAGS"] += " -stdlib=libc++"

        # See compile/link flags in upstream cefclient
        os.environ["CEF_CCFLAGS"] += (
                " -fno-strict-aliasing"
                " -fno-rtti"
                " -fno-threadsafe-statics"
                " -fobjc-call-cxx-cdtors"
                " -fvisibility=hidden"
                " -fvisibility-inlines-hidden"
        )
        os.environ["CEF_LINK_FLAGS"] += (
                " -lc++"
                " -lc++abi"
                " -Wl,-search_paths_first"
                " -Wl,-ObjC"
                " -Wl,-pie"
                " -Wl,-dead_strip"
        )

Ref:

# Compile against libc++ otherwise error "symbol not found"

In cython_setup.py here:

        extra_compile_args.extend([
                # Compile against libc++ otherwise error "symbol not found"
                # with cef::logging::LogMessage symbol. Also include -lc++
                # and -lc++abi libraries.
                "-stdlib=libc++",
                "-Wno-return-type-c-linkage",
                "-Wno-constant-logical-operand",
        ])

Ref:

extra_compile_args.extend([

See also this post on the Forum that explains the clang/libc++ linking in some more details:

There seem to be two signifcant differences between that I think might be the cause of the issue:

  1. I think the issue might be caused because the cefpython module was built using clang and linked against libc++ and the Python.org package is built with an old version of gcc 4.2. It seems that Python.org package is built with gcc 4.2 compiler while system Python 2.7 is built with clang compiler. I've checked also Homebrew Python that works fine with cefpython and it seems that it is also built with clang compiler (it checks for ENV.compiler option). I think that Chromium/CEF can work with both gcc and clang compilers, however I've had problems with making it work with gcc compiler. So the cefpython module links against libc++. Since Chromium v56 the minimum OS supported is MacOS 10.9+. MacOS 10.9+ no longer uses GCC/libstdc++, but uses libc++ and Clang. So it is okay for cefpython to be built with clang and linked against libc++, as the minimum requirements for Chromium do support this (Mac OS 10.9+).

  2. I wonder if the --enable-universalsdk=/Developer/SDKs/MacOSX10.6.sdk flag is causing any issue, but it's a little chance I think.

I think that the issue can be resolved if you build Python yourself. Download Python sources from Python.org and build it with the --enable-framework flag. Make sure that Python builds with clang. If you're using Mac OS 10.9 or higher that should be the default. The Python.org binaries that you've installed were built with gcc 4.2, so that it supports old OSes (Mac OS 10.6+).

I am not sure if anything can be done (and should) the cefpython side. It is how things work on Mac. They replaced the default compiler to clang/libc++ on Mac OS 10.9. And Mac OS 10.9 is the minimum requirement for cefpython/CEF/Chromium. The minimum supported version of gcc supported by Chromium is gcc 4.8+.

Ref: https://groups.google.com/d/msg/cefpython/NxqAmhuSQPM/KIBJ4pvAAgAJ

CEF Python works fine on these Python configurations

  1. CEF Python works fine when running system Python on Mac (the preinstalled Python on a fresh Mac OS).
  2. CEF Python also works fine running Python 3 installed with the Homebrew package manager.
  3. CEF Python should also run fine with Python built using Python.org sources on Mac OS 10.9+ when built using clang compiler and the --enable-framework flag.

Config flags for Python.org binaries 3.5.1

'--enable-framework'
'--enable-universalsdk=/Developer/SDKs/MacOSX10.6.sdk'
'--with-universal-archs=intel'
'--with-computed-gotos'
'--without-ensurepip'
'-C'
'LDFLAGS=-g'
'CFLAGS=-g'
'CC=gcc-4.2'

Config flags for system Python 2.7

'--prefix=/usr'
'--mandir=/usr/share/man'
'--infodir=/usr/share/info'
'--disable-dependency-tracking'
'--enable-ipv6'
'--with-system-expat'
'--with-threads'
'--enable-framework=/System/Library/Frameworks'
'--enable-toolbox-glue'
'--with-system-ffi'
'CC=cc'
'CFLAGS=-arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32'
'LDFLAGS=-arch x86_64 -arch i386 -Wl,-F.'

Config flags for Homebrew Python

See https://github.com/Homebrew/homebrew-core/blob/master/Formula/python3.rb

@cztomczak
Copy link
Owner Author

To build with gcc the error "symbol not found" with cef::logging::LogMessage symbol needs to be resolved. Related issue for this error: Issue #230 ("Error when importing the CEF Python 47 module: undefined symbol: cef::logging::LogMessage").

The issue is caused when including the src/include/base/cef_logging.h header file. A possible solution for this "symbol not found" error might be to create cef_logging.cpp in "src/client_handler/" directory and include it when building/linking the cefpython module, so that no required symbols are stripped during compile/link operations.

@cztomczak cztomczak changed the title Mac: Make cefpython work with the Python.org .pkg installer [Mac] Make cefpython work with the Python.org pkg installer Aug 23, 2017
@cztomczak
Copy link
Owner Author

It's already explained in the Knowledge-Base.md document that Python on Mac needs to be built as a framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant