Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding include directories does not work (on Linux) #192

Closed
madebr opened this issue Jul 14, 2024 · 17 comments
Closed

Adding include directories does not work (on Linux) #192

madebr opened this issue Jul 14, 2024 · 17 comments

Comments

@madebr
Copy link

madebr commented Jul 14, 2024

While experimenting with cake, I tried to transpile a few sources from SDL2.
But adding -I <include-folder> appears to not work.

$ git clone https://github.com/libsdl-org/SDL /tmp/SDL -b SDL2 --depth 1
$ cake /tmp/SDL/test/testsprite2.c -I /tmp/SDL/include -o /tmp/newsrc.c
Cake 0.9.10
/tmp/SDL/test/testsprite2.c
/tmp/SDL/test/testsprite2.c:22:22: error: file SDL_test.h not found
 22 |#include "SDL_test.h"
    |                     ~
/tmp/SDL/include
file not found '/tmp/SDL/include'
/tmp/newsrc.c
file not found '/tmp/newsrc.c'

 3 files in 0.04 seconds
 2 errors 0 warnings 0 notes 

Copying all SDL headers to the test folder allows cake to start (but fail later):

$ cp /tmp/SDL/include/*.h /tmp/SDL/test/
$ cake /tmp/SDL/test/testsprite2.c -I /tmp/SDL/include -o /tmp/newsrc.c
Cake 0.9.10
/tmp/SDL/test/testsprite2.c
/tmp/SDL/test/SDL_stdinc.h:414:1: error: _Static_assert failed "sizeof(Uint64) == 8"
...
@thradams
Copy link
Owner

I think the problem is the extra space after -I .
For test purposes you can add at cakeconfig.h using pragma dir.
Was your test on windows or linux? cake -autoconfig generate the cakeconfig.h with the include directories of gcc on linux.

@thradams
Copy link
Owner

I tested on Windows.
No space after -I. cakeconfig already configured.

C:\Users\thiag\source\repos\SDL\test>cake -IC:\Users\thiag\source\repos\SDL\include testsprite.c
Cake 0.9.10
C:/Users/thiag/source/repos/SDL/test/testsprite.c

 1 files in 1.41 seconds
 0 errors 0 warnings 0 notes

It worked.

@madebr
Copy link
Author

madebr commented Jul 15, 2024

I'm running the tests on Linux.
And indeed, removing the space (-I/tmp/SDL/include) does not require me to copy the SDL headers anymore.

After running cake -autoconfig, recompiling src/build.c and rebuilding cake.

I get the following behavior:

$ cake /tmp/SDL/test/testsprite2.c -I/tmp/SDL/include -o /tmp/newsrc.c
Cake 0.9.10
/tmp/SDL/test/testsprite2.c
/tmp/SDL/include/SDL_stdinc.h:414:1: error: _Static_assert failed "sizeof(Uint64) == 8"
 [E106]
 414 |SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8)_Static_assert(sizeof(Uint64)==8,"sizeof(Uint64) == 8");
     |                                                    ~~~~~~~~~~~~~~                                           
/tmp/SDL/include/SDL_stdinc.h:415:1: error: _Static_assert failed "sizeof(Sint64) == 8"
 [E106]
 415 |SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8)_Static_assert(sizeof(Sint64)==8,"sizeof(Sint64) == 8");
     |                                                    ~~~~~~~~~~~~~~                                           
/tmp/SDL/include/SDL_pixels.h:305:9: error: not found 'SDL_static_cast' [E68]
 305 |        SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2')((((Uint32)(SDL_static_cast(Uint8,('Y'))))<<0)|(((Uint32)(SDL_static_cast(Uint8,('V'))))<<8)|(((Uint32)(SDL_static_cast(Uint8,('1'))))<<16)|(((Uint32)(SDL_static_cast(Uint8,('2'))))<<24)),
     |                                                              ~~~~~~~~~~~~~~~                                                                                                                                                                  
/tmp/SDL/include/SDL_pixels.h:305:9: error: expected TK_RIGHT_CURLY_BRACKET [E97]
 305 |        SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2')((((Uint32)(SDL_static_cast(Uint8,('Y'))))<<0)|(((Uint32)(SDL_static_cast(Uint8,('V'))))<<8)|(((Uint32)(SDL_static_cast(Uint8,('1'))))<<16)|(((Uint32)(SDL_static_cast(Uint8,('2'))))<<24)),
     |                                                              ~~~~~~~~~~~~~~~                                                                                                                                                                  
/tmp/SDL/include/SDL_pixels.h:305:9: error: empty declarator name?? unexpected [E65]
 305 |        SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2')((((Uint32)(SDL_static_cast(Uint8,('Y'))))<<0)|(((Uint32)(SDL_static_cast(Uint8,('V'))))<<8)|(((Uint32)(SDL_static_cast(Uint8,('1'))))<<16)|(((Uint32)(SDL_static_cast(Uint8,('2'))))<<24)),
     |                                                                                         ~                                                                                                                                                     
/tmp/SDL/include/SDL_pixels.h:305:9: error: expected TK_SEMICOLON [E97]
 305 |        SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2')((((Uint32)(SDL_static_cast(Uint8,('Y'))))<<0)|(((Uint32)(SDL_static_cast(Uint8,('V'))))<<8)|(((Uint32)(SDL_static_cast(Uint8,('1'))))<<16)|(((Uint32)(SDL_static_cast(Uint8,('2'))))<<24)),
     |                                                                                         ~                                                                                                                                                     
/tmp/newsrc.c
file not found '/tmp/newsrc.c'

 2 files in 0.24 seconds
 7 errors 0 warnings 0 notes 

@thradams
Copy link
Owner

I need more time to check . The problems seams to be on

Uint64, Uint8 etc..definition.

It may be that the code that declares Uint64 is checking for some compiler specific stuff.
Then we need to adapt or "clone" something from gcc.

@thradams
Copy link
Owner

(I never checked SDL code before, but it can be included for tests)

@thradams
Copy link
Owner

-E also may be useful because it can shows how Uint64 was defined

cl  -IC:\Users\thiag\source\repos\SDL\include testsprite.c -E

@madebr
Copy link
Author

madebr commented Jul 15, 2024

On gcc, SDL uses the libc types from stdint.h to define its Uint32, Sint32, ... types.
Does cake autoconvert these? Reading cppreference, they are c99.

I attached the output of /tmp/cake/src/cake -E /tmp/SDL/test/testsprite2.c -I/tmp/SDL/include -o /tmp/newsrc.c > /tmp/testsprite2_preproc.c:
testsprite2_preproc.txt

@thradams
Copy link
Owner

Found the problem

typedef long unsigned int uint64_t;
_Static_assert(sizeof(uint64_t) == 8, "");
int main(){}

The sizeof "long unsigned int" is different from gcc.
In gcc it compiles and in cake it fail.s
I will fix that. On windows it does not have this problem.

@thradams thradams reopened this Jul 15, 2024
@thradams
Copy link
Owner

This problem has been fixed.

typedef long unsigned int uint64_t;
_Static_assert(sizeof(uint64_t) == 8, "");
int main(){}

@madebr
Copy link
Author

madebr commented Jul 15, 2024

Indeed! Very nice!

I still see the SDL_DEFINE_PIXELFOURCC error. Should I create a new issue for that?

@madebr
Copy link
Author

madebr commented Jul 15, 2024

(I never checked SDL code before, but it can be included for tests)

One of the reasons I'm looking into cake is for this.
It would be useful to transpile SDL to c89 for deprecated platforms with no new toolchains.

@thradams
Copy link
Owner

It took me a while. (added cake to linux path was new to me etc)
I am on linux WSL . It is compiling in my machine.

tra@Thiago:~/SDL/test$ cake testsprite.c -I../include
Cake 0.9.10
/home/tra/SDL/test/testsprite.c

 1 files in 0.29 seconds
 0 errors 0 warnings 0 notes

@thradams
Copy link
Owner

linuxsdl.txt

@thradams
Copy link
Owner

(I never checked SDL code before, but it can be included for tests)

One of the reasons I'm looking into cake is for this. It would be useful to transpile SDL to c89 for deprecated platforms with no new toolchains.

The main motivation for target < C99 was to be compatible with C++ 98.
But if necessary I can add more C89 translations. (for loop is missing, designed initializers..)

more info
http://thradams.com/cake/manual.html#toc_12

@madebr
Copy link
Author

madebr commented Jul 15, 2024

The main motivation for target < C99 was to be compatible with C++ 98. But if necessary I can add more C89 translations. (for loop is missing, designed initializers..)

I suppose c++98 would be fine as well, as long as the public interface is a C interface.
The problem with c++ however is that is more pedantic: you can't assign a void pointer to a typed pointer without a warning/error.

linuxsdl.txt

Nice! I see an issue with FLT_MAX__FLT_MAX__ in the log.
The -Wenum-conversion warnings might need to be fixed by a cast in a helper macro.
The -Wdiv-by-zero warning is a thing the tests do to generate a nan float.

I don't know why, but I still see the SDL_DEFINE_PIXELFOURCC errors from #192 (comment) when caking testsprite2.c.

@madebr
Copy link
Author

madebr commented Jul 15, 2024

Building with -DTEST=ON makes the errors of #192 (comment) go away.
See #194

@thradams
Copy link
Owner

The

-DTEST

create a new main function that call test functions that are under #ifdef TEST groups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants