使用 swig 和 distutils 时 GCC 无法识别标准头文件

发布于 2024-09-08 19:14:39 字数 1310 浏览 5 评论 0原文

我正在尝试为我正在组合的 C++ 库生成一个 python 包装器。我刚刚遇到 SWIG,并尝试将其与 distutils 结合使用。我正在修改别人的代码,所以奇怪的错误是预料之中的,但这个错误只是令人困惑。

我已经成功地使用 SWIG 生成了一个 C++ 包装器文件,现在正在尝试运行 setup.py 的修改版本以安装包装器(它本身可能会或可能不会工作,但当它出现时我会跨过那座桥) )当执行此操作时,编译器会弹出有关无法包含头文件的错误。具体来说 - 字符串、ostream、sstream、映射和向量。所有这些都是标准库,包含为“include”。

代码本身可以编译,但在尝试以这种方式创建包装器时却不能编译。

我不完全确定哪些信息与此相关,但这就是扩展的制作方式:

## Extension definition
import os
wrapsrc = './project_rewrite_wrap.c'
incdir_src = os.path.abspath('../include/project')
incdir_build = os.path.abspath('../include/project')
libdir = os.path.abspath('../lib')
ext = Extension('_project_rewrite',
                [wrapsrc],
                include_dirs=[incdir_src, incdir_build],
                library_dirs=[libdir, os.path.join(libdir,'.libs')],
                libraries=['ProjectMain'])

运行的 gcc 命令是:

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/home/ben/Project/rewrite/include/Project -I/home/ben/Project /rewrite/include/Project -I/usr/include/python2.6 -c ./project_rewrite_wrap.c -o build/temp.linux-i686-2.6/./project_rewrite_wrap.o

这会导致错误,例如:

./project_rewrite_wrap.c:2696:18: 错误:字符串:没有这样的文件或目录

任何想法将不胜感激,谢谢。

I'm trying to generate a python wrapper for a C++ library that I am putting together. I have just come across SWIG and am trying to use this in conjunction with distutils. I'm modifying someone elses code, so odd errors were to be expected but this one is just confusing.

I've managed to generate a c++ wrapper file with SWIG and am now attempting to run a modified version of setup.py in order to install the wrapper (which itself may or may not work, but I'll cross that bridge when it comes to it.) When doing this compiler errors pop up about inability to include header files. Specifically - string, ostream, sstream, map and vector. All of which are standard libraries, included as "include ".

The code itself compiles, but in trying to create a wrapper this way it does not.

I'm not entirely sure what information is relevant to this but this is how the extension is made:

## Extension definition
import os
wrapsrc = './project_rewrite_wrap.c'
incdir_src = os.path.abspath('../include/project')
incdir_build = os.path.abspath('../include/project')
libdir = os.path.abspath('../lib')
ext = Extension('_project_rewrite',
                [wrapsrc],
                include_dirs=[incdir_src, incdir_build],
                library_dirs=[libdir, os.path.join(libdir,'.libs')],
                libraries=['ProjectMain'])

The gcc command that is run is:

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/home/ben/Project/rewrite/include/Project -I/home/ben/Project/rewrite/include/Project -I/usr/include/python2.6 -c ./project_rewrite_wrap.c -o build/temp.linux-i686-2.6/./project_rewrite_wrap.o

Which results in errors such as:

./project_rewrite_wrap.c:2696:18: error: string: No such file or directory

Any thoughts would be greatly appreciated, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浊酒尽余欢 2024-09-15 19:14:39

您正在编译 C 代码 - 您提到的标头是 C++ 的一部分,而不是 C。要编译为 C++ 代码,请使用 g++ 驱动程序而不是 gcc,并为源文件提供 .cpp 扩展名而不是 .c。

You are compiling C code - the headers you mention are part of C++, not C. To compile as C++ code, use the g++ driver instead of gcc, and give the source files a .cpp extension instead of .c.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文