jdah / jdh-8

An 8-bit minicomputer with a fully custom architecture

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does not compile on arch linux

chitramdasgupta opened this issue · comments

So I did the following:

git clone https://github.com/jdah/jdh-8.git
cd jdh-8
make

And I get the following error:

mkdir -p bin
clang -o emu/emu.o -c emu/emu.c -std=c11 -O0 -g -Wall -Wextra -Wpedantic -Wstrict-aliasing -Wno-pointer-arith -Wno-unused-parameter -Wno-gnu-zero-variadic-macro-arguments
emu/emu.c:21:34: warning: implicit declaration of function 'fileno' is invalid in C99 [-Wimplicit-function-declaration]
    struct pollfd pfds = { .fd = fileno(stdin), .events = POLLIN };
                                 ^
emu/emu.c:35:14: warning: implicit declaration of function 'strcasecmp' is invalid in C99 [-Wimplicit-function-declaration]
        if (!strcasecmp(speed, "realtime")) {
             ^
emu/emu.c:99:5: warning: implicit declaration of function 'strlcpy' is invalid in C99 [-Wimplicit-function-declaration]
    strlcpy(str, text, sizeof(str));
    ^
emu/emu.c:170:19: warning: implicit declaration of function 'fmemopen' is invalid in C99 [-Wimplicit-function-declaration]
        FILE *f = fmemopen((void *) out, n, "wb");
                  ^
emu/emu.c:170:15: warning: incompatible integer to pointer conversion initializing 'FILE *' (aka 'struct _IO_FILE *') with an expression of type 'int' [-Wint-conversion]
        FILE *f = fmemopen((void *) out, n, "wb");
              ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 warnings generated.
clang -o emu/kb.o -c emu/kb.c -std=c11 -O0 -g -Wall -Wextra -Wpedantic -Wstrict-aliasing -Wno-pointer-arith -Wno-unused-parameter -Wno-gnu-zero-variadic-macro-arguments
In file included from emu/kb.c:1:
In file included from emu/emu.h:4:
emu/../common/util.h:39:9: error: unknown type name 'ssize_t'; did you mean 'size_t'?
typedef ssize_t isize;
        ^~~~~~~
        size_t
/usr/lib/clang/12.0.1/include/stddef.h:46:23: note: 'size_t' declared here
typedef __SIZE_TYPE__ size_t;

1 error generated.
make: *** [Makefile:57: emu/kb.o] Error 1

Try adding the line #include <sys/types.h> in common/util.h.

No luck compiling it.

I added #include <sys/types.h> to the file common/util.h

But this still results in compilation errors:

mkdir -p bin
clang -o emu/libemu.o -c emu/libemu.c -std=c11 -O0 -g -Wall -Wextra -Wpedantic -Wstrict-aliasing -Wno-pointer-arith -Wno-unused-parameter -Wno-gnu-zero-variadic-macro-arguments
emu/libemu.c:45:17: warning: implicit declaration of function 'clock_gettime' is invalid in C99 [-Wimplicit-function-declaration]
    u64 start = NOW(),
                ^
emu/libemu.c:15:17: note: expanded from macro 'NOW'
        assert(!clock_gettime(MONO_CLOCK, &ts));            \
                ^
emu/libemu.c:45:17: error: use of undeclared identifier '_CLOCK_MONOTONIC_RAW'
emu/libemu.c:15:31: note: expanded from macro 'NOW'
        assert(!clock_gettime(MONO_CLOCK, &ts));            \
                              ^
emu/libemu.c:10:21: note: expanded from macro 'MONO_CLOCK'
        #define MONO_CLOCK _CLOCK_MONOTONIC_RAW
                           ^
emu/libemu.c:51:15: warning: implicit declaration of function 'clock_gettime' is invalid in C99 [-Wimplicit-function-declaration]
        now = NOW();
              ^
emu/libemu.c:15:17: note: expanded from macro 'NOW'
        assert(!clock_gettime(MONO_CLOCK, &ts));            \
                ^
emu/libemu.c:51:15: error: use of undeclared identifier '_CLOCK_MONOTONIC_RAW'
emu/libemu.c:15:31: note: expanded from macro 'NOW'
        assert(!clock_gettime(MONO_CLOCK, &ts));            \
                              ^
emu/libemu.c:10:21: note: expanded from macro 'MONO_CLOCK'
        #define MONO_CLOCK _CLOCK_MONOTONIC_RAW
                           ^
emu/libemu.c:82:41: warning: implicit declaration of function 'clock_gettime' is invalid in C99 [-Wimplicit-function-declaration]
        u64 sleep_time = ns_per_step - (NOW() - now);
                                        ^
emu/libemu.c:15:17: note: expanded from macro 'NOW'
        assert(!clock_gettime(MONO_CLOCK, &ts));            \
                ^
emu/libemu.c:82:41: error: use of undeclared identifier '_CLOCK_MONOTONIC_RAW'
emu/libemu.c:15:31: note: expanded from macro 'NOW'
        assert(!clock_gettime(MONO_CLOCK, &ts));            \
                              ^
emu/libemu.c:10:21: note: expanded from macro 'MONO_CLOCK'
        #define MONO_CLOCK _CLOCK_MONOTONIC_RAW
                           ^
emu/libemu.c:86:9: warning: implicit declaration of function 'nanosleep' is invalid in C99 [-Wimplicit-function-declaration]
        SLEEP(sleep_time);
        ^
emu/libemu.c:25:13: note: expanded from macro 'SLEEP'
            nanosleep(&req, &rem);                          \
            ^
4 warnings and 3 errors generated.
make: *** [Makefile:57: emu/libemu.o] Error 1

Try adding #define _POSIX_C_SOURCE 199309L at the beginning of emu/libemu.c right before #include <time.h>

I added #define _POSIX_C_SOURCE 199309L at the beginning of emu/libemu.c and I got the following error:

clang -o emu/libemu.o -c emu/libemu.c -std=c11 -O0 -g -Wall -Wextra -Wpedantic -Wstrict-aliasing -Wno-pointer-arith -Wno-unused-parameter -Wno-gnu-zero-variadic-macro-arguments
emu/libemu.c:46:17: error: use of undeclared identifier '_CLOCK_MONOTONIC_RAW'
    u64 start = NOW(),
                ^
emu/libemu.c:16:31: note: expanded from macro 'NOW'
        assert(!clock_gettime(MONO_CLOCK, &ts));            \
                              ^
emu/libemu.c:11:21: note: expanded from macro 'MONO_CLOCK'
        #define MONO_CLOCK _CLOCK_MONOTONIC_RAW
                           ^
emu/libemu.c:52:15: error: use of undeclared identifier '_CLOCK_MONOTONIC_RAW'
        now = NOW();
              ^
emu/libemu.c:16:31: note: expanded from macro 'NOW'
        assert(!clock_gettime(MONO_CLOCK, &ts));            \
                              ^
emu/libemu.c:11:21: note: expanded from macro 'MONO_CLOCK'
        #define MONO_CLOCK _CLOCK_MONOTONIC_RAW
                           ^
emu/libemu.c:83:41: error: use of undeclared identifier '_CLOCK_MONOTONIC_RAW'
        u64 sleep_time = ns_per_step - (NOW() - now);
                                        ^
emu/libemu.c:16:31: note: expanded from macro 'NOW'
        assert(!clock_gettime(MONO_CLOCK, &ts));            \
                              ^
emu/libemu.c:11:21: note: expanded from macro 'MONO_CLOCK'
        #define MONO_CLOCK _CLOCK_MONOTONIC_RAW
                           ^
3 errors generated.
make: *** [Makefile:57: emu/libemu.o] Error 1

_CLOCK_MONOTIC_RAW seems to be the culprit.

Instead of doing it in 'libemu.c' do it in 'emu.c' right before the line that says '#include <time.h>'

But there is no '#include <time.h>' in emu.c

My bad, it was only in libemu.c. Replace _CLOCK_MONOTONIC_RAW with CLOCK_MONOTONIC_RAW in libemu.c.

On Archlinux, I found out I have to change two more things to build it.

  • In Makefile, capitalise all occurrence of sdl.
  • In emu/emu.c, use strncpy instead of strlcpy as it's a BSD thing.
commented

This is all in with ca57c54, can anyone running arch confirm that these changes work?

Again, -lSDL2 is needed instead of -lsdl2, and strlcpy isn't a POSIX function. :)

commented

Ah, yeah, can see it's a nonstandard BSD thing.

But on the capitalisation of SDL, is there any easy way to detect Arch specifically (or preferably just the presence of SDL2 over sdl2)? I have no machine to test on.

commented

Okay, Arch should now be fixed. But it depends on ARCH_LINUX := $(shell grep "Arch Linux" /etc/os-release 2>/dev/null) working on Arch, so can anyone confirm now that it works properly?

Why not use sdl-config just like on Windows?

@MikeWalrus I dont think it would work because I dont think sdl-config works on arch linux (and jdah im gonna get an arch vm soon to test it out)

@MikeWalrus I dont think it would work because I dont think sdl-config works on arch linux (and jdah im gonna get an arch vm soon to test it out)

I think sdl2-config --cflags --libs do work though.

@MikeWalrus I dont think it would work because I dont think sdl-config works on arch linux (and jdah im gonna get an arch vm soon to test it out)

I think sdl2-config --cflags --libs do work though.

Probably... you can try

@chitramdasgupta It works on arch linux...

This is all in with ca57c54, can anyone running arch confirm that these changes work?

@jdah Yup! It works

Requesting close to this issue as problem has been fixed