The enums does not get passed to TCL when we have SWIG TCL Static Linking

白昼怎懂夜的黑 提交于 2019-12-25 08:01:33

问题


In continuation to question

how to pass enum values from TCL script to C++ class using Swig

I have following code

1) File : example.i

%module example
%{
      /* Put header files here or function declarations like below */
      #include "example.h"
%}

%include "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) 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;
 }  

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

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

Looking forward for guidance/help


回答1:


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

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.

[EDIT from comments for visibility]: The variables are in the ::swig namespace.



来源:https://stackoverflow.com/questions/40078645/the-enums-does-not-get-passed-to-tcl-when-we-have-swig-tcl-static-linking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!