Hello, <div><br></div><div>I try to compile an example of FFI to C++ under windows.</div><div><br></div><div>1) vc2008.bat was copyed to Gambit's root</div><div>2) Modifyed one line in vc2008.bat. At the end of "set COMP_GEN=cl -nologo ....." added -D___ENABLE_CPLUSPLUS</div>
<div>3) The bat file executed and finished w/o any issues. </div><div>4) Then gsc.exe gsi.exe and gsc-cc-o.bat were copyed to ~/bin folder</div><div><br></div><div>My previously tested example of cpp-ffi (wich works fine under linux and mac) I am compiling with BAT file. Compilation finished with:</div>
<div><br></div><div><div>cube-test_.obj : error LNK2001: unresolved external symbol _____20_cube_2d_test</div><div>cube-test_.obj : error LNK2019: unresolved external symbol "int __cdecl ___main_char(int,char * * const,union ___mod_or_</div>
<div>lnk_union * (__cdecl*)(struct ___global_state_struct *),char *)" (?___main_char@@YAHHQAPADP6APAT___mod_or_lnk_union@@PAU</div><div>___global_state_struct@@@ZPAD@Z) referenced in function _main</div><div>cube-test.exe : fatal error LNK1120: 2 unresolved externals</div>
</div><div><br></div><div>Whay am I doing wrong? </div><div><br></div><div><div>Content of the source files below. There is also Makefile wich was used at the unix environments, and make.bat file witch I am using in this case.</div>
</div><div><br></div><div>---</div><div>Valery</div><div><br></div><div><br></div><div><br></div><div>==== SOURCE FILES =====</div><div><br></div><div>make.bat</div><div>-------------------------------------------</div><div>
<div>del cube-test.exe </div><div>del cube-test.c</div><div>del cube.o</div><div>del cube-test_.c</div><div><br></div><div><br></div><div>setlocal</div><div>@call "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"</div>
<div><br></div><div>set GAMBCDIR=..\..\Package</div><div>set GAMBCDIR_LIB=%GAMBCDIR%\lib</div><div>set GAMBCDIR_INCLUDE=%GAMBCDIR%\include</div><div><br></div><div>set COMP_GEN=cl -nologo -Oityb1 -Zi -GS -RTC1 -MT -D_CRT_SECURE_NO_DEPRECATE -c -I%GAMBCDIR_INCLUE% -D___ENABLE_CPLUSPLUS -D___SYS_TYPE_CPU=\"i686\" -D___SYS_TYPE_VENDOR=\"pc\" -D___SYS_TYPE_OS=\"visualc\"</div>
<div><br></div><div>if not "%1%" == "" (</div><div>set COMP_GEN=%COMP_GEN% -D___GAMBCDIR=\"%1%\"</div><div>)</div><div><br></div><div>set COMP_LIB_MH=%COMP_GEN% -D___LIBRARY</div><div>set COMP_LIB_PR_MH=%COMP_LIB_MH% -D___PRIMAL</div>
<div>set COMP_LIB=%COMP_LIB_MH% -D___SINGLE_HOST</div><div>set COMP_LIB_PR=%COMP_LIB_PR_MH% -D___SINGLE_HOST</div><div>set COMP_APP=%COMP_GEN% -D___SINGLE_HOST</div><div><br></div><div>gsc -c cube-test.scm</div><div>gsc -link cube-test.c </div>
<div>ren cube-test_.c cube-test_.cpp</div><div><br></div><div>%COMP_APP% cube.cpp</div><div>%COMP_APP% cube-test_.cpp</div><div><br></div><div>cl -Fecube-test.exe %GAMBCDIR_LIB%\libgambc.lib cube-test_.obj cube.obj Kernel32.Lib User32.Lib Gdi32.Lib WS2_32.Lib</div>
</div><div><br></div><div><br></div><div>cube.h</div><div><div>-------------------------------------------</div><div></div><div>#ifndef CUBE_HH</div><div>#define CUBE_HH</div><div><br></div><div>class Cube</div><div>{</div>
<div>public:</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>Cube();</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>~Cube();</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>void setSide(double s);</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>double getSide();</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>double Area();</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>double Volume();</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>void Properties();</div><div>private:</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>double Side;</div><div>};</div><div>#endif</div>
<div><br></div><div>cube.cpp</div><div><div>-------------------------------------------</div><div></div><div>#include <iostream></div><div>#include "cube.h"</div><div><br></div><div>Cube::Cube() { }</div><div>
Cube::~Cube() { }</div><div>void Cube::setSide(double s) { Side = s <= 0 ? 1 : s; }</div><div>double Cube::getSide() { return Side; }</div><div>double Cube::Area() { <span class="Apple-tab-span" style="white-space:pre">    </span>return 6 * Side * Side; }</div>
<div>double Cube::Volume() { return Side * Side * Side; }</div><div>void Cube::Properties()</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>std::cout << "Characteristics of this cube";</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>std::cout << "\nSide   = " << getSide();</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>std::cout << "\nArea   = " << Area();</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>std::cout << "\nVolume = " << Volume() << "\n\n";</div><div>}</div><div><br></div><div>cube-test.scm</div><div>-------------------------------------------</div>
<div></div><div>;;; Gambit should be compiled with  --enable-cplusplus flag</div><div><div><br></div><div>(c-declare "#include \"cube.h\"")</div><div><br></div><div>(define cube-new</div><div>  (c-lambda () (pointer "Cube") "___result_voidstar = (void *)(new Cube());"))</div>
<div><br></div><div>(define cube-set-side</div><div> (c-lambda ((pointer "Cube") double) void "___arg1->setSide(___arg2);"))</div><div><br></div><div>(define cube-get-side</div><div>  (c-lambda ((pointer "Cube")) double "___arg1->getSide();"))</div>
<div><br></div><div>(define cube-properties</div><div>  (c-lambda ((pointer "Cube")) void "___arg1->Properties();"))</div><div><br></div><div><br></div><div>(display "C++ test\n")</div><div>
(define c (cube-new))</div><div>(cube-set-side c 10.2)</div><div>(display (cube-get-side c))</div><div>(print "\n")</div><div>(cube-properties c)</div><div><br></div><div>Makefile</div><div><div>-------------------------------------------</div>
<div></div><div>cube-test:<span class="Apple-tab-span" style="white-space:pre">     </span>cube-test.c cube.o</div></div><div><div><span class="Apple-tab-span" style="white-space:pre">    </span>gsc -link cube-test.c</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>gcc -o cube-test cube.o -x c++ cube-test.c cube-test_.c -lm -ldl -lgambc -lstdc++ -lutil -I/usr/local/Gambit-C/include -L/usr/local/Gambit-C/lib</div>
<div><br></div><div>cube.o:<span class="Apple-tab-span" style="white-space:pre">      </span>cube.cpp cube.h</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>gcc -c cube.cpp </div><div><br></div><div>cube-test.c:<span class="Apple-tab-span" style="white-space:pre">        </span>cube-test.scm</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>rm -f cube-test.c</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>gsc -c -o cube-test.c cube-test.scm</div><div><br></div><div>clean:</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span>rm -f cube-test cube-test.c cube.o cube-test_.c</div></div><div><br></div></div></div></div>