我有一个目录结构:
include/foo/bar/header1.h
include/foo/bar/header2.hheader1.h包括header2.h。但是,当我尝试这样做时:
import cppyy
cppyy.add_include_path('include')
cppyy.include('foo/bar/header1.h')我得到了错误:
ImportError: Failed to load header file "foo/bar/header1.h"
In file included from input_line_33:1:
./include/foo/bar/header1.h:11:10: fatal error: 'foo/bar/header2.h' file not found
#include "foo/bar/header2.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~我不知道在这里该做什么。我可以手动包含header2.h,但它又有其他的包含文件,我可能最终会手动包含整个项目,这似乎不需要发生。我已经尝试过cppyy.include('include/foo/bar/header1.h')和cppyy.include('foo/bar/header1.h')了。我还尝试过cppyy.add_include_path('include')和cppyy.add_include_path('include/foo')。这两种方法都没有帮助。
发布于 2021-09-15 20:09:48
尽管在上面的评论中得出了结论,但下面的内容是为了帮助调试,以防有人在这个问题上遇到同样的问题。
要打印Cling所看到的完整的包含目录集,请执行以下操作:
import cppyy
print(cppyy.gbl.gInterpreter.GetIncludePath())它将显示为一系列-I<dir>参数,就像在命令行上提供给C++编译器一样。
每个函数的<dir>部分中的路径既可以是绝对路径,也可以是相对路径。如果存在任何相对路径,则os.chdir()将从进程的当前目录中考虑它们,因此可以使用基本的os.getcwd()来检索它,并使用Cling来更改它。
如果在程序运行期间的任何时候,当前工作目录可能会意外更改,那么我建议将给定的所有路径设置为绝对路径(或立即包含所有相关的头文件)。例如:
cppyy.add_include_path(os.path.abspath('include'))https://stackoverflow.com/questions/69185463
复制相似问题