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 :-)