tomhrr / dale

Lisp-flavoured C
BSD 3-Clause "New" or "Revised" License
1.03k stars 48 forks source link

How to import libs? #136

Closed porky11 closed 7 years ago

porky11 commented 7 years ago

I want to save some functions and macros, that could be used in different projects, in a lib. so i have a dir ../mylib/ and it contains compiled dt files, for example libutil.dtm now in another program I want to use this, so I thought, I'd have to compile this program this way: dalec -c src/file.dt -L ../mylib -lutil and file src/file.dt would look like this:

(module file)
(import util)

…

But that's not the way it works.

tomhrr commented 7 years ago

On compiling a module, five files are produced. In this case, they will be named libutil.bc, libutil.so, libutil-nomacros.bc, libutil-nomacros.so and libutil.dtm. The current working directory is implicitly a module include directory, so if a module's files are present in a directory and the program that uses that module is compiled within that directory, no extra flags need to be passed to dalec. If the files are in another directory, then the -M flag needs to be passed to dalec, with the path to the directory that contains those files as the argument:

user@host:~$ cat util.dt
(module util)

(def util-fn (fn extern int (void) 123))
user@host:~$ dalec -c util.dt
user@host:~$ mkdir mylibdir
user@host:~$ mv libutil* mylibdir/
user@host:~$ cat test.dt
(import util)
(import cstdio)

(def main (fn extern-c int (void)
  (printf "%d\n" (util-fn))
  0))
user@host:~$ dalec test.dt
test.dt:1:1: error: /usr/local/lib/dale/libutil.dtm: No such file or directory
test.dt:1:1: error: unable to load module 'util'
test.dt:5:18: error: not in scope: 'util-fn'
user@host:~$ dalec -Mmylibdir test.dt
user@host:~$ ./a.out
123
user@host:~$
porky11 commented 7 years ago

works, thanks