carp-lang / Carp

A statically typed lisp, without a GC, for real-time applications.
Apache License 2.0
5.51k stars 174 forks source link

Getting Started: fatal error: "stdbool.h" file not found #332

Closed theronic closed 5 years ago

theronic commented 5 years ago

Hello! I'm trying to get Carp going on OS X. I followed all the installation steps, but trying to eval anything throws a "stdbool.h" not found error. I assume Carp is trying to use clang, which I have installed. Running clang -v shows:

clang version 6.0.1 (emscripten 1.38.12 : 1.38.12) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Users/petrus/Projects/wallfly/emsdk/clang/e1.38.12_64bit

The Error:

$ carp
Welcome to Carp 0.2.0
This is free software with ABSOLUTELY NO WARRANTY.
Evaluate (help) for more information.
鲮 (eval (my-function 12345 "w00t"))
In file included from ./out//main.c:1:
In file included from /Users/petrus/Projects/Carp/core/carp_debug.h:1:
/Users/petrus/Projects/Carp/core/core.h:5:10: fatal error: 'stdbool.h' file not found
#include <stdbool.h>
         ^~~~~~~~~~~
1 error generated.
carp: callCommand: clang -fPIC -lm ./out//main.c -shared -o "./out//Untitled"   -I/Users/petrus/Projects/Carp/core/  -g  (exit 1): failed

I'm sure this is not a Carp-specific issue, but I have no recourse to solve it.

theronic commented 5 years ago

I managed to get things going by setting compiler to gcc, but I don't know how to make it stick?

(Project.config "compiler" "gcc")

--important-flag didn't work

eriksvedang commented 5 years ago

Hi!

You can make it stick by putting a file at ~/.carp/profile.carp (we should document this better, sorry)

Also, Clang should work if it knows it should use C99. Perhaps we need to send that flag as default..?

hellerve commented 5 years ago

We could alternatively also just define the macros bool, true, and false ourselves to get rid of the header (that’s basically all it does anyway).

This would make the program more portable; the header is prefixed with std, but it isn’t actually super portable.

Extended info about the header My assertions are mostly based [on the ISO standard](https://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdbool.h.html). YMMV. For reference, this is what it looks like on my machine (as provided by LLVM): ```C /* Don't define bool, true, and false in C++, except as a GNU extension. */ #ifndef __cplusplus #define bool _Bool #define true 1 #define false 0 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* Define _Bool as a GNU extension. */ #define _Bool bool #if __cplusplus < 201103L /* For C++98, define bool, false, true as a GNU extension. */ #define bool bool #define false false #define true true #endif #endif #define __bool_true_false_are_defined 1 ``` The relevant definitions are these: ```C #define bool _Bool #define true 1 #define false 0 #define __bool_true_false_are_defined 1 ``` They are trivially inlineable and not really subject to change. Alternatively, we could just use the `_Bool` type, but it doesn’t fit the naming cheme and isn’t particularly pretty.
eriksvedang commented 5 years ago

That's a good idea, lets do that! I think we still need to enforce C99 though, it's what the emitted code expects.

hellerve commented 5 years ago

Is that a lower bound or a constraint?

eriksvedang commented 5 years ago

Lower bound.

hellerve commented 5 years ago

This should be fixed by #334. @theronic if you want you can pull the latest version and play around with it; do tell us if there are any other issues!

eriksvedang commented 5 years ago

I'll close this for now...