我正在尝试从C++调用python函数。我编写了一个简单的main.cpp文件和和helloworld.py,如下所示:
main.cpp:
int main(int argc, char* argv[])
{
Py_Initialize();
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('./')");
PyObject *pModule = PyImport_ImportModule( "helloworld" );
PyObject *pFunc = PyObject_GetAttrString(pModule, "say_hello_world");
PyEval_CallObject(pFunc, NULL);
Py_Initialize();
}helloworld.py:
def say_hello_world():
print( "Hello World from Python" )我用以下方法编写程序:
g++
python-config --cflagsmain.cpppython-config --ldflags-o main
因此,除了收到以下警告外,一切正常:
cc1plus:警告:命令行选项‘-’对于C/ObjC有效,但对默认启用的C++无效。
这是什么原因?有办法摆脱它吗?
发布于 2014-06-23 15:59:46
编写一个脚本gccflags-filter,过滤出对给定语言不合适的标记。例如
python-config --cflags | gccflags-filter --lang=c++可以从文档中提取标志列表。
如果您现在需要针对您的特定问题采取权宜之计,请考虑如下
g++ `python-config --cflags | sed s/-Wstrict-prototypes//`https://stackoverflow.com/questions/24369812
复制相似问题