当我们有 SWIG TCL 静态链接时,枚举不会传递给 TCL
The enums does not get passed to TCL when we have SWIG TCL Static Linking
继续提问
我有以下代码
1) 文件:example.i
%module example
%{
/* Put header files here or function declarations like below */
#include "example.h"
%}
%include "example.h"
2 个文件 example.h
class myClass {
public:
enum Type {one,two};
myClass() {}
static bool printVal(int val);
static bool printEnum(Type val);
};
3) 文件 example.cpp
#include "example.h"
#include <iostream>
using namespace std;
bool myClass::printVal(int val) {
cout << " Int Val = " << val << endl;
return 0;
}
bool myClass::printEnum(type val) {
cout << " Enum Val = " << val << endl;
return 0;
}
如果我 link 共享库形式的 swig 文件它工作正常
swig -c++ -tcl example.i
g++ -c -fpic example_wrap.cxx example.cpp -I/usr/local/include
g++ -shared example.o example_wrap.o -o example.so
setenv LD_LIBRARY_PATH /pathtoexample.so:$LD_LIBRARY_PATH
tclsh
% load example.so
% myClass_printVal $myClass_one
但是如果 swig 代码和 example.* 文件是 link 静态编辑的,我会收到以下错误
% myClass_printVal $myClass_one
can't read "myClass_one": no such variable
期待guidance/help
首先,如果你使用更多的共享库路径,你不需要改变LD_LIBRARY_PATH
变量。如果它在当前目录中(方便测试)你可以这样做:
load ./example.so
当它与当前脚本位于同一目录中时,您改为执行此相当长的版本:
load [file join [file dirname [info script]] example.so]
# This also probably works:
#load [file dirname [info script]]/example.so
其次,您应该检查示例实际创建的内容;它可能只是使用了与您期望的名称不同的名称。您可以使用 info commands
、info vars
和 namespace children
来找出答案;他们列出了当前可见的命令、变量和命名空间。
[根据评论编辑可见性]: 变量位于 ::swig
命名空间中。
继续提问
我有以下代码
1) 文件:example.i
%module example
%{
/* Put header files here or function declarations like below */
#include "example.h"
%}
%include "example.h"
2 个文件 example.h
class myClass {
public:
enum Type {one,two};
myClass() {}
static bool printVal(int val);
static bool printEnum(Type val);
};
3) 文件 example.cpp
#include "example.h"
#include <iostream>
using namespace std;
bool myClass::printVal(int val) {
cout << " Int Val = " << val << endl;
return 0;
}
bool myClass::printEnum(type val) {
cout << " Enum Val = " << val << endl;
return 0;
}
如果我 link 共享库形式的 swig 文件它工作正常
swig -c++ -tcl example.i
g++ -c -fpic example_wrap.cxx example.cpp -I/usr/local/include
g++ -shared example.o example_wrap.o -o example.so
setenv LD_LIBRARY_PATH /pathtoexample.so:$LD_LIBRARY_PATH
tclsh
% load example.so
% myClass_printVal $myClass_one
但是如果 swig 代码和 example.* 文件是 link 静态编辑的,我会收到以下错误
% myClass_printVal $myClass_one
can't read "myClass_one": no such variable
期待guidance/help
首先,如果你使用更多的共享库路径,你不需要改变LD_LIBRARY_PATH
变量。如果它在当前目录中(方便测试)你可以这样做:
load ./example.so
当它与当前脚本位于同一目录中时,您改为执行此相当长的版本:
load [file join [file dirname [info script]] example.so]
# This also probably works:
#load [file dirname [info script]]/example.so
其次,您应该检查示例实际创建的内容;它可能只是使用了与您期望的名称不同的名称。您可以使用 info commands
、info vars
和 namespace children
来找出答案;他们列出了当前可见的命令、变量和命名空间。
[根据评论编辑可见性]: 变量位于 ::swig
命名空间中。