在使用swig到OCAML时,奇怪的重命名行为
Strange renaming behavior in using swig to ocaml
我观察到奇怪的重命名行为我将swig应用于OCAML代码,我复制了在SWIG官方示例代码(https://github.com/swig/swig/swig/blob/master/examples/ocaml/std_vector(:
示例.h
#include <vector>
#include <stdexcept>
#include <numeric>
double average(std::vector<int> v) {
# instead of calculating the average,
# throw an invalid_argument
throw std::invalid_argument("test");
return 0;
}
示例.i(与上面链接中的一个相同(
%module example
%{
#include "example.h"
%}
%include stl.i
/* instantiate the required template specializations */
%template(IntVector) std::vector<int>;
%template(DoubleVector) std::vector<double>;
/* Let's just grab the original header file here */
%include "example.h"
这个带来:
➜ std_vector git:(master) ✗ make
/Library/Developer/CommandLineTools/usr/bin/make -f ../../Makefile
SRCDIR='' SRCS=''
SWIG_LIB_DIR='../../../Lib' SWIGEXE='../../../swig'
PROGFILE='runme.ml' TARGET='example' INTERFACE='example.i'
ocaml_static_cpp
rm -rf swig.mli swig.ml swigp4.ml && env SWIG_LIB=../../../Lib ../../../swig -ocaml -co swig.mli 2>/dev/null && env SWIG_LIB=../../../Lib ../../../swig -ocaml -co swig.ml 2>/dev/null && env SWIG_LIB=../../../Lib ../../../swig -ocaml -co swigp4.ml 2>/dev/null && ocamlc -c swig.mli && ocamlc -c swig.ml && ocamlc -I ` camlp4 -where` -pp "camlp4o pa_extend.cmo q_MLast.cmo" -c swigp4.ml
env SWIG_LIB=../../../Lib ../../../swig -ocaml -c++ -o
example_wrap.cxx example.i
cp example_wrap.cxx example_wrap.c
ocamlc -cc 'g++ -Wno-write-strings' -g -c -ccopt -g -ccopt "-xc++ "
example_wrap.c
ocamlc -g -c example.mli
ocamlc -g -c example.ml
(some warnings)
false || ocamlc -g -ccopt -g -cclib -g -custom -o example swig.cmo
example.cmo runme.cmo example_wrap.o -cclib "" -cc 'g++ -Wno-write-strings'
clang: warning: treating 'c' input as 'c++' when in C++ mode, this
behavior is deprecated [-Wdeprecated]
Undefined symbols for architecture x86_64:
"std::caml_invalid_argument::~caml_invalid_argument()", referenced from:
average(std::__1::vector<int, std::__1::allocator<int> >) in example_wrap.o
"typeinfo for std::caml_invalid_argument", referenced from:
average(std::__1::vector<int, std::__1::allocator<int> >) in
example_wrap.o
"vtable for std::caml_invalid_argument", referenced from:
average(std::__1::vector<int, std::__1::allocator<int> >) in
example_wrap.o
NOTE: a missing vtable usually means the first non-inline virtual
member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
File "_none_", line 1:
Error: Error while building custom runtime system
make[1]: *** [ocaml_static_cpp] Error 2
问题是,如果某个名称(Invalid_argument(与OCAML C接口中的预定词与" CAML_"前缀(CAML_INVALID_ARGUMENT(一致,则看起来前者的所有发生在某些地方在某些地方替换了前者的所有情况。。我观察到具有不同名称(初始化和CAML_Initialize(和不同环境(Macos Sierra,带有Clang或G 和Ubuntu 14.10和G (的同一问题。这是Swig还是Ocaml中的错误?
有一个名为 caml/compatibility.h
的文件,其定义与此类似:
. . .
#define failwith caml_failwith
#define invalid_argument caml_invalid_argument
. . .
也许即使不应该包含在内?
相关文章:
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 通过重命名C++中的符号来减小二进制大小
- 如何以与 API 兼容的方式重命名类成员?
- 如何在Visual Studio Code中重命名我的a.exe文件?
- 在Qt中复制,剪切,粘贴,重命名,撤消和重做
- 重命名 win32api 函数以进行混淆
- 将内容从第一个文件("constituencies")移动到第二个文件("temp")并在之后重命名时,我的文件被删除
- 如何在重命名函数 (c++) 中使用变量?
- 如何通过 boost::p ython 重命名构造函数的关键字参数
- 以编程方式防止重命名或删除文件,但仍使其可写
- C++:重命名dll和lib并链接
- 使用 stdio.h 重新定位和重命名文件C++
- C++ Qt5 QDir重命名返回错误
- C++提升 ptree 重命名键
- 如何检测哪些进程更改,重命名或创建文件?
- 禁用/重命名从主机环境导入"env"
- 录制后无法重命名 rosbag 文件
- 避免在统计数据和重命名之间进行TOCTOU(检查时间,使用时间)
- 在使用swig到OCAML时,奇怪的重命名行为
- SWIG生成的Lua<-->C++ Wrapper错误地处理了typedef重命名的基元类型