BYVoid / OpenCC

Conversion between Traditional and Simplified Chinese
https://opencc.byvoid.com/
Apache License 2.0
8.3k stars 974 forks source link

Compile failed using gcc 4.8.2 #524

Open hekaisheng opened 3 years ago

hekaisheng commented 3 years ago

I tried to build wheel from source, error raised when run python setup.py bdist_wheel as below:

[ 53%] Building CXX object CMakeFiles/opencc_clib.dir/src/py_opencc.cpp.o
In file included from /home/OpenCC/deps/pybind11-2.5.0/include/pybind11/pytypes.h:12:0,
                 from /home/OpenCC/deps/pybind11-2.5.0/include/pybind11/cast.h:13,
                 from /home/OpenCC/deps/pybind11-2.5.0/include/pybind11/attr.h:13,
                 from /home/OpenCC/deps/pybind11-2.5.0/include/pybind11/pybind11.h:44,
                 from /home/OpenCC/src/py_opencc.cpp:1:
/home/OpenCC/deps/pybind11-2.5.0/include/pybind11/detail/common.h: In instantiation of ‘struct pybind11::overload_cast<const char*, long unsigned int>’:
/home/OpenCC/src/py_opencc.cpp:12:59:   required from here
/home/OpenCC/deps/pybind11-2.5.0/include/pybind11/detail/common.h:772:5: error: static assertion failed: pybind11::overload_cast<...> requires compiling in C++14 mode
     static_assert(detail::deferred_t<std::false_type, Args...>::value,
     ^
/home/OpenCC/src/py_opencc.cpp: In function ‘void pybind11_init_opencc_clib(pybind11::module&)’:
/home/OpenCC/src/py_opencc.cpp:12:59: error: no matching function for call to ‘pybind11::overload_cast<const char*, long unsigned int>::overload_cast(<unresolved overloaded function type>, const std::integral_constant<bool, true>&)’
             (&opencc::SimpleConverter::Convert, py::const_)
                                                           ^
/home/OpenCC/src/py_opencc.cpp:12:59: note: candidates are:
In file included from /home/OpenCC/deps/pybind11-2.5.0/include/pybind11/pytypes.h:12:0,
                 from /home/OpenCC/deps/pybind11-2.5.0/include/pybind11/cast.h:13,
                 from /home/OpenCC/deps/pybind11-2.5.0/include/pybind11/attr.h:13,
                 from /home/OpenCC/deps/pybind11-2.5.0/include/pybind11/pybind11.h:44,
                 from /home/OpenCC/src/py_opencc.cpp:1:
/home/OpenCC/deps/pybind11-2.5.0/include/pybind11/detail/common.h:771:36: note: constexpr pybind11::overload_cast<const char*, long unsigned int>::overload_cast()
 template <typename... Args> struct overload_cast {
                                    ^
/home/OpenCC/deps/pybind11-2.5.0/include/pybind11/detail/common.h:771:36: note:   candidate expects 0 arguments, 2 provided
/home/OpenCC/deps/pybind11-2.5.0/include/pybind11/detail/common.h:771:36: note: constexpr pybind11::overload_cast<const char*, long unsigned int>::overload_cast(const pybind11::overload_cast<const char*, long unsigned int>&)
/home/OpenCC/deps/pybind11-2.5.0/include/pybind11/detail/common.h:771:36: note:   candidate expects 1 argument, 2 provided
/home/OpenCC/deps/pybind11-2.5.0/include/pybind11/detail/common.h:771:36: note: constexpr pybind11::overload_cast<const char*, long unsigned int>::overload_cast(pybind11::overload_cast<const char*, long unsigned int>&&)
/home/OpenCC/deps/pybind11-2.5.0/include/pybind11/detail/common.h:771:36: note:   candidate expects 1 argument, 2 provided
gmake[2]: *** [CMakeFiles/opencc_clib.dir/src/py_opencc.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/opencc_clib.dir/all] Error 2
gmake: *** [all] Error 2
Traceback (most recent call last):
  File "setup.py", line 216, in <module>
    keywords=['opencc', 'convert', 'chinese']
  File "/opt/python/cp37-cp37m/lib/python3.7/site-packages/setuptools/__init__.py", line 165, in setup
    return distutils.core.setup(**attrs)
  File "/opt/python/cp37-cp37m/lib/python3.7/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/opt/python/cp37-cp37m/lib/python3.7/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/opt/python/cp37-cp37m/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/opt/python/cp37-cp37m/lib/python3.7/site-packages/setuptools/command/build_ext.py", line 87, in run
    _build_ext.run(self)
  File "/opt/python/cp37-cp37m/lib/python3.7/distutils/command/build_ext.py", line 340, in run
    self.build_extensions()
  File "/opt/python/cp37-cp37m/lib/python3.7/distutils/command/build_ext.py", line 449, in build_extensions
    self._build_extensions_serial()
  File "/opt/python/cp37-cp37m/lib/python3.7/distutils/command/build_ext.py", line 474, in _build_extensions_serial
    self.build_extension(ext)
  File "setup.py", line 135, in build_extension
    build_libopencc()
  File "setup.py", line 118, in build_libopencc
    assert errno == 0, 'Build failed'
AssertionError: Build failed

This may be related to the overloaded methods in pybind11, as described in the docs:

If you prefer the py::overload_cast syntax but have a C++11 compatible compiler only, you can use py::detail::overload_cast_impl with an additional set of parentheses:

template <typename... Args>
using overload_cast_ = pybind11::detail::overload_cast_impl<Args...>;

py::class_<Pet>(m, "Pet")
   .def("set", overload_cast_<int>()(&Pet::set), "Set the pet's age")
   .def("set", overload_cast_<const std::string &>()(&Pet::set), "Set the pet's name");

Maybe some work could be done to make it work with C++11 compatible compiler.

mingruimingrui commented 3 years ago

@hekaisheng You're right, I'll make a pr soon.

hekaisheng commented 3 years ago

@hekaisheng You're right, I'll make a pr soon.

Thanks!