Author Topic: Problem compiling C++ code produced with the ScrBas to C conversion module  (Read 10638 times)

GSAC3

  • Guest
Whenever I try to use BS32 to create and compile a C or C++ version of any SB program, the compile fails with the message that it can't find the 'stndlone' function.

I have searched in vain trying to find the missing function, but have had no luck.

Can someone tell me where it is located in the SB distribution and what could be causing this problem?

Thank you.

Don

verhas

  • Guest
Re: Problem compiling C++ code produced with the ScrBas to C conversion module
« Reply #1 on: September 11, 2008, 01:31:25 AM »
When you compile a BASIC program to C then you get a very simple main function and a table. The table contains the BASIC code and the main function that actually starts the interpreter. To compile the generated C code is straightforward. If you can not then the C compiler is bad.

Your problem not finding the function 'stndlone' is a linker problem. To get an executable code from the OBJ file that was generated from the C file (which was indeed generated from BASIC) you have to link it (the OBJ file) together with the ScriptBasic libraries (which you did, because you mentioned only one problem above). What you also need to link your OBJ file when linking is the stndlone.OBJ which is available in the distribution or in the source as stndlone.c and stndlone.h

This object file is not part of the libraries because on some systems it did not link properly when this was  in the library archive. Having it on the command line of the linker as a separate object file should work.

That should solve this issue.

GSAC3

  • Guest
Re: Problem compiling C++ code produced with the ScrBas to C conversion module
« Reply #2 on: September 11, 2008, 10:08:35 AM »
Thank you for your reply.

I did as you advised.  I compiled into an OBJ file the stndlone.c source and added it to the link sequence.
However, now I am getting different, unresolved external symbol,  errors in the stndlone function during linking.  Please see below---

Attempt to compile to C and link generated OBJ file:
---------------------------------------------------------

REM @echo off
REM
REM compile a BASIC program to exe using the Visual C compiler
REM under WINDOWS-XP
REM
SET LIB=C:\VC\lib;C:\VC\libVC
scriba -n -Co HELLO.c HELLO.SB
C:\VC\BIN\cl /Ox /GA6s /DWIN32 /MT /nologo /W0 /c /FoHELLO.obj HELLO.c
C:\VC\BIN\cl /Ox /GA6s /DWIN32 /MT /nologo /W0 /FeHELLO.exe HELLO.obj stndlone.obj  C:\ScrBas\lib\libscriba.lib ws2_32.lib advapi32.lib


-------------------------------------------------------------------------------------
The Results:

C:\ScrBas\bin>REM @echo off
C:\ScrBas\bin>REM
C:\ScrBas\bin>REM compile a BASIC program to exe using the Visual C compiler
C:\ScrBas\bin>REM under WINDOWS-XP
C:\ScrBas\bin>REM
C:\ScrBas\bin>SET LIB=C:\VC\lib;C:\VC\libVC
C:\ScrBas\bin>scriba -n -Co HELLO.c HELLO.SB
C:\ScrBas\bin>C:\VC\BIN\cl /Ox /GA6s /DWIN32 /MT /nologo /W0 /c /FoHELLO.obj HELLO.c
HELLO.c

C:\ScrBas\bin>C:\VC\BIN\cl /Ox /GA6s /DWIN32 /MT /nologo /W0 /FeHELLO.exe HELLO.obj stndlone.obj  C:\ScrBas\lib\libscriba.lib ws2_32.lib advapi32.lib 
stndlone.obj : error LNK2019: unresolved external symbol _alloc_InitSegment referenced in function _libscriba_LoadBinaryProgram
stndlone.obj : error LNK2019: unresolved external symbol _alloc_Alloc referenced in function _libscriba_LoadBinaryProgram
stndlone.obj : error LNK2019: unresolved external symbol _scriba_destroy referenced in function _stndlone
stndlone.obj : error LNK2019: unresolved external symbol _report_report referenced in function _stndlone
stndlone.obj : error LNK2019: unresolved external symbol _scriba_Run referenced in function _stndlone
stndlone.obj : error LNK2019: unresolved external symbol _scriba_SetFileName referenced in function _stndlone
stndlone.obj : error LNK2019: unresolved external symbol _scriba_LoadConfiguration referenced in function _stndlone
stndlone.obj : error LNK2019: unresolved external symbol _GlobalDebugDisplayFlag referenced in function _stndlone
HELLO.exe : fatal error LNK1120: 8 unresolved externals


Don

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: Problem compiling C++ code produced with the ScrBas to C conversion module
« Reply #3 on: September 13, 2008, 07:31:14 PM »
Hi Don,

It seems this has been confusing process for some time. Here is another thread Peter responded to.

Scriptbasic - Compiling the generated C code

It would be nice if this process was easier. I was able to create standalone programs with gcc when I first got started with ScriptBasic in 2005 but haven't had much luck with the 2.1 release doing the same. I like Euphoria's method of generating C source and compiling to an executable in a simple two step process.

Once you get yours working, I would appreciate if you could post something here that a full time Basic programmer, part time C maintenance hack like myself can understand.  :) 

Thanks !

John
« Last Edit: September 13, 2008, 07:38:45 PM by support »

GSAC3

  • Guest
Re: Problem compiling C++ code produced with the ScrBas to C conversion module
« Reply #4 on: September 14, 2008, 08:00:05 AM »
John:

Thanks for the thread reference to Peter's previous response to the C compiling problems experienced by other ScriptBasic users.

I have followed his recomendations precisely, but am having absolutely no luck.  I am not a "C person", but it seems to me that there must be something else wrong besides the fact that stnalone is not included in the SCRIBA lib.  Unfortunately the discussions in the thread you cited don't seem to help.

Don

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: Problem compiling C++ code produced with the ScrBas to C conversion module
« Reply #5 on: September 14, 2008, 12:53:16 PM »
If all your looking for is a standalone executable, the scriba -E option works great.

Windows:

scriba -Eo hello.exe hello.bas


Linux:

/usr/bin/scriba -Eo hello hello.bas


John
« Last Edit: September 14, 2008, 12:58:53 PM by support »