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

-Wformat error #10

Closed
IngwiePhoenix opened this issue Feb 16, 2019 · 4 comments
Closed

-Wformat error #10

IngwiePhoenix opened this issue Feb 16, 2019 · 4 comments

Comments

@IngwiePhoenix
Copy link

platform_libc.c:18:53: error: format specifies type 'int' but the argument has type 'unsigned long' [-Werror,-Wformat]
        FATAL("Could not allocate %d bytes for %s", (int)nmemb * size, name);
                                  ~~                ^~~~~~~~~~~~~~~~~
                                  %lu
./util.h:20:21: note: expanded from macro 'FATAL'
    fprintf(stderr, __VA_ARGS__); exit(1); \
                    ^~~~~~~~~~~
platform_libc.c:28:53: error: format specifies type 'int' but the argument has type 'unsigned long' [-Werror,-Wformat]
        FATAL("Could not allocate %d bytes for %s", (int)nmemb * size, name);
                                  ~~                ^~~~~~~~~~~~~~~~~
                                  %lu
./util.h:20:21: note: expanded from macro 'FATAL'
    fprintf(stderr, __VA_ARGS__); exit(1); \
                    ^~~~~~~~~~~
2 errors generated.
make: *** [platform_libc.o] Error 1

I can fix the Makefile on my own but you may want to fix this. :)

@IngwiePhoenix
Copy link
Author

Also as a side note, on Mac OS, this happens later on:

Ingwie@Ingwies-MBP.fritz.box ~/W/g/wac $ emmake make 
gcc  -DPLATFORM=1 -std=gnu99 -m32 -g -c wa.c -o wa.o
gcc  -DPLATFORM=1 -std=gnu99 -m32 -g -c util.c -o util.o
gcc  -DPLATFORM=1 -std=gnu99 -m32 -g -c thunk.c -o thunk.o
gcc  -DPLATFORM=1 -std=gnu99 -m32 -g -c platform_libc.c -o platform_libc.o
platform_libc.c:18:53: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
        FATAL("Could not allocate %d bytes for %s", (int)nmemb * size, name);
                                  ~~                ^~~~~~~~~~~~~~~~~
                                  %lu
./util.h:20:21: note: expanded from macro 'FATAL'
    fprintf(stderr, __VA_ARGS__); exit(1); \
                    ^~~~~~~~~~~
platform_libc.c:28:53: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
        FATAL("Could not allocate %d bytes for %s", (int)nmemb * size, name);
                                  ~~                ^~~~~~~~~~~~~~~~~
                                  %lu
./util.h:20:21: note: expanded from macro 'FATAL'
    fprintf(stderr, __VA_ARGS__); exit(1); \
                    ^~~~~~~~~~~
2 warnings generated.
ar rcs wa.a wa.o util.o thunk.o platform_libc.o
gcc  -DPLATFORM=1 -std=gnu99 -m32 -g -c wac.c -o wac.o
gcc  -DPLATFORM=1 -std=gnu99 -m32 -g -rdynamic -Wl,--no-as-needed -o wac \
	    -Wl,--start-group wa.a wac.o -Wl,--end-group -lm -ldl -ledit
ld: unknown option: --no-as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [wac] Error 1

@kanaka kanaka closed this as completed in 6d6f440 Feb 20, 2019
@kanaka
Copy link
Owner

kanaka commented Feb 20, 2019

@IngwiePhoenix I wasn't seeing those warning with my version of gcc (5.4.0) but I've pushed changes that should fix that. Can you check and verify that it builds for you?

@IngwiePhoenix
Copy link
Author

On OS X, the default compiler is LLVM Clang. Howeve,r as you mentioned GCC, I decided to change my make invocation into this:

Ingwie@Ingwies-Macbook-Pro.local ~/W/g/wac $ env HOST_CC=/usr/local/opt/gcc/bin/gcc-8 CFLAGS="-I "(xcrun --show-sdk-path)/usr/include make
/usr/local/opt/gcc/bin/gcc-8 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -DPLATFORM=1 -std=gnu99 -m32 -g -c wa.c -o wa.o
/usr/local/opt/gcc/bin/gcc-8 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -DPLATFORM=1 -std=gnu99 -m32 -g -c util.c -o util.o
/usr/local/opt/gcc/bin/gcc-8 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -DPLATFORM=1 -std=gnu99 -m32 -g -c thunk.c -o thunk.o
/usr/local/opt/gcc/bin/gcc-8 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -DPLATFORM=1 -std=gnu99 -m32 -g -c platform_libc.c -o platform_libc.o
ar rcs wa.a wa.o util.o thunk.o platform_libc.o
/usr/local/opt/gcc/bin/gcc-8 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -DPLATFORM=1 -std=gnu99 -m32 -g -c wac.c -o wac.o
/usr/local/opt/gcc/bin/gcc-8 -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -DPLATFORM=1 -std=gnu99 -m32 -g -rdynamic -Wl,--no-as-needed -o wac \
	    -Wl,--start-group wa.a wac.o -Wl,--end-group -lm -ldl -ledit
ld: unknown option: --no-as-needed
collect2: error: ld returned 1 exit status
make: *** [wac] Error 1

Note, I am using the Fish shell - that is why the command substition is a little bit off and weird-looking.

But as you see, warnings gone! :)

@kanaka kanaka reopened this Feb 20, 2019
@kanaka
Copy link
Owner

kanaka commented Feb 21, 2019

That means that the ld on OS X doesn't support the --no-as-needed flag. I suspect that you can probably drop that flag and you should be okay. It might not be needed on Linux (I think --no-as-needed is default but there was a valid reason I needed it in the past). But it will probably be a while before I can around to testing that for sure. I'm going to close the bug for now since the issue is specific to OS X ld.

@kanaka kanaka closed this as completed Feb 21, 2019
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