swig c ++到python ld:未知选项:-在MacOS Mojave上共享

时间:2019-04-06 22:17:45

标签: c++ macos swig ld macos-mojave

我正在尝试使用swigc++包装一些python,但是无法在编译中执行链接步骤。我正在使用MacOS Mojave 10.14.4g++homebrew.)中的g++ 8.3.0。在this example之后,我有以下Makefile

# standard compile options for the c++ executable
FLAGS = -fPIC -std=c++17

# the python interface through swig
PYTHONI = -I/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/include/python3.7m
PYTHONL = -Xlinker

# default super-target
all: 
    g++ $(FLAGS) -c saw.cpp -o saw.o
    swig -c++ -python -o saw_wrap.cxx saw.i 
    g++ $(FLAGS) $(PYTHONI) -c saw_wrap.cxx -o saw_wrap.o
    g++ $(PYTHONL) $(LIBFLAGS) -shared saw.o saw_wrap.o -o _saw.so

请注意,我-std=c++17并删除了-export-dynamic。但是,当我运行make时,除链接步骤外,一切似乎都进行得很好:

g++ -fPIC -std=c++17 -c saw.cpp -o saw.o
swig -c++ -python -o saw_wrap.cxx saw.i 
g++ -fPIC -std=c++17 -I/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c saw_wrap.cxx -o saw_wrap.o
g++ -Xlinker  -shared saw.o saw_wrap.o -o _saw.so
ld: unknown option: -shared
collect2: error: ld returned 1 exit status
make: *** [all] Error 1

当我删除-shared选项时,我会遇到更多错误。我怎样才能解决这个问题?我也尝试使用python的{​​{1}},但是那也不起作用。我很担心,当我运行distutils时,which ld会得到/usr/bin/ld/usr/local/bin/g++的对比。

这是我的which g++的{​​{1}}文件:

saw.i

.i

saw.hpp

swig

saw.cpp

%module saw
%{
    #include "saw.hpp"
    using namespace std;
    using namespace saw;
%}

%include "std_string.i"
%include "std_vector.i"
%include "std_sstream.i"

%include "saw.hpp"

0 个答案:

没有答案