3

I have need to compile and statically link a Chicken program. I expect to use many extensions, most notably http-client.

I can compile the source with the following command:

csc -compile-syntax -static linux-setup.scm

or

csc -R http-client -compile-syntax -static linux-setup.scm

But when I run it, I get the following error:

Error: (require) cannot load extension: http-client

    Call history:

    ##sys#require           <--

I have also tried (declare (uses http-client)) in the source, with no success:

linux-setup.o: In function `f_369':
/mnt/data/Documents/Programming/chicken-scheme/linux-setup/linux-setup.c:219:
 undefined reference to `C_http_2dclient_toplevel'
collect2: error: ld returned 1 exit status

Error: shell command terminated with non-zero exit status 256: 'gcc' 'linux-setup.o'
 -o 'linux-setup' -L"/usr/lib"  -Wl,-R"/usr/lib" -static '/usr/lib/libchicken.a' -lm -ldl

Static linking is something I need. This is not an XY problem. I need my executables to run on a freshly-installed Linux system with no dependancies. This is the primary reason I switched from Common Lisp to Scheme in the first place.

What am I doing wrong, please?

Sod Almighty
  • 1,768
  • 1
  • 16
  • 29

1 Answers1

1

Assuming your program is in a-program.scm file:

csc -deploy a-program.scm
cd a-program/
chicken-install -deploy -p $PWD http-client

...et voilà!

edit: turns out that the proper answer to the problem posted is solved in this document: http://www.foldling.org/scheme.html#compiling-statically-linked-chicken-scheme-programs-with-extensions

dercz
  • 962
  • 6
  • 9
  • Well, that's handy to know...and technically it **will** run on a fresh Linux install...but it's not an answer to my question, which was "how do I get everything in the one executable?" There are one hundred and ninety files in the $PWD after running `chicken-install`. That is, I feel, a tad excessive. – Sod Almighty Aug 13 '16 at 02:59
  • I don't mean to be mean but the question was "I need my executables to run on a freshly-installed Linux system with no dependancies. (...) What am I doing wrong, please?" ;) Anyway there is a tedious way claimed to build a single self-contained executable which might work for you: http://www.foldling.org/scheme.html#compiling-statically-linked-chicken-scheme-programs-with-extensions -- note that -deploy has already created the .o files in a-program/ -- however this might be harder than just csc -static a-program.o a-program/*.o -o aprog ... good luck! – dercz Aug 13 '16 at 12:12
  • ps maybe you could also try gambit-c, it worked for me but I didn't mess up with packages othern than than matcher and irregex... – dercz Aug 13 '16 at 12:21
  • 1
    Thanks, I'll check those out. But in my question, when I said "static linking", I kinda meant "everything in one executable". That's usually what the term means, in my experience. – Sod Almighty Aug 13 '16 at 14:49
  • Looks like the foldling.org way is the correct solution. If you'd like to make it an answer, I'll accept it. – Sod Almighty Aug 13 '16 at 19:14
  • 1
    Static linking of eggs is one of the things we want to improve with CHICKEN 5 as well by making it easier to do the right thing. Asking egg authors to take care of it didn't work out so well, as we noticed with CHICKEN 3; most authors neglected the static versions of their eggs because so few people use static linking. Also, note that Gambit-C, while an excellent Scheme system in its own right, doesn't really _have_ an extension system, so the question is kind of moot, there. – sjamaan Aug 15 '16 at 06:46