英文:
How to include "<>" cascading headers
问题
我正在尝试使用SWIG将C++代码作为Go模块使用。
我的文件夹组织如下:
MyLib/
-go-integration
-basic_host
-basic_host.i
-basic_host_wrap.cxx // 由SWIG生成
-basic_host_wrap.h // 由SWIG生成
-basic_host.go // 由SWIG生成
-MyLib/
-include/
-mylib
-common.hpp
-inputs.hpp
-guests.hpp
-logger.hpp
- ...
-src/
-guests.cpp
-logger.cpp
- ...
我的basic_host.i文件:
%module(directors="1") basic_host
%{
#include <atomic>
#include <map>
#include <iostream>
#include "../../MyLib/include/mylib/inputs.hpp"
#include "../../MyLib/include/mylib/common.hpp"
#include "../../MyLib/include/mylib/guests.hpp"
%}
%inline %{
导出的一些函数....
%}
%constant 一些常量...
我目前使用的命令是:
swig -go -cgo -c++ -intgosize 64 .\basic_host.i
go install
在文件 basic_host_wrap.cxx 的第344行包含的文件中:
../../MyLib/include/mylib/common.hpp:6:10: 致命错误: mylib/inputs.hpp: 没有那个文件或目录
6 | #include <mylib/inputs.hpp>
|
^~~~~~~~~~~~~~~~~~~~~~
编译终止。
我的问题是,似乎我无法导入我的C++文件,因为它们使用了“<>”符号导入文件。然而,在C++端使用这些文件时没有问题(导入成功)。
我需要在guests.hpp
中导入我的go包,但它导入了common.hpp
,而common.hpp
又导入了inputs.hpp
,从而导致了错误。也许有一种方法可以直接通过外部依赖项导入我的库,而不是使用相对路径,但我还没有找到这种方法。
这种行为可能可以解释为SWIG使用gcc/g++,并且不知道如何找到包含文件的位置,但我也不知道如何更改/尝试。
英文:
I'm trying to use SWIG to be able to use C++ code as a Go module.
My folders are organized as this:
MyLib/
-go-integration
-basic_host
-basic_host.i
-basic_host_wrap.cxx // gen by SWIG
-basic_host_wrap.h // gen by SWIG
-basic_host.go // gen by SWIG
-MyLib/
-include/
-mylib
-common.hpp
-inputs.hpp
-guests.hpp
-logger.hpp
- ...
-src/
-guests.cpp
-logger.cpp
- ...
My basic_host.i file:
%module(directors="1") basic_host
%{
#include <atomic>
#include <map>
#include <iostream>
#include "../../MyLib/include/mylib/inputs.hpp"
#include "../../MyLib/include/mylib/common.hpp"
#include "../../MyLib/include/mylib/guests.hpp"
%}
%inline %{
somefunc to export ....
%}
%constant someConstant...
Right now what I have been using is:
swig -go -cgo -c++ -intgosize 64 .\basic_host.i
go install
In file included from basic_host_wrap.cxx:344:
../../MyLib/include/mylib/common.hpp:6:10: fatal error: mylib/inputs.hpp: No such file or directory
6 | #include <mylib/inputs.hpp>
|
^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
My problem is that it seems that I'm unable to import my C++ files as they are importing files with "<>". However on C++ side I've no problem for using those files(the importing is done well).
My import for my go package is needed on guests.hpp
but it imports common.hpp
that imports inputs.hpp
and giving me that error. Maybe there is a way to import direclty by ext dependencies my lib and not giving the relative path but I haven't found it.
This behaviour might be explainable by the fact that SWIG is using gcc/g++ and doesn't know where to find include files but I don't know either how to change/try that.
答案1
得分: 0
这是我怀疑的情况,SWIG使用gcc和cgo来生成文件,你可以将CGO_CPPFLAGS
作为环境变量添加,它是指向你的包含文件路径的路径。
$env:CGO_CPPFLAGS="-I D:/Repos/MyLib/MyLib/include"
我还尝试了使用SWIG的-I命令,像这样:
swig -go -cgo -c++ -I"D:/Repos/MyLib/MyLib/include" -intgosize 64 .\basic_host.i
但它没有直接起作用。
英文:
This is what I was suspecting, SWIG uses gcc and cgo to produce the files and you can add as an environment variable CGO_CPPFLAGS
that is the path to your include files.
$env:CGO_CPPFLAGS="-I D:/Repos/MyLib/MyLib/include"
I also tried with the command -I of SWIG like this :
swig -go -cgo -c++ -I"D:/Repos/MyLib/MyLib/include" -intgosize 64 .\basic_host.i
But it wasn't working direclty.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论