sasagawa888 / eisl

ISLisp interpreter/compiler
Other
267 stars 22 forks source link

make error on MacOS #296

Closed StarSugar closed 9 months ago

StarSugar commented 9 months ago
cc -Icii/include -g -Wall -Wextra -D_FORTIFY_SOURCE=2 -I/usr/include/ncurses -U_XOPEN_SOURCE -D_XOPEN_SOURCE=700 -D_XOPEN_SOURCE_EXTENDED -Inana/src -O3 -flto -DNDEBUG=1 -DWITHOUT_NANA=1 -std=c17 -DSHAREDIR=/usr/local/share/eisl -c main.c -o main.o
main.c:473:28: error: use of undeclared identifier '_SC_NPROCESSORS_CONF'
    worker_count = sysconf(_SC_NPROCESSORS_CONF) - 1;
                           ^
1 error generated.
make: *** [main.o] Error 1

It seems like _SC_NPROCESSORS_CONF isn't exist in MacOS, please try sysctlbyname("hw.logicalcpu", ...). Also, please adding a line #include <pthread.h> in eisl.h to get identifiers like pthread_cond_t, it is important for clang.

StarSugar commented 9 months ago

I am sad to say even these errors are solved, eisl can not runs well on MacOS.

sasagawa888 commented 9 months ago

I appreciate the report. By the way, I do not own a Mac. It would be very helpful if someone could contribute to error fixing.

sasagawa888 commented 9 months ago

I added "#include " to eisl.h. Will it work?

StarSugar commented 9 months ago

Yes it works, but it still can't be compiled unless i let worker_count = 2; as mentioned above. And I got a segmentation fault when running echo '(load "library/compiler.lsp") (compile-file "$<")' | ./eisl -r. In syntax.c queue out of bound at line 2549, loading null pointer at line 2601.

sasagawa888 commented 9 months ago

I have understood the situation. I will carefully review the code.

sasagawa888 commented 9 months ago

I fixed. Will it work? sysconf(_SC_NPROCESSORS_CONF) may operate correctly depending on the OS, and in such cases, it could potentially result in a negative number. It is assumed that the current CPU has at least 4 cores. Therefore, in the event of a negative number, we set it to 4 - 1 = 3.

StarSugar commented 9 months ago

No, it won't, because there is no macro _SC_NPROCESSORS_CONF's definition unless the words -D_XOPEN_SOURCE=700 -D_XOPEN_SOURCE_EXTENDED in makefile are deleted. There is a condition in MacOS's :

#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
#define _SC_NPROCESSORS_CONF        57
#define _SC_NPROCESSORS_ONLN        58
#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */

Although do so will make addwstr no longer valid.

How about just define -D_XOPEN_SOURCE=700 -D_XOPEN_SOURCE_EXTENDED when including and , and undefine it after including like:

#define _XOPEN_SOURCE=700
#define _XOPEN_SOURCE_EXTENDED
#include <ncurse.h>
#undef _XOPEN_SOURCE
#undef _XOPEN_SOURCE_EXTENDED
StarSugar commented 9 months ago

I pulled a request. The changes allows the c files can be compiled on MacOS.

sasagawa888 commented 9 months ago

Thank you for the pull request. I have made modifications to make it work on Linux. Please accept them.

StarSugar commented 9 months ago

I closed this issue, for c codes compiling error had been solved.