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 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题