taku910 / crfpp

CRF++: Yet Another CRF toolkit
Other
505 stars 192 forks source link

Build fails on Mac OS X 10.14.4 #48

Closed Issacwww closed 5 years ago

Issacwww commented 5 years ago

I simply follow the readme to install the python-api when I run

python setup.py build

I got following error

running build
running build_py
running build_ext
building '_CRFPP' extension
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/xxx/anaconda3/include -arch x86_64 -I/Users/xxx/anaconda3/include -arch x86_64 -I/Users/xxx/anaconda3/include/python3.7m -c CRFPP_wrap.cxx -o build/temp.macosx-10.7-x86_64-3.7/CRFPP_wrap.o
warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to
      use the libc++ standard library instead [-Wstdlibcxx-not-found]
CRFPP_wrap.cxx:2375:23: warning: explicitly assigning value of variable of type 'int' to itself
      [-Wself-assign]
                  res = SWIG_AddCast(res);
                  ~~~ ^              ~~~
CRFPP_wrap.cxx:2378:23: warning: explicitly assigning value of variable of type 'int' to itself
      [-Wself-assign]
                  res = SWIG_AddCast(res);
                  ~~~ ^              ~~~
CRFPP_wrap.cxx:2900:9: warning: variable 'res' is used uninitialized whenever 'if' condition is true
      [-Wsometimes-uninitialized]
    if (PyType_Ready(tp) < 0)
        ^~~~~~~~~~~~~~~~~~~~
CRFPP_wrap.cxx:2924:10: note: uninitialized use occurs here
  return res;
         ^~~
CRFPP_wrap.cxx:2900:5: note: remove the 'if' if its condition is always false
    if (PyType_Ready(tp) < 0)
    ^~~~~~~~~~~~~~~~~~~~~~~~~
CRFPP_wrap.cxx:2881:10: note: initialize the variable 'res' to silence this warning
  int res;
         ^
          = 0
CRFPP_wrap.cxx:2981:10: fatal error: 'stdexcept' file not found
#include <stdexcept>
         ^~~~~~~~~~~
4 warnings and 1 error generated.
error: command 'gcc' failed with exit status 1

I tried to add '-stdlib=libc++' args in the setup.py in following way,

from distutils.core import setup,Extension,os
import string
import platform

if platform.system() == "Windows":
    extra_args = ["/std:c++latest", "/EHsc"]
elif platform.system() == "Darwin":
    extra_args = ['-std=c++11', "-Os", "-stdlib=libc++", "-mmacosx-version-min=10.7"]
else:
    extra_args = []

setup(name = "mecab-python",
      py_modules=["CRFPP"],
      ext_modules = [Extension("_CRFPP",
                               ["CRFPP_wrap.cxx",],
                               libraries=["crfpp", "pthread"],
                               extra_compile_args=extra_args)
                     ])

it did not work, I got more warnings

ld: library not found for -lstdc++
Issacwww commented 5 years ago

solved by add following line into bash_profile

export MACOSX_DEPLOYMENT_TARGET=10.14