我一直在Windows 7(64位)下使用scilab版本5.5.2(64位)。 对于当前项目,我需要能够创建具有行为的xcos块 由我自己的C语言源代码规定。我发现以下 优秀的教程Tutorial Creating a C Function Block in Scicos。
首先,我安装了MinGw工具箱0.9.3。安装似乎 成功,因为函数haveacompiler返回true。然后我 根据上述教程编写了源代码
// This is the computational function for a scicos model block.
// The model is of a variable-gain integrator with hard high and low limits.
#include "c:\Program Files\scilab-5.5.2\modules\scicos_blocks\includes\scicos_block4.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define r_IN(n, i) ((GetRealInPortPtrs(blk, n+1))[(i)])
#define r_OUT(n, i) ((GetRealOutPortPtrs(blk, n+1))[(i)])
// parameters
#define Lhi (GetRparPtrs(blk)[0]) // integrator high limit
#define Llo (GetRparPtrs(blk)[1]) // integrator low limit
// inputs
#define in (r_IN(0,0)) // integrator input
#define gainp (r_IN(1,0)) // integrator gain when x > 0
#define gainn (r_IN(2,0)) // integrator gain when x <= 0
// states
#define X (GetState(blk)[0]) // integrator state
#define Xdot (GetDerState(blk)[0]) // derivative of the integrator output
// outputs
#define out (r_OUT(0,0)) // integrator output
#define Igain (r_OUT(1,0)) // integrator gain
// other constants
#define surf0 (GetGPtrs(blk)[0])
#define surf1 (GetGPtrs(blk)[1])
#define surf2 (GetGPtrs(blk)[2])
#define mode0 (GetModePtrs(blk)[0])
// if X is greater than Lhi, then mode is 1
// if X is between Lhi and zero, then mode is 2
// if X is between zero and Llo, then mode is 3
// if X is less than Llo, then mode is 4
#define mode_xhzl 1
#define mode_hxzl 2
#define mode_hzxl 3
#define mode_hzlx 4
void lim_int(scicos_block *blk, int flag)
{
double gain = 0;
switch(flag)
{
case 0:
// compute the derivative of the continuous time state
if((mode0 == mode_xhzl && in < 0) || mode0 == mode_hxzl)
gain = gainp;
else if((mode0 == mode_hzlx && in > 0) || mode0 == mode_hzxl)
gain = gainn;
Xdot = gain*in;
break;
case 1:
// compute the outputs of the block
if(X >=Lhi || X <= Llo)
Igain = 0;
else if (X > 0)
Igain = gainp;
else
Igain = gainn;
out = X;
break;
case 9:
// compute zero crossing surfaces and set modes
surf0 = X - Lhi;
surf1 = X;
surf2 = X - Llo;
if(get_phase_simulation() == 1)
{
if(surf0 >= 0)
mode0 = mode_xhzl;
else if(surf2 <= 0)
mode0 = mode_hzlx;
else if(surf1 > 0)
mode0 = mode_hxzl;
else
mode0 = mode_hzxl;
}
break;
}
}
之后,我用以下命令调用了函数ilib_for_link
参数ilib_for_link('lim_int','lim_int_comp.c',[],"c")
该函数返回以下输出:
ilib_for_link('lim_int','lim_int_comp.c',[],"c")
Generate a loader file
Generate a Makefile
Running the Makefile
Compilation of lim_int_comp.obj
Building shared library (be patient)
!------------- Compile file lim_int_comp.c -------------- !
! !
!x86_64-w64-mingw32-gcc.exe -c -DWIN32 -D_MSC_VER -DSTRICT -DFORDLL -I"C:/PROGRA~1/SCILAB!
! ~1.2/libs/MALLOC/includes" -I"C:/PROGRA~1/SCILAB~1.2/modules/core/includes" -I"C:/P!
! ROGRA~1/SCILAB~1.2/modules/api_scilab/includes" -I"C:/PROGRA~1/SCILAB~1.2/modules/c!
! all_scilab/includes" -I"C:/PROGRA~1/SCILAB~1.2/modules/output_stream/includes" -I"C!
! :/PROGRA~1/SCILAB~1.2/modules/jvm/includes" -I"C:/PROGRA~1/SCILAB~1.2/modules/local!
! ization/includes" -I"C:/PROGRA~1/SCILAB~1.2/modules/dynamic_link/includes" -I"C:/PR!
! OGRA~1/SCILAB~1.2/modules/mexlib/includes" -I"C:/PROGRA~1/SCILAB~1.2/modules/time/i!
! ncludes" -I"C:/PROGRA~1/SCILAB~1.2/modules/windows_tools/includes" -I"C:/PROGRA~1/S!
! CILAB~1.2/libs/f2c" -I"C:/PROGRA~1/SCILAB~1.2/libs/hashtable" -I"C:/PROGRA~1/SCILAB!
! ~1.2/libs/intl" -m64 lim_int_comp.c !
! !
!lim_int_comp.c: In function 'lim_int': !
! !
!lim_int_comp.c:76:7: warning: implicit declaration of function 'get_phase_simulation' [-!
! Wimplicit-function-declaration] !
! !
! if(get_phase_simulation() == 1) !
! !
! ^~~~~~~~~~~~~~~~~~~~ !
! !
!------------- Link files -------------- !
! !
!x86_64-w64-mingw32-gcc.exe --shared lim_int_comp.o -L"c:\cygwin64\x86_64-w64-mingw32\li!
! b" -LC:\Users\Stepan\AppData\Roaming\Scilab\scilab-5.5.2\mingwlib_x64 -lstdc++ -lgf!
! ortran -lMALLOC -lblasplus -lf2c -llapack -lcore -lcore_f -lintersci -loutput_strea!
! m -ldynamic_link -linteger -loptimization_f -ljvm -lscilocalization -lintl -llinpac!
! k_f -lcall_scilab -ltime -lapi_scilab -lscilab_windows -lscicos -lscicos_blocks -ls!
! cicos_blocks_f -lscicos_f -o liblim_int.dll -Wl,--out-implib=liblim_int.a -Wl,--ex!
! port-all-symbols -Wl,--enable-auto-import -Wl !
! !
!x86_64-w64-mingw32-gcc.exe: error: unrecognized command line option '-Wl'; did you mean !
! '-W'? !
! !
!Makelib:102: recipe for target 'liblim_int.dll' failed !
! !
!make: *** [liblim_int.dll] Error 1 !
!--error 10000
ilib_compile: Error while executing Makelib.
at line 25 of function dlwCompile called by :
at line 51 of function ilib_compile called by :
at line 94 of function ilib_for_link called by :
ilib_for_link('lim_int','lim_int_comp.c',[],"c")
在我看来,问题在于get_phase_simulation函数的原型是 失踪。有人遇到过这个问题吗?感谢您的任何建议。
答案 0 :(得分:1)
错误似乎不是由于缺少原型(只是警告),而是由于x86_64-w64-mingw32-gcc.exe的-Wl参数