TNG/boost-python-examples

`Could NOT find Boost: missing: python37`

kldavis4 opened this issue · 6 comments

I'm having trouble getting these to build with homebrew python3 on mojave. I have installed boost and boost-python3 and made the following changes to build.sh to tell it to use python3:

 if [[ "$OSTYPE" == "linux-gnu" || "$OSTYPE" == "linux" ]]; then
     cmake -DPYTHON_VERSION_SUFFIX=-py3 -DCMAKE_BUILD_TYPE=DEBUG .. && make && make test
 elif [[ "$OSTYPE" == "darwin"* ]]; then
-    PYTHON_VERSION=`python -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)";`
+    PYTHON_VERSION=`python3 -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)";`
     PYTHON_LIBRARY=/usr/local/Frameworks/Python.framework/Versions/$PYTHON_VERSION/lib/libpython$PYTHON_VERSION.dylib
     PYTHON_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Versions/$PYTHON_VERSION/Headers/
-    cmake -DPYTHON_LIBRARY=$PYTHON_LIBRARY -DPYTHON_INCLUDE_DIR=$PYTHON_INCLUDE_DIR -DCMAKE_BUILD_TYPE=DEBUG .. && make && make test
+    cmake -DPYTHON_EXECUTABLE=/usr/local/bin/python3 -DPYTHON_LIBRARY=$PYTHON_LIBRARY -DPYTHON_INCLUDE_DIR=$PYTHON_INCLUDE_DIR -DCMAKE_BUILD_TYPE=DEBUG .. && make && make test
 elif [[ "$OSTYPE" == "cygwin" ]]; then
     : # POSIX compatibility layer and Linux environment emulation for Windows
 elif [[ "$OSTYPE" == "msys" ]]; then

When I execute it I get the following:

++ basename ./build.sh
+ cd ./
+ mkdir build
mkdir: build: File exists
+ cd build
+ [[ darwin18 == \l\i\n\u\x\-\g\n\u ]]
+ [[ darwin18 == \l\i\n\u\x ]]
+ [[ darwin18 == \d\a\r\w\i\n* ]]
++ python3 -c 'import sys;t='\''{v[0]}.{v[1]}'\''.format(v=list(sys.version_info[:2]));sys.stdout.write(t)'
+ PYTHON_VERSION=3.7
+ PYTHON_LIBRARY=/usr/local/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7.dylib
+ PYTHON_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Versions/3.7/Headers/
+ cmake -DPYTHON_EXECUTABLE=/usr/local/bin/python3 -DPYTHON_LIBRARY=/usr/local/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7.dylib -DPYTHON_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Versions/3.7/Headers/ -DCMAKE_BUILD_TYPE=DEBUG ..
CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /usr/local/bin/python3 (found version "3.7.4")
-- Could NOT find Boost: missing: python37 (found /usr/local/lib/cmake/Boost-1.71.0/BoostConfig.cmake (found version "1.71.0"))
-- Found PythonInterp: /usr/local/bin/python3 (found suitable version "3.7.4", minimum required is "3")
-- Found PythonLibs: /usr/local/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7.dylib (found suitable version "3.7.4", minimum required is "3")
-- PYTHON_LIBRARIES = /usr/local/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7.dylib
-- PYTHON_EXECUTABLE = /usr/local/bin/python3
-- PYTHON_INCLUDE_DIRS = /usr/local/Frameworks/Python.framework/Versions/3.7/Headers
-- Boost_LIBRARIES =
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/keldavis/projects/boost-python-examples/build
+ make
[  3%] Linking CXX shared module hello.so
Undefined symbols for architecture x86_64:
  "boost::python::detail::init_module(PyModuleDef&, void (*)())", referenced from:
      _PyInit_hello in hello.cpp.o
  "boost::python::detail::gcc_demangle(char const*)", referenced from:
      boost::python::type_info::name() const in hello.cpp.o
  "boost::python::detail::scope_setattr_doc(char const*, boost::python::api::object const&, char const*)", referenced from:
      void boost::python::def<char const* (*)()>(char const*, char const* (*)()) in hello.cpp.o
  "boost::python::objects::function_object(boost::python::objects::py_function const&)", referenced from:
      boost::python::api::object boost::python::detail::make_function_aux<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> >(char const* (*)(), boost::python::default_call_policies const&, boost::mpl::vector1<char const*> const&) in hello.cpp.o
  "boost::python::objects::py_function_impl_base::~py_function_impl_base()", referenced from:
      boost::python::objects::caller_py_function_impl<boost::python::detail::caller<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> > >::~caller_py_function_impl() in hello.cpp.o
  "boost::python::converter::do_return_to_python(char const*)", referenced from:
      boost::python::to_python_value<char const* const&>::operator()(char const* const&) const in hello.cpp.o
  "boost::python::converter::registry::query(boost::python::type_info)", referenced from:
      boost::python::converter::expected_pytype_for_arg<char const*>::get_pytype() in hello.cpp.o
  "boost::python::objects::py_function_impl_base::max_arity() const", referenced from:
      vtable for boost::python::objects::caller_py_function_impl<boost::python::detail::caller<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> > > in hello.cpp.o
  "boost::python::converter::registration::expected_from_python_type() const", referenced from:
      boost::python::converter::expected_pytype_for_arg<char const*>::get_pytype() in hello.cpp.o
  "typeinfo for boost::python::objects::py_function_impl_base", referenced from:
      typeinfo for boost::python::objects::caller_py_function_impl<boost::python::detail::caller<char const* (*)(), boost::python::default_call_policies, boost::mpl::vector1<char const*> > > in hello.cpp.o
  "vtable for boost::python::objects::py_function_impl_base", referenced from:
      boost::python::objects::py_function_impl_base::py_function_impl_base() in hello.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [01-HelloWorld/hello.so] Error 1
make[1]: *** [01-HelloWorld/CMakeFiles/hello.dir/all] Error 2
make: *** [all] Error 2

Trying to understand how to resolve: Could NOT find Boost: missing: python37 (found /usr/local/lib/cmake/Boost-1.71.0/BoostConfig.cmake (found version "1.71.0"))

Seems to be a cmake problem. Even if all the documented variables are set, cmake is not able to recognize the boost installation. Everything else seems to be following from this problem.

After looking further into it, I assume this be a problem with homebrew's packaging of boost-python:

CMake Error at /usr/local/Cellar/boost/1.71.0/lib/cmake/Boost-1.71.0/BoostConfig.cmake:117 (find_package):
  Could not find a package configuration file provided by "boost_python"
  (requested version 1.71.0) with any of the following names:

    boost_pythonConfig.cmake
    boost_python-config.cmake

Respective files are available for all other boost components (as part of the boost package), but are missing for boost-python and boost-python3. Adding them to one of the packages (and I don't know which would be the right one), should solve the problem.

@Achimh3011 thanks for looking into this - it helped a lot. I found this YosysHQ/nextpnr#322 (comment) and set
set(Boost_NO_BOOST_CMAKE true) and was able to get the build to succeed.

Cool! Would you like to make a PR with the work-around for this repo?

Removed the requirement from the CMakeLists.txt
changed to: find_package(Boost REQUIRED python)