macOS Big Sur, $(make) fails
$ pwd
/Users/XXX/tools/corange
$ ls
LICENCE.md README.md corange.ico demos obj
Makefile assets_core corange.rc include src
$ sudo make
Password:
gcc src/cengine.c -c -I ./include -std=gnu99 -Wall -Werror -Wno-unused -O3 -g -fPIC -o obj/cengine.o
src/cengine.c:6:7: error: variable 'p' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (unlikely(strlen(path) >= PATH_MAX)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/cengine.h:115:21: note: expanded from macro 'unlikely'
#define unlikely(x) __builtin_expect((x),0)
^~~~~~~~~~~~~~~~~~~~~~~
src/cengine.c:12:10: note: uninitialized use occurs here
return p;
^
src/cengine.c:6:3: note: remove the 'if' if its condition is always false
if (unlikely(strlen(path) >= PATH_MAX)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/cengine.c:4:3: note: variable 'p' is declared here
fpath p;
^
1 error generated.
make: *** [obj/cengine.o] Error 1
Tried on Linux Mint last time, worked fine. Switched to Big Sur last month. Most important thing, I'm a noob.
$ uname -a
Darwin XXXMacBook-Air.local 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64
Could not compile
$ pwd
/Users/XXX/tools/corange/demos/sea
$ ls
Makefile assets sea.c
$ make
gcc sea.c -I../../include -std=gnu99 -Wall -Werror -Wno-unused -O3 -g -lcorange -framework OpenGL -lSDL2main -lSDL2 -lSDL2_net -lSDL2_mixer -o sea
sea.c:123:79: error: function definition is not allowed here
collision collision_test_ellipsoid(void* x, vec3* position, vec3* velocity) {
^
sea.c:130:74: error: use of undeclared identifier 'collision_test_ellipsoid'
collision_response_slide(g_dr, &test_ellipsoid.center, &test_velocity, collision_test_ellipsoid);
^
sea.c:185:71: error: function definition is not allowed here
collision collision_camera(void* x, vec3* position, vec3* velocity) {
^
sea.c:189:59: error: use of undeclared identifier 'collision_camera'; did you mean 'collision_merge'?
collision_response_slide(g_dr, &c->position, &velocity, collision_camera);
^~~~~~~~~~~~~~~~
collision_merge
../../include/cphysics.h:21:11: note: 'collision_merge' declared here
collision collision_merge(collision c0, collision c1);
^
4 errors generated.
make: *** [sea] Error 1
And I have SDL2 installed:
$ brew list | grep sdl
sdl2
sdl2_gfx
sdl2_image
sdl2_mixer
sdl2_net
sdl2_ttf
$ clang --version
Apple clang version 12.0.5 (clang-1205.0.22.9)
Target: x86_64-apple-darwin20.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
send help uwu
show GCC version please
But you can try redefine macros 'unlikely'
in engine.h
-#define likely(x) __builtin_expect((x),1)
-#define unlikely(x) __builtin_expect((x),0)
+#define likely(x) x
+#define unlikely(x) x
or before try use clang make clean ; make CC=clang
$ gcc-10 --version
gcc-10 (Homebrew GCC 10.3.0) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ vim cengine.h
$ ls
SDL2 cengine.h cnet.h data
assets centity.h corange.h entities
casset.h cgraphics.h cphysics.h rendering
caudio.h cjoystick.h cui.h ui
$ cd ..
$ ls
LICENCE.md README.md corange.ico demos obj
Makefile assets_core corange.rc include src
$ make
gcc src/cengine.c -c -I ./include -std=gnu99 -Wall -Werror -Wno-unused -O3 -g -fPIC -o obj/cengine.o
src/cengine.c:6:16: error: variable 'p' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (unlikely(strlen(path) >= PATH_MAX)) {
~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
./include/cengine.h:119:21: note: expanded from macro 'unlikely'
#define unlikely(x) x
^
src/cengine.c:12:10: note: uninitialized use occurs here
return p;
^
src/cengine.c:6:3: note: remove the 'if' if its condition is always false
if (unlikely(strlen(path) >= PATH_MAX)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/cengine.c:4:3: note: variable 'p' is declared here
fpath p;
^
1 error generated.
make: *** [obj/cengine.o] Error 1
$ make CC=gcc-10 CFLAGS=" -I/usr/local/include/SDL2 -L/usr/local/lib"
gcc-10 src/cengine.c -c -I/usr/local/include/SDL2 -L/usr/local/lib -o obj/cengine.o
src/cengine.c:1:10: fatal error: cengine.h: No such file or directory
1 | #include "cengine.h"
| ^~~~~~~~~~~
compilation terminated.
make: *** [obj/cengine.o] Error 1
@fedor-elizarov Actually I was going to learn C by making games... I don't really know, like, should I edit #include "cengine.h" to something like #include "../include/cengine.h"?
$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.9)
Target: x86_64-apple-darwin20.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ gcc-10 --version
gcc-10 (Homebrew GCC 10.3.0) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I was going to learn C by making games
Good idea!
#include "cengine.h" == #include "../include/cengine.h" becouse compiler have option -I../../include
- 1 Dont use sudo for compile
- 2 Dont use make install for start learning
Ok. If you learn C use simple methods
- 1 Clone Corange
- 2
make - 3
rm libcorange.so(for static compilation. if you have .a and .so you take conflict) - 4
cd demos - 5 just copy someone demo (for example ui demo) folder and rename
my_awesome_game(stay in demo folder!) - 6 rename ui.c to my_awesome_game.c
- 7 clear or modify source code
- 8 in Makefine rename APP name
APP=my_awesome_game - 9
make && ./my_awesome_game - Done! You app work!
if you need modify engine edit code and make; rm libcorange.so and go you Corange/demos/my_awesome_game/ and make && ./my_awesome_game
- you system clean
- you all code experiments in
./demosfolder (for new experiments just copy new folder and rename *.c and APP in makefile. or create template) - you can modify engine and recompile without install in you system.
you tested demos?
And sorry for my english =)
#include "cengine.h" == #include "../include/cengine.h" becouse compiler have option -I../../include it Makefiles in ./demo/*/Makefile
Ok. if you can give full log
git clone https://github.com/orangeduck/Corange.git
cd Corange
make
rm libcorange.so
cd ./demos/ui/
make && ./ui
@fedor-elizarov Wow, Makefile looks interesting! ^_^
I would like to test these demos but I feel like maybe there's something tricky about macOS... Or is it just because I'm such a noob?
$ ls
Makefile noise.c noise.fs noise.mat noise.vs
$ make
gcc-10 noise.c -I../../include:/usr/local/include/SDL2 -L/usr/local/lib -std=gnu99 -Wall -Werror -Wno-unused -O3 -g -lcorange -framework OpenGL -lSDL2main -lSDL2 -lSDL2_net -lSDL2_mixer -o noise
In file included from ../../include/corange.h:24,
from noise.c:1:
../../include/cengine.h:30:10: fatal error: SDL2/SDL_opengl.h: No such file or directory
30 | #include <SDL2/SDL_opengl.h>
| ^~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [noise] Error 1
I do have everything under /usr/local/include/SDL2 tho,
$ pwd
/usr/local/include/SDL2
$ ls | grep SDL_opengl.h
SDL_opengl.h
so I'm just trying to fix every #include statement by hand (adding ../../include inside of <>) since -I../../include not seem working...
This is what I'm doing right now: #include <corange.h> ==> #include <../../include/corange.h> seems working? so far so good...
#include "cengine.h" == #include "../include/cengine.h" becouse compiler have option -I../../include it Makefiles in ./demo/*/Makefile
Ok. if you can give full log
git clone https://github.com/orangeduck/Corange.git cd Corange make rm libcorange.so cd ./demos/ui/ make && ./ui
$ git clone https://github.com/orangeduck/Corange.git
正克隆到 'Corange'...
remote: Enumerating objects: 9288, done.
remote: Counting objects: 100% (22/22), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 9288 (delta 7), reused 6 (delta 2), pack-reused 9266
接收对象中: 100% (9288/9288), 234.88 MiB | 3.40 MiB/s, 完成.
处理 delta 中: 100% (6085/6085), 完成.
正在更新文件: 100% (666/666), 完成.
$ cd Corange
$ make
mkdir obj
gcc src/casset.c -c -I ./include -std=gnu99 -Wall -Werror -Wno-unused -O3 -g -fPIC -o obj/casset.o
gcc src/caudio.c -c -I ./include -std=gnu99 -Wall -Werror -Wno-unused -O3 -g -fPIC -o obj/caudio.o
gcc src/cengine.c -c -I ./include -std=gnu99 -Wall -Werror -Wno-unused -O3 -g -fPIC -o obj/cengine.o
src/cengine.c:6:7: error: variable 'p' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (unlikely(strlen(path) >= PATH_MAX)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/cengine.h:115:21: note: expanded from macro 'unlikely'
#define unlikely(x) __builtin_expect((x),0)
^~~~~~~~~~~~~~~~~~~~~~~
src/cengine.c:12:10: note: uninitialized use occurs here
return p;
^
src/cengine.c:6:3: note: remove the 'if' if its condition is always false
if (unlikely(strlen(path) >= PATH_MAX)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/cengine.c:4:3: note: variable 'p' is declared here
fpath p;
^
1 error generated.
make: *** [obj/cengine.o] Error 1
$
@fedor-elizarov Here's the full log...
OK I give up, there're hundreds of .h files in there, maybe I should write a python script to add absolute path to all the #includes
Thanks. I myself do not understand, maybe this is specific to macOS (I don't have it but it shouldn't matter )
maybe I should write a python script to add absolute path to all the #includes
NOOOOOOOOOOOOOOOOOOOOOOOOOO!! ))))))))))))))))))))
Do not give up! In programming, you just need to find out where the problem is and solve it.
first try make CC=gcc-9 if you have gcc-9 if it no help open ./Corange/include/cengine.h and edit
#define likely(x) x // __builtin_expect((x),1)
#define unlikely(x) x //__builtin_expect((x),0)
and make clean && make or make clean && make CC=gcc-9
@jdek Hello, why is this happening ?
@anzhi0708
It’s late in the evening and I’m going to bed. Do not give up. It's not a big problem. I want to sleep and my head doesn't work. But together we will solve the problem. Maybe not right away.
@fedor-elizarov Have a sweet dream ^^ Thanks for your help sir
@anzhi0708 Thanks ::)
Hi @anzhi0708 you try compile engine with gcc-9 or/and replace likely/unlikely macros?
Hi @anzhi0708 ,
I got the same error while compiling the library on macOS Mojave.
The problem is on the compiler and the LFLAGS for the linker.
As @fedor-elizarov has mentioned:
Hi @anzhi0708 you try compile engine with gcc-9 or/and replace likely/unlikely macros?
You need to change the compiler to gcc-9. Better not use other versions, because I tried gcc-11 and the compilation failed at the linker stage.
$ gcc-9 --version
gcc-9 (Homebrew GCC 9.4.0) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For some reasons, the gcc-9 on macOS cannot find the header files correctly.
Change your the CFLAG and LFLAG in your Makefile like this:
-CFLAGS = -I ./include -std=gnu99 -Wall -Werror -Wno-unused -O3 -g
-LFLAGS = -lSDL2 -lSDL2_mixer -lSDL2_net -shared -g
+CFLAGS = -I ./include -I /usr/local/include -std=gnu99 -Wall -Werror -Wno-unused -O3 -g
+LFLAGS = `sdl2-config --libs --cflags` -lSDL2_mixer -lSDL2_net -shared -g
I installed SDL2 and other dependencies using homebrew, thus I added the path where the headers are installed. This works for me.
Good luck.