<div dir="ltr">Great. Remember to write up your findings on the Wiki.<div class="gmail_extra"><br><div class="gmail_quote">2015-02-12 8:43 GMT+05:30 Colin Gilbert <span dir="ltr"><<a href="mailto:colingilbert86@gmail.com" target="_blank">colingilbert86@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi, I would like to add a quick addition to method #2: you need to add "-lm" at the end or else you'll get endless compiler errors about undefined references to standard math libraries. The full command is:<br><br>```<span class=""><br>gcc -O1 -DHAVE_ERRNO_H -DHAVE_STDLIB_H -DHAVE_STRING_H 
-D___VOIDSTAR_WIDTH=8 -D___MAX_CHR=0x10ffff -D___BOOL=int -D___SINGLE_VM
 -D___SINGLE_THREADED_VMS -D___USE_NO_THREAD_SYSTEM 
-D___NO_THREAD_LOCAL_STORAGE_</span><div>CLASS -D___LABEL_ACCESS_OLD -D___SINGLE_HOST -D___GAMBCDIR='"/usr/local/Gambit-C"' *.c -o hello.exe -lm<br><br></div>```<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 11 February 2015 at 18:38, Colin Gilbert <span dir="ltr"><<a href="mailto:colingilbert86@gmail.com" target="_blank">colingilbert86@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Dr Feeley,<br><br>Your prompt reply is very much appreciated.<br><br>Once request I'd like to make, however: If you used C99 to compile your resulting files (or Gambit itself), would it automatically use C99's built-in types and not require __VOIDSTAR_WIDTH?<br><br><br>Thank you.<br></div><div><div><div class="gmail_extra"><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Colin, if you wanted to put a link to this Mailing list archive page  on the Wiki would be great, thanks.<div><br><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>2015-02-11 20:01 GMT+05:30 Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>></span>:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div><div><br>
> On Feb 10, 2015, at 11:40 PM, Colin Gilbert <<a href="mailto:colingilbert86@gmail.com" target="_blank">colingilbert86@gmail.com</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> Pardon the silly noob question, but I've been trying to use Gambit to quickly write up a small submodule, and then use each target's native compiler to embed it into the build. Unfortunately, I am getting link errors:<br>
><br>
> Is my my mini program:<br>
> hello.scm: (display "hello") (newline)<br>
><br>
> Here is what happens when I try to use it.<br>
><br>
> >> gsc -c hello.scm<br>
> *** INFO -- loading syntax expander<br>
><br>
> >> gcc hello.c<br>
><br>
> cc hello.c<br>
> /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/../../../../lib64/crt1.o: In function `_start':<br>
> (.text+0x20): undefined reference to `main'<br>
> /tmp/ccpGbiFh.o: In function `___H__20_hello':<br>
> hello.c:(.text+0x8d): undefined reference to `___gstate0'<br>
> hello.c:(.text+0xd4): undefined reference to `___gstate0'<br>
> hello.c:(.text+0xee): undefined reference to `___G_display'<br>
> hello.c:(.text+0x132): undefined reference to `___G_display'<br>
> hello.c:(.text+0x144): undefined reference to `___gstate0'<br>
> hello.c:(.text+0x176): undefined reference to `___gstate0'<br>
> hello.c:(.text+0x194): undefined reference to `___G_newline'<br>
> hello.c:(.text+0x1d5): undefined reference to `___G_newline'<br>
> hello.c:(.text+0x1e7): undefined reference to `___gstate0'<br>
> /tmp/ccpGbiFh.o: In function `___setup_mod':<br>
> hello.c:(.text+0x25c): undefined reference to `___G__20_hello'<br>
> /tmp/ccpGbiFh.o: In function `___init_mod':<br>
> hello.c:(.text+0x26f): undefined reference to `___gstate0'<br>
> hello.c:(.text+0x281): undefined reference to `___G__20_hello'<br>
> /tmp/ccpGbiFh.o: In function `____20_hello':<br>
> hello.c:(.text+0x29b): undefined reference to `___S_hello'<br>
> collect2: error: ld returned 1 exit status<br>
><br>
> I tried using -link, -flat,-link -flat but no real difference.<br>
><br>
> What files need to be present before you can compile the code natively?<br>
<br>
</div></div>The default Gambit-C build procedure is designed for building on the same type of platform where the executable will be run.  For portability to different platforms, the build procedure uses a “configure” script that determines various properties of the platform (the existence of various system header files, the width of pointers, the type of operating system, etc).  The “configure” script will adapt the makefiles and also fill in some blanks in include/<a href="http://gambit.h.in" target="_blank">gambit.h.in</a> to generate the Gambit header file include/gambit.h (and similarly for include/<a href="http://config.h.in" target="_blank">config.h.in</a>).<br>
<br>
In a situation with multiple target platforms, the configure script would have to be run on each target platform to determine the properties of the platform and adapt the include/<a href="http://gambit.h.in" target="_blank">gambit.h.in</a> file and the include/<a href="http://config.h.in" target="_blank">config.h.in</a> file accordingly for compiling on that platform.<br>
<br>
I sense that you are looking for a different approach.  I assume in the following that you want to compile a Scheme app into a set of .c and .h files that you can compile on multiple target platforms with little or no changes and no configure script or equivalent procedure.<br>
<br>
Here are two approches.  The first assumes that your target platforms share similar characteristics with the development platform (same OS, same processor word size) so that the gambit.h and config.h files produced by the configure script are OK.  The second approach uses options on the C compiler’s command line to fill in the information that the configure script normally determines.<br>
<br>
So we start with compiling Gambit on the development platform:<br>
<br>
% mkdir embed<br>
% cd embed<br>
% git clone <a href="http://github.com/feeley/gambit.git" target="_blank">http://github.com/feeley/gambit.git</a><br>
% cd gambit<br>
% ./configure --enable-single-host<br>
% make from-scratch<br>
% make install<br>
% cd ..<br>
<br>
Now we use the first approach that reuses the development platform’s gambit.h and config.h files.  Note that we compile all the .c files (from the Gambit library and the Scheme app) in one call of the C compiler (this could be changed to a seperate compilation of each .c file).  In any case it takes less than a minute to compile everything (this is with GNU gcc 4.9.2 on a fast machine with an SSD).<br>
<br>
% mkdir test1<br>
% cd test1<br>
% echo '(println "hello!")' > hello.scm<br>
% gsc -c hello.scm      # generate hello.c from hello.scm<br>
% gsc -link hello.c     # generate hello_.c from hello.c<br>
% cp ../gambit/include/stamp.h .<br>
% cp ../gambit/include/gambit.h .<br>
% cp ../gambit/include/config.h .<br>
% cp ../gambit/lib/*.c .<br>
% cp ../gambit/lib/*.h .<br>
% time gcc -O1 -DHAVE_CONFIG_H *.c -o hello.exe<br>
<br>
real    0m47.653s<br>
user    0m46.124s<br>
sys     0m1.443s<br>
% ./hello.exe<br>
hello!<br>
% cd test1<br>
% ls -l hello.exe<br>
-rwxr-xr-x+ 1 feeley  staff  5187576 Feb 11 08:09 hello.exe<br>
% strip hello.exe<br>
% ls -l hello.exe<br>
-rwxr-xr-x+ 1 feeley  staff  4566440 Feb 11 08:09 hello.exe<br>
% cd ..<br>
<br>
Now for the second approach.  Note that the gambit.h file is simply a copy of the <a href="http://gambit.h.in" target="_blank">gambit.h.in</a> file.  The “blanks” in that file (normally filled in by the configure script) are filled in with C compiler options (-D___VOIDSTAR_WIDTH=8 for a 64 bit processor, D___MAX_CHR=0x10ffff for full Unicode support, etc).  Similarly, the information in the config.h file is specified with C compiler options (-DHAVE_ERRNO_H to indicate that errno.h is available, etc).<br>
<br>
% mkdir test2<br>
% cd test2<br>
% echo '(println "hello!")' > hello.scm<br>
% gsc -c hello.scm      # generate hello.c from hello.scm<br>
% gsc -link hello.c     # generate hello_.c from hello.c<br>
% cp ../gambit/include/<a href="http://gambit.h.in" target="_blank">gambit.h.in</a> gambit.h<br>
% cp ../gambit/include/stamp.h .<br>
% cp ../gambit/lib/*.c .<br>
% cp ../gambit/lib/*.h .<br>
% time gcc -O1 -DHAVE_ERRNO_H -DHAVE_STDLIB_H -DHAVE_STRING_H -D___VOIDSTAR_WIDTH=8 -D___MAX_CHR=0x10ffff -D___BOOL=int -D___SINGLE_VM -D___SINGLE_THREADED_VMS -D___USE_NO_THREAD_SYSTEM -D___NO_THREAD_LOCAL_STORAGE_CLASS -D___LABEL_ACCESS_OLD -D___SINGLE_HOST -D___GAMBCDIR='"/usr/local/Gambit-C"' *.c -o hello.exe<br>
<br>
real    0m48.342s<br>
user    0m46.860s<br>
sys     0m1.387s<br>
% ./hello.exe<br>
hello!<br>
% ls -l hello.exe<br>
-rwxr-xr-x+ 1 feeley  staff  5150656 Feb 11 08:42 hello.exe<br>
% strip hello.exe<br>
% ls -l hello.exe<br>
-rwxr-xr-x+ 1 feeley  staff  4532824 Feb 11 08:43 hello.exe<br>
% cd ..<br>
<br>
So once compiled, a Scheme app can be seen as a set of .c and .h files and building the app requires a bit of knowledge of the characteristics of the target platform (but not very much, in fact the only critical one is ___VOIDSTAR_WIDTH = sizeof(void*), which has to be known at C macro expansion time to adapt some of the macros defined in gambit.h).<br>
<br>
Note that the need to specify -D___LABEL_ACCESS_OLD and -D___GAMBCDIR='"/usr/local/Gambit-C"' (and maybe a few others) will go away in a future release of Gambit as they could have default values.<br>
<span><font color="#888888"><br>
Marc<br>
<br>
</font></span><br></div></div><span>_______________________________________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca" target="_blank">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
<br></span></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>