当我们有SWIG TCL静态链接时,枚举不会传递给TCL [英] The enums does not get passed to TCL when we have SWIG TCL Static Linking
问题描述
继续提问
以下代码
1)文件:example.i
1) File : example.i
%module example
%{
/* Put header files here or function declarations like below */
#include "example.h"
%}
%include "example.h"
2文件example.h
2 File example.h
class myClass {
public:
enum Type {one,two};
myClass() {}
static bool printVal(int val);
static bool printEnum(Type val);
};
3)文件example.cpp
3) File 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;
}
如果我以共享库的形式链接swig文件,则可以正常工作
If I link the swig files in the form of shared library it is working fine
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。*文件是静态链接的我遇到以下错误
But if the swig code and example.* files are linked statically I am getting following error
% myClass_printVal $myClass_one
can't read "myClass_one": no such variable
期待指导/帮助
推荐答案
首先,如果您使用共享库的更多路径,则无需更改 LD_LIBRARY_PATH
变量。如果它在当前目录中(方便测试),则可以执行以下操作:
Firstly, if you use more of the path to the shared library, you don't need to alter the LD_LIBRARY_PATH
variable. In the case that it's in the current directory (convenient for testing) you can just do this:
load ./example.so
当它与当前脚本位于同一目录时,您可以使用更长的版本:
When it's in the same directory as the current script, you instead do this rather longer version:
load [file join [file dirname [info script]] example.so]
# This also probably works:
#load [file dirname [info script]]/example.so
,您应该检查示例实际创建的内容;它可能只是使用了与您期望的名称不同的名称。您可以使用 info命令
, info vars
和命名空间子项
找出答案;他们列出了当前可见的命令,变量和名称空间。
Secondly, you should check what the example has actually created; it might simply be using a different name to what you expect. You can use info commands
, info vars
and namespace children
to find this out; they list the commands, variables and namespaces currently visible.
[通过注释编辑可见性]:变量位于 :: swig
命名空间。
这篇关于当我们有SWIG TCL静态链接时,枚举不会传递给TCL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!