cyclone
cyclone copied to clipboard
Allow programs to use (c-linker-options ...)
Arthur asked a good question:
why does (c-linker-options ...) only work with library definitions? Would it be too difficult to allow programs to use it too? I really found it elegant to use scheme code instead of passing flags to the command line and consequently depending other script language to automate compilation.
This is a good idea and should be possible. We would just need to treat c-linker-options
as a special top-level form for compiled programs, similar to import
.
I think it would be quite useful to have a (c-compiler-options ...)
too, both on libraries and programs. What do you think, @justinethier?
Boch (c-linker-options ...) and (c-compiler-options ...) would be useful for porting C libs. Maybe also a flag to the compiler would be useful. @justinethier, what do you think?
@arthurmaciel I agree. We can add c-compiler-options
as another library form and both as compiler forms.
I need to look at adding these to the compiler. It seems like both should be trivial to add but I think there is a bit more work involved. Let me add this to the roadmap for upcoming development.
It would also be helpful to have a -COPT or such option to specify the C compiler options from the command line.
Added -COPT
and the c-compiler-options
expression for libraries.
Still need to add support for specifying options from a program.
Updated to allow both c-linker-options
and c-compiler-options
to work at the top-level of a program.
Hi @justinethier!
Could you help me find what I am missing?
In t.scm
:
(import (scheme base)
(scheme write)
(cyclone foreign))
(c-compiler-options "-I/tmp")
(display "hello")
$ cyclone t.scm # version 0.34.0
Error: Unbound variable(s):
(c-compiler-options)
That's a good question @arthurmaciel - this should work. Let me reopen this issue and look into it.
@arthurmaciel In the meantime this hack will at least let you keep moving, but this is not the long-term solution:
(c-compiler-options "-I/tmp")
(define c-compiler-options list)
Thanks, Justin. Unfortunately the hack doesn't work here (now using cyclone 0.35.0
).
(import (scheme base)
(scheme write)
(cyclone foreign))
(c-compiler-options "-I/tmp")
(define c-compiler-options list)
(display "hello")
$ cyclone t.scm
$ ./t
[1] 88020 segmentation fault (core dumped) ./t
@arthurmaciel Alright, this is fixed on the master
branch now. This was broken by the changes to have cyclone
call itself as a subprocess before invoking the C compiler. Let me see if I can add a test case to ensure this continues to work going forward...