mkusner / wmd

Word Mover's Distance from Matthew J Kusner's paper "From Word Embeddings to Document Distances"
537 stars 132 forks source link

install error=> ld: unknown option: -shared #22

Open wwwxmu opened 6 years ago

wwwxmu commented 6 years ago

mac os high sierra 10.13 install error

Building object file 'emd.o'. -n cc -o emd.o -c emd.c -fPIC -I/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/include/python2.7 In file included from emd.c:20: ./emd.h:22:9: warning: 'INFINITY' macro redefined [-Wmacro-redefined]

define INFINITY 1e20

^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/math.h:68:9: note: previous definition is here

define INFINITY HUGE_VALF

^ 1 warning generated.

Generating C interface swig -python emd.i

Building object file 'emd_wrap.o'. -n cc -o emd_wrap.o -c emd_wrap.c -fPIC -I/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/include/python2.7 In file included from emd_wrap.c:3020: ./emd.h:22:9: warning: 'INFINITY' macro redefined [-Wmacro-redefined]

define INFINITY 1e20

^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/math.h:68:9: note: previous definition is here

define INFINITY HUGE_VALF

^ 1 warning generated.

Linking wrapper library '_emd.so'. -n ld -shared -o _emd.so emd.o emd_wrap.o ld: unknown option: -shared make: *** [_emd.so] Error 1 rm emd_wrap.o emd.o emd_wrap.c

sdraper-CS commented 6 years ago

I am also working on a Mac, and had both this and then subsequently some of the other reported installation problems.

Firstly this one - replace '-shared' with '-dylib'

After that, if you have multiple python installations and use some sort of Python virtual environment (I'm using Anaconda) you'll probably still have problems, first with building, and then potentially with runtime errors (Fatal Python error: PyThreadState_Get: no current thread).

To resolve these you need to ensure that you are building the EMD module against the correct libraries for your runtime Python installation. Assuming you have your runtime python activated then changing the makefile like this should solve your issues:

...
WRAPPERS := _emd.so emd.py
INCLUDES := $(shell python2-config --includes)

CC = cc
LD = ld
LIBS := $(shell python2-config --prefix)/lib
LD_FLAGS := -L$(LIBS) $(shell python2-config --ldflags)
CFLAGS := $(shell python2-config --cflags)
CFLAGS += -fPIC

all: $(WRAPPERS)

_%.so: %.o %_wrap.o
    @echo ">>> Linking wrapper library '$(@)'."
    @echo -n "    "
    $(LD) $(LD_LIBS) $(LD_FLAGS) -dylib -o $@ $^
    @echo

%.o: %.c
    @echo ">>> Building object file '$(@)'."
    @echo -n "    "
    $(CC) -o $@ -c $< $(CFLAGS) $(INCLUDES) $(LIBS)
    @echo
...