ECL/Building libraries

From formgames wiki
< ECL
Jump to: navigation, search

NOTE: This is just a list of personal bookmarks and notes made during my experiments with ECL. For more detailed explanations see ECL's Homepage and its official Documentation!

Contents

Documentation

Linux

TODO

Mac

TODO

Windows

Static Libraries

TODO

Shared Libraries

Using asdf:make-build

Related documentation:

TODO

Using 'compile-file' and 'c:build-shared-library'

Sources: shared-library.tar.gz

Usage
  • Adapt the path of the batch file 'vcvars64.bat' in 'vsenv' to correspond to the local installation of Microsoft Visual C++.
  • Adapt the variable 'ECL_INSTALLATION_DIR' in 'Makefile' to point to the ECL installation dir.
  • Open a cygwin xterm and execute:
./vsenv nmake
./hello.exe

> hello-lisp!

./vsenv nmake clean
hello-lisp.lisp
(defun hello-lisp () (format t "hello-lisp!~%"))
hello.c
#include <stdio.h>
#include <ecl/ecl.h>

int main (int argc, char **argv) {

  /* Function to initialize the library */
  extern void init_lib_HELLO_LISP(cl_object);

  /* Initialize ECL */
  cl_boot(argc, argv);

  /* Initialize the library */
  ecl_init_module(NULL, init_lib_HELLO_LISP);

  /* Use the library */
  cl_eval(c_string_to_object("(hello-lisp)"));

  /* Shut down ECL */
  cl_shutdown();

  return 0;
}
Makefile
# ECL installation dir:
ECL_INSTALLATION_DIR = "C:/Users/dietrich/home/cs/lang/lisp/ecl/64/git/install"

# Compiler options:
# Adapted from output of: ecl-config.bat --cflags
COMPILER_OPTIONS = /EHsc /DGC_DLL /DGC_BUILD /nologo /D_CRT_SECURE_NO_DEPRECATE /Zi /D_DEBUG /MDd /Od -I"$(ECL_INSTALLATION_DIR)"

# Linker options:
# Adapted from output of: ecl-config.bat --libs
LINKER_OPTIONS = /incremental:no /nologo /nodefaultlib:libcmt /nodefaultlib:libcmtd /nodefaultlib:libc /nodefaultlib:libcd /debug /nodefaultlib:msvcrt.lib /LIBPATH:"$(ECL_INSTALLATION_DIR)" ecl.lib

hello.exe: hello.obj hello-lisp.lib
	link $(LINKER_OPTIONS) hello.obj hello-lisp.lib

hello.obj: hello.c
	cl /c $(COMPILER_OPTIONS) hello.c

hello-lisp.lib: hello-lisp.lisp
	ecl -norc -load build.lisp

clean:
	del hello.exe hello.obj hello.pdb vc100.pdb
	del hello-lisp.data hello-lisp.h hello-lisp.c hello-lisp.obj
	del hello-lisp.lib hello-lisp.dll
build.lisp
(ext:install-c-compiler)
(compile-file "hello-lisp.lisp" :c-file "hello-lisp.c" :h-file "hello-lisp.h" :data-file "hello-lisp.data" :system-p t)
(c:build-shared-library "hello-lisp" :lisp-files '("hello-lisp.obj") :init-name "init_lib_HELLO_LISP")
(quit)
vsenv
#!/usr/bin/bash

# Batch file for setting the Microsoft Visual Studio 10.0 environment
vcvars64bat="C:\Program Files (x86)\Microsoft Visual Studio 10.0/VC/bin/AMD64/vcvars64.bat"

# Temporary file
tmpfile="$TMP/tmp$$.bat"
tmpfile_win=$(cygpath -m "$tmpfile")

# Generating the batch file
cat > $tmpfile <<EOF
@echo off
call "${vcvars64bat}"
bash -c "%*"
EOF

# Executing the temporary batch file
cmd /c "${tmpfile_win} $@"

# Removing the temporary file
rm -f $tmpfile