jani-nykanen / a-flying-fish-experiment

Now with 256 colors!
6 stars 0 forks source link

Compile error on Mac (files it want for include not found). #1

Open Tricky1975 opened 5 years ago

Tricky1975 commented 5 years ago

As I am currently trying to train myself in C, I hope you don't mind me digging through your source codes trying to learn from you a bit. However trying to compile this through make gave me this:

gcc -Wall -O3 -o game src/engine/app.c src/engine/assets.c src/engine/bitmap.c src/engine/config.c src/engine/controls.c src/engine/frame.c src/engine/graphics.c src/engine/list.c src/engine/mathext.c src/engine/mesh.c src/engine/scene.c src/engine/sprite.c src/engine/transform.c src/engine/vector.c src/game/askquit.c src/game/camera.c src/game/decoration.c src/game/game.c src/game/player.c src/game/stage.c src/global.c src/intro/intro.c src/lib/parseword.c src/lib/tmxc.c src/main.c src/vpad.c -lSDL2 -lm
src/engine/config.c:14:10: fatal error: 'error.h' file not found
#include "error.h"
         ^~~~~~~~~
1 error generated.
src/engine/frame.c:7:10: fatal error: 'malloc.h' file not found
#include "malloc.h"
         ^~~~~~~~~~
1 error generated.
src/engine/graphics.c:9:10: fatal error: 'malloc.h' file not found
#include "malloc.h"
         ^~~~~~~~~~
1 error generated.
src/lib/tmxc.c:7:10: fatal error: 'malloc.h' file not found
#include "malloc.h"
         ^~~~~~~~~~
1 error generated.
make: *** [game] Error 1

Now I need to note that Mac will ALWAYS use clang and not gcc (even when you type gcc at the prompt, it will just redirect to clang. That's just Apple's coding philosophy that gcc should be banished from the world of programming), and I do not know if the difference between clang and gcc has anything to do with it this issue in an other repository appears to aim for that direction where they advise to #include in stead of malloc.h And here it's noted that error.h does not exist on several OSes (Including Mac and Cygwin).

image

jani-nykanen commented 5 years ago

I never made the game Mac-compatible, really. Actually I think in this project the building does not even work on other platforms than Linux (not even on Windows without some tweaking).

That header file issue might be caused by errors in include path, I don't know. malloc I understand, but that error.h should be a local file (it's also a global header, though), I wonder why the compiler cannot find it...

Anyway, my advice: don't try to compile my C projects, heh.

Tricky1975 commented 5 years ago

"Anyway, my advice: don't try to compile my C projects, heh." Is your coding style that "ugly"?

I've looked up about error.h which appears to be a GNU-only file: https://www.gnu.org/software/gnulib/manual/html_node/error_002eh.html

Maybe this explains its absence in MacOS????

jani-nykanen commented 5 years ago

Is your coding style that "ugly"?

Nah, but makefiles were made to work only on 64-bit Linux and "normal" gcc.

Also, the error.h I'm using is a local file (can be find in some source folder), not the global file. However, one possible problem might be that I use "stdio.h" like including for global files (i.e those in /usr/include/ etc.), so your compiler might require . If you replace every malloc.h with , or remove malloc and replace it with , maybe it'll work? (Now I think of it, in my newer projects I never include malloc, I include stdlib. I wonder why have I done it here...)

Tricky1975 commented 5 years ago

I shall try to take a look when I got the time. stdio is what I've used in my own C projects so far... Mac currently compiles in C99 by default and that has given me a few problems when compiling my C programs in Linux (since Linux does not appear to do that yet, and Windows is an even bigger problem, or so it seems). I am currently following a JavaScript/Scrumming course and my teacher loves C, and although C was not the target of this course he has been helping me on a few things with C, and so we found that one out.

Taking a look at my practise repo (don't laugh at the code there... that repo was only used for training), I do see stdio.h in nearly all my sources there, although I did use "stdio.h" in stead of and those programs did appear to work. Anyway, I'll try out later. Thanks for your time, anyway ;)

jani-nykanen commented 5 years ago

Wait, are you saying Linux & Windows have problems with C99? I'm positive those standards are fully supported, Linux gcc even has - or at least should have - some features from C11 (not threads, unfortunately).

Tricky1975 commented 5 years ago

My own C projects didn't compile (and if they did they lead to segmentation faults) on Linux unless I specifically add some extra parameters forcing gcc to use c99. On Linux Mint there even was an alias "c99" to take care of that. When I forced gcc to compile in c99 the stuff worked. At least on Linux Mint it did. My current programming teacher tried that one out for me. (I am still not that good in C, but that is what my teacher and I experienced when trying to get this test program compiled on Linux, which I wrote on a Mac. I'm trying to get the JCR6 system (which I already got succesfully working in BlitzMax, Go and C#) to work in C, and that is when I got this c99 conflict on my way. Of course, the computer on which I tried this is running Ubuntu 16.xx (because the mini-computer I can use twice a week to run Linux does not like later versions of Ubuntu. At least internet and internal networking stops working then), so I cannot fully rule out recent versions of Linux have this covered. All documentation I found on compiling c99 on Windows could be summarized as "forget it", especially through MinGW as it uses .dll files that appear c99 incompatible. Of course, all that was old too, so I really don't know if there's a "fix" already for that.

jani-nykanen commented 5 years ago

Now I do some research, it indeed looks like that not all C99 are supported by gcc. I guess I've been using mostly C89, then, since I haven't had to include -std=c99 flag and had no problems to get my code compiled. One StackOverflow answer said that if one wants to write portable C code, one should stick to C89 standard.

If you want to make your life even worse, try building DOS application using OpenWatcom C compiler. It has some nice extra restrictions like having to define variables in before any function calls in the beginning of each function.

C is a nice language performance wise and it feels good to program in a language that is not bloated with features, but there is a reason why I'm currently trying different languages (I made a game in Java, two games in Html5/Javascript and now I'm using C#)...

Tricky1975 commented 5 years ago

I gotta admit that the fact that C forces me to do a lot myself does indeed give me a bit of freedom, and I found a few (extremely handy) features in C I never found in a language before (Like macros and unions for example), but the fact that C is so unforgiving on runtime errors and has no memory management is getting to me sometimes... :wink:

jani-nykanen commented 5 years ago

Try to parse a text file, say a Wavefront OBJ 3D model file, in C. Or a part of an xml file (like reading some basic info from a Tiled map file). I have done both, and it's pure pain. Especially if you want to store stuff but you don't know how much content you have, so you have to dynamically allocate & reallocate memory, which means a lot of memory errors that sometimes happen, sometimes don't.

Tricky1975 commented 5 years ago

Yeah, that is EXACTLY the pain I'm facing while trying to get JCR6 to work in C, as JCR6 is swamped with data classes of which all elements have a variable width... It was originally desgined in BlitzMax and Go after all :(