我试图在TCL中构建一个测试框架,该框架允许我通过TCP套接字在远程设备上执行脚本测试。在Ubuntu中已经存在一个Visual Basic接口和SWIG,我正在重新使用它调用的C函数来构建一个共享库,它将作为TCL的扩展工作。我已经成功地使用SWIG的typemaps将基本函数(如打开/关闭套接字和基本读/写)合并到设备上的单个内存地址.i为readAddress函数提供指针(* OUTPUT),以将地址值返回给TCL 。使用SWIG将结构指针从TCL传递到C函数中
问题是,为了这个有用,我将不得不并入大量的远程过程调用,这些调用将复杂的数据类型传入(并退出!)设备。作为概念证明,我试图获得一个相对简单的功能。这试图通过RPC读取默认测试参数;为功能提供了一个指向结构的指针:rpc_testDefaults (testDefaults_t *testDefaults)
。
为testDefaults_t
的类型定义是在testDefaults.h,这是在下面的风格:
// testDefaults.h
#include <stdint.h>
typedef uint32_t customType_t;
typedef struct
{
customType_t varName1; // Description
uint32_t varName2; // Description
// 13 more uint32_t elements
} testDefaults_t;
// Two more struct type definitions
testDefaults.c是沿着这个线路:
// testDefaults.c
#include "testDefaults.h"
// #ifdefs to compile as 'client' OR 'server' (defaults to 'client')
rpc_testDefaults (testDefaults_t, *testDefaults)
{
// function
}
我痛饮接口文件看起来像这样:
// rpcTest.i
%module rpcTest
%include <cpointer.i>
%include "testDefaults.h"
%pointer_functions(testDefaults_t, testDefaults);
//%apply int *OUTPUT {testDefaults_t, *testDefaults};
%{
#include "testDefaults.h"
extern int rpc_testDefaults (testDefaults_t, *testDefaults)
}%
extern int rpc_testDefaults (testDefaults_t, *testDefaults)
还有许多其他的.c和头文件支持这个功能的相同文件夹以及我提到的其他文件夹我工作。
我跑swig -tcl -debug-typedef rpcTest.i
这给了我rpcTest_wrap.c,我可以看到testDefaults_t已被公认为一种类型/范围,因为是在调试输出部分(它也包含在无名范围部分:testDefaults_t -> testDefaults_t
)。
我运行了gcc -fPIC -DCLIENT_FLAG -c *.c -I/usr/include/tcl8.5
,我从SWIG输出文件中的一行中得到一个错误:rpcTest_wrap.c:1803:3: error: unknown type name 'testDefaults_t'
(加上由此衍生出的更多错误)。有问题的行是在这个函数的第一行:
static testDefaults_t *new_testDefaults() {
return (testDefaults_t *)malloc(sizeof(testDefaults_t));
}
我相信这是cpointers.i创建一个功能TCL以“创造”一个指针结构。
我有一种感觉,这是与海湾合作委员会做的事情,包括错误的顺序的文件,但我不知道下一步该怎么做。我已经尝试了在接口文件中的各个位置定义头部的多种组合,这是组合给出了最少的错误:)。你可以看到我的注释部分尝试使用typemaps而不是cpointers,但我对这些更加无知,我管理它的指向单个值的指针,但它似乎不适用于具有它自己的结构类型。它编译没有错误,但。
所以有可能得到我正在尝试使用cpointers.i工作吗?有关如何克服编译器问题的任何建议?我会更好地学习如何使用类型映射吗?让我知道在哪里可以提供更多详细信息,如果有帮助的话,我可能会遗漏关键信息,因为我必须总结和更改所有名称,因为这是公司的内容。
任何帮助/批评将不胜感激!
作为进一步的说明,移动%pointer_function(...到接口文件的底部排除了gcc编译问题。 – TheChizler