dsx5201 2017-09-19 08:36
浏览 186
已采纳

自从Golang中的一些C删除以来,用于go的SWIG是否已过时?

I've been trying to generate a Go wrapper for open-vcdiff so I took a look at SWIG for the first time with the following attempt:

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 works well, generating the files godelta_wrap.cxx, godelta_gc.c and godelta.go. The problem I'm facing now is that it's generating the includes:

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

Resulting in the error:

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

I have looked everywhere for that file, even searched the Go repository on GitHub. I'm only finding what seems to be replacements of that file in Go.

By the way, my go version is:

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

And SWIG:

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

Any insight on the subject will be highly appreciated, especially if it leads to me being able to run go build on the package without this error :-)

  • 写回答

1条回答 默认 最新

  • duanji1026 2017-09-24 05:14
    关注

    It looks like I was missing a flag on my Swig command. My original command looked like this:

    swig -go -intgosize 64 godelta.swig
    

    But as pointed out on the issue I eventually filed, I was supposed to include -c++ and -cgo ending up with:

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

    It's working fine now :-)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误