将C ++程序链接到Python

时间:2013-12-27 23:01:33

标签: c++ python wrapper

对于链接C ++和python,我使用了以下命令:

编译实际功能:

g++ -c -fpic main.cpp

使用SWIG生成包装C代码:

swig -c++ -python main.i

编译包装C代码:

g++ -c -fpic main_wrap.cxx -I/usr/include/python2.7

将所有内容链接在一起我使用了这些拖拽指令:

1)  g++ -shared main.o main_wrap.o -o _main.so 
2)  g++ -lpython -shared main.o main_wrap.o -o _main.so

并且两者都有错误,但在第二个错误中却少了。 (对于我检查的func.c示例,它只能与-lpython标志链接!) 但是,它仍然给我以下错误:

Undefined symbols for architecture x86_64:
"std::vector<double, std::allocator<double> > power_method<double>(double, int)", referenced from:
  __wrap_power_methodDouble in main_wrap.o
 "std::vector<float, std::allocator<float> > power_method<float>(float, int)", referenced from:
  __wrap_power_methodFloat in main_wrap.o
"std::vector<int, std::allocator<int> > power_method<int>(int, int)", referenced from:
  __wrap_power_methodInt in main_wrap.o
 ld: symbol(s) not found for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to see invocation)
 Show message history

0 个答案:

没有答案