我观察到奇怪的重命名行为
我将swig应用于ocaml代码,并复制了这些代码
关于swig官方示例代码(
https://github.com/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
问题是,如果某个名称(无效的_参数)与ocaml C接口中预定义的带有“caml_”前缀(caml_无效的_参数)的名称一致,则在编译过程中,在某些地方,前者的所有出现似乎都被后者所取代。
我用不同的名称(initialize和caml\u initialize)和不同的环境(macOS Sierra with clang或g++,ubuntu 14.10和g++)观察到了相同的问题。
这是swig或ocaml中的错误吗?