gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 02:02:45 24 4
gpt4 key购买 nike

我一直在尝试为 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com