I've got a module mymod in mymod.scm:
(module mymod (hello)
(import scheme)
(define (hello)
(display "Hello, World, I'm in mymod!")
(newline)))
and I've got a module trymod in trymod.scm:
(module trymod ()
(import scheme)
(import mymod)
(hello)
)
and when I compile them like this:
csc -s -J mymod.scm
csc -s mymod.import.scm
csc trymod.scm
it produces an executable trymod that runs and dynamically loads mymod.so,
unloads it, and loads it again, then produces the expected output, calling
the function hello in mymod as running it on macOS with
DYLD_PRINT_LIBRARIES=YES
./trymod shows.
...
dyld: loaded: <59A8239F-C28A-3B59-B8FA-11340DC85EDC> /usr/lib/libc++.1.dylib
dyld: loaded: <EBB10A36-BF4E-3C83-9B63-9D26028D43B9> ./mymod.so
dyld: unloaded: <EBB10A36-BF4E-3C83-9B63-9D26028D43B9> ./mymod.so
dyld: loaded: <EBB10A36-BF4E-3C83-9B63-9D26028D43B9> ./mymod.so
Hello, World, I'm in mymod!
However, I can't figure out how to do the same thing with mymod as
non-shared objects. I tried
csc -c -J mymod.scm
csc -c mymod.import.scm
csc -static -o trymod.static mymod.o mymod.import.o trymod.scm
but I got
Undefined symbols for architecture x86_64:
"_C_mymod_toplevel", referenced from:
_f_138 in trymod.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Error: shell command terminated with non-zero exit status 256: 'clang'
'mymod.import.o' 'mymod.o' 'trymod.o' -o 'trymod.static' -m64
-L/usr/local/Cellar/chicken/5.2.0/lib
/usr/local/Cellar/chicken/5.2.0/lib/libchicken.a -lm
What am I doing wrong?
--
T. Kurt Bond, [email protected], https://tkurtbond.github.io