草庐IT

c++ - 自从在 Golang 中删除了一些 C 之后,SWIG for go 是否已经过时了?

coder 2023-06-30 原文

我一直在尝试为 open-vcdiff 生成一个 Go 包装器,所以我通过以下尝试第一次了解了 SWIG:

godelta.swig

%module godelta
%include "include/godelta.hpp"

godelta.hpp

#include "config.h"
#include <assert.h>
#include <errno.h>
#ifdef WIN32
#include <fcntl.h>
#include <io.h>
#endif  // WIN32
#include <stdio.h>
#include "google/vcdecoder.h"
#include "google/vcencoder.h"
#include "google/jsonwriter.h"
#include "google/encodetable.h"
#include "unique_ptr.h" // auto_ptr, unique_ptr

#ifndef HAS_GLOBAL_STRING

#endif  // !HAS_GLOBAL_STRING

static const size_t kDefaultMaxTargetSize = 1 << 26;      // 64 MB

namespace godelta {

    class Godelta {
    public:
        Godelta();
        ~Godelta();

        bool Encode();
        bool Decode();
        bool DecodeAndCompare();

        int opt_buffersize;
        int opt_max_target_window_size;
        int opt_max_target_file_size;

    private:
        input file
        static bool FileSize(FILE* file, size_t* file_size);
        bool OpenFileForReading(const string& file_name,
                            const char* file_type,
                            FILE** file,
                            std::vector<char>* buffer);
        bool OpenDictionary();
        bool OpenInputFile() {
            return OpenFileForReading(input_file_name_,
                                  input_file_type_,
                                  &input_file_,
                                  &input_buffer_);
        }

        bool OpenOutputFile();
        bool OpenOutputFileForCompare() {
            return OpenFileForReading(output_file_name_,
                                  output_file_type_,
                                  &output_file_,
                                  &compare_buffer_);
        }

        bool ReadInput(size_t* bytes_read);
        bool WriteOutput(const string& output);
        bool CompareOutput(const string& output);

        std::vector<char> dictionary_;

        UNIQUE_PTR<open_vcdiff::HashedDictionary> hashed_dictionary_;

        const char* input_file_type_;
        const char* output_file_type_;

        string input_file_name_;
        string output_file_name_;

        FILE* input_file_;
        FILE* output_file_;

        std::vector<char> input_buffer_;
        std::vector<char> compare_buffer_;

        Godelta(const Godelta&);  // NOLINT
        void operator=(const Godelta&);
    };

} // namespace godelta

Swig 运行良好,生成文件 godelta_wrap.cxxgodelta_gc.cgodelta.go。我现在面临的问题是它正在生成包含:

#include "runtime.h"
#include "cgocall.h"

导致错误:

godelta_gc.c:2:10: fatal error: 'runtime.h' file not found

我到处寻找那个文件,甚至搜索了 GitHub 上的 Go 存储库。我只在 Go 中找到似乎是该文件的替代品。

对了,我的go版本是:

go version go1.9 darwin/amd64

clang :

Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

还有 SWIG:

SWIG Version 3.0.12
Compiled with g++ [x86_64-apple-darwin16.7.0]
Configured options: +pcre

任何关于这个主题的见解都将受到高度赞赏,特别是如果它使我能够在包上运行 go build 而不会出现此错误:-)

最佳答案

看起来我在 Swig 命令中缺少一个标志。我的原始命令如下所示:

swig -go -intgosize 64 godelta.swig

但正如在 issue 上指出的那样我最终提交了,我应该包括 -c++-cgo 结束:

swig -c++ -go -cgo -intgosize 64 godelta.swig

现在一切正常:-)

关于c++ - 自从在 Golang 中删除了一些 C 之后,SWIG for go 是否已经过时了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46295661/

有关c++ - 自从在 Golang 中删除了一些 C 之后,SWIG for go 是否已经过时了?的更多相关文章

  1. ruby-on-rails - 如何验证 update_all 是否实际在 Rails 中更新 - 2

    给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru

  2. ruby-on-rails - 如何从 format.xml 中删除 <hash></hash> - 2

    我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为

  3. ruby - 我可以使用 Ruby 从 CSV 中删除列吗? - 2

    查看Ruby的CSV库的文档,我非常确定这是可能且简单的。我只需要使用Ruby删除CSV文件的前三列,但我没有成功运行它。 最佳答案 csv_table=CSV.read(file_path_in,:headers=>true)csv_table.delete("header_name")csv_table.to_csv#=>ThenewCSVinstringformat检查CSV::Table文档:http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV/Table.html

  4. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  5. ruby - 检查数组是否在增加 - 2

    这个问题在这里已经有了答案:Checktoseeifanarrayisalreadysorted?(8个答案)关闭9年前。我只是想知道是否有办法检查数组是否在增加?这是我的解决方案,但我正在寻找更漂亮的方法:n=-1@arr.flatten.each{|e|returnfalseife

  6. ruby - 我可以使用 aws-sdk-ruby 在 AWS S3 上使用事务性文件删除/上传吗? - 2

    我发现ActiveRecord::Base.transaction在复杂方法中非常有效。我想知道是否可以在如下事务中从AWSS3上传/删除文件:S3Object.transactiondo#writeintofiles#raiseanexceptionend引发异常后,每个操作都应在S3上回滚。S3Object这可能吗?? 最佳答案 虽然S3API具有批量删除功能,但它不支持事务,因为每个删除操作都可以独立于其他操作成功/失败。该API不提供任何批量上传功能(通过PUT或POST),因此每个上传操作都是通过一个独立的API调用完成的

  7. ruby - 检查字符串是否包含散列中的任何键并返回它包含的键的值 - 2

    我有一个包含多个键的散列和一个字符串,该字符串不包含散列中的任何键或包含一个键。h={"k1"=>"v1","k2"=>"v2","k3"=>"v3"}s="thisisanexamplestringthatmightoccurwithakeysomewhereinthestringk1(withspecialcharacterslike(^&*$#@!^&&*))"检查s是否包含h中的任何键的最佳方法是什么,如果包含,则返回它包含的键的值?例如,对于上面的h和s的例子,输出应该是v1。编辑:只有字符串是用户定义的。哈希将始终相同。 最佳答案

  8. ruby-on-rails - Ruby 检查日期时间是否为 iso8601 并保存 - 2

    我需要检查DateTime是否采用有效的ISO8601格式。喜欢:#iso8601?我检查了ruby​​是否有特定方法,但没有找到。目前我正在使用date.iso8601==date来检查这个。有什么好的方法吗?编辑解释我的环境,并改变问题的范围。因此,我的项目将使用jsapiFullCalendar,这就是我需要iso8601字符串格式的原因。我想知道更好或正确的方法是什么,以正确的格式将日期保存在数据库中,或者让ActiveRecord完成它们的工作并在我需要时间信息时对其进行操作。 最佳答案 我不太明白你的问题。我假设您想检查

  9. ruby - 检查日期是否在过去 7 天内 - 2

    我的日期格式如下:"%d-%m-%Y"(例如,今天的日期为07-09-2015),我想看看是不是在过去的七天内。谁能推荐一种方法? 最佳答案 你可以这样做:require"date"Date.today-7 关于ruby-检查日期是否在过去7天内,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/32438063/

  10. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

随机推荐