cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

Clang complains about lack of ansi compliance (use of long long) on OSX

Open iCodeSometime opened this issue 6 years ago • 13 comments

On OSX using Clang, I get errors about long long not being a supported datatype in ansi C.

I am building through the following process

git clone https://github.com/DaveGamble/cJSON
cd cJSON
mkdir build
cd build
cmake ..
make

The full error message I receive is:

In file included from /Users/kennethcochran/programming/libsource/cJSON/tests/print_number.c:24:
In file included from /Users/kennethcochran/programming/libsource/cJSON/tests/unity/src/unity.h:16:
/Users/kennethcochran/programming/libsource/cJSON/tests/unity/src/unity_internals.h:73:10: error: 
      'long long' is an extension when C99 mode is not enabled [-Werror,-Wlong-long]
    #if (UINTPTR_MAX <= 0xFFFF)
         ^
/usr/include/stdint.h:132:23: note: expanded from macro 'UINTPTR_MAX'
#define UINTPTR_MAX       UINT64_MAX
                          ^
/usr/include/stdint.h:87:27: note: expanded from macro 'UINT64_MAX'
#define UINT64_MAX        18446744073709551615ULL
                          ^
In file included from /Users/kennethcochran/programming/libsource/cJSON/tests/print_number.c:24:
In file included from /Users/kennethcochran/programming/libsource/cJSON/tests/unity/src/unity.h:16:
/Users/kennethcochran/programming/libsource/cJSON/tests/unity/src/unity_internals.h:75:12: error: 
      'long long' is an extension when C99 mode is not enabled [-Werror,-Wlong-long]
    #elif (UINTPTR_MAX <= 0xFFFFFFFF)
           ^
/usr/include/stdint.h:132:23: note: expanded from macro 'UINTPTR_MAX'
#define UINTPTR_MAX       UINT64_MAX
                          ^
/usr/include/stdint.h:87:27: note: expanded from macro 'UINT64_MAX'
#define UINT64_MAX        18446744073709551615ULL
                          ^
In file included from /Users/kennethcochran/programming/libsource/cJSON/tests/print_number.c:24:
In file included from /Users/kennethcochran/programming/libsource/cJSON/tests/unity/src/unity.h:16:
/Users/kennethcochran/programming/libsource/cJSON/tests/unity/src/unity_internals.h:77:12: error: 
      'long long' is an extension when C99 mode is not enabled [-Werror,-Wlong-long]
    #elif (UINTPTR_MAX <= 0xFFFFFFFFFFFFFFFF)
           ^
/usr/include/stdint.h:132:23: note: expanded from macro 'UINTPTR_MAX'
#define UINTPTR_MAX       UINT64_MAX
                          ^
/usr/include/stdint.h:87:27: note: expanded from macro 'UINT64_MAX'
#define UINT64_MAX        18446744073709551615ULL
                          ^
3 errors generated.
make[2]: *** [tests/CMakeFiles/print_number.dir/print_number.c.o] Error 1
make[1]: *** [tests/CMakeFiles/print_number.dir/all] Error 2
make: *** [all] Error 2

iCodeSometime avatar Jun 23 '18 23:06 iCodeSometime

I just switched the compiler flag from c89 to c99 in CMakeLists.txt to work around this for now.

iCodeSometime avatar Jun 24 '18 01:06 iCodeSometime

Hm, seems like the testing framework I'm using doesn't completely follow ANSI C after all.

For now you can fix this by not building the testing framework with -DENABLE_CJSON_TEST=Off

FSMaxB avatar Jun 24 '18 19:06 FSMaxB

Thanks!

On Sun, Jun 24, 2018, 2:15 PM Max Bruckner [email protected] wrote:

Hm, seems like the testing framework I'm using doesn't completely follow ANSI C after all.

For now you can fix this by not building the testing framework with -DENABLE_CJSON_TEST=Off

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DaveGamble/cJSON/issues/275#issuecomment-399780319, or mute the thread https://github.com/notifications/unsubscribe-auth/AD9PCoauQYrffAIkQhfbRkKkuuEXdTN2ks5t_-VhgaJpZM4U09hA .

iCodeSometime avatar Jun 24 '18 19:06 iCodeSometime

I pushed a possible fix to the long-long-fix branch, can you check if that fixes it?

FSMaxB avatar Jun 24 '18 19:06 FSMaxB

That does not fix the error. It's still trying to #include <stdint.h> I did the following:

rm -rf build
git pull
git checkout long-long-fix
git clean -f
git reset --hard
mkdir build
cd build
cmake ..
make

Same error as far as I can tell.

iCodeSometime avatar Jun 24 '18 19:06 iCodeSometime

Then I'll have to take a closer look at it next week. What version of Xcode did you use to install Clang?

FSMaxB avatar Jun 24 '18 19:06 FSMaxB

Version 9.2 (9C40b)

and here's the compiler version

$ cc --version
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

iCodeSometime avatar Jun 24 '18 19:06 iCodeSometime

I can't seem to reproduce this with (Apple LLVM version 9.0.0 (clang-900.0.39.2). (commandline tools installed separately without downgrading Xcode).

I will try downgrading Xcode next.

FSMaxB avatar Jun 27 '18 18:06 FSMaxB

Still cannot reproduce it, do you have some additional compiler flags set?

env | grep CFLAGS

FSMaxB avatar Jun 27 '18 19:06 FSMaxB

Do you have a 32 bit system?

FSMaxB avatar Jun 27 '18 19:06 FSMaxB

env | grep CFLAGS does not return anything.

It is 64 bit.

If it helps, here's the full output when compiling with cmake .. && make: https://gist.github.com/kennycoc/5d3ce6d4b90fadb16a6a9f3da8840d9b

iCodeSometime avatar Jun 27 '18 19:06 iCodeSometime

Seems like it is still includint stdint.h and the long long comes in the form of a literal.

Hm.

FSMaxB avatar Jun 29 '18 05:06 FSMaxB

Just hit this issue on macOS 11.1 - trivial fix is to change std=c89 to std=c99 i CMakeLists.txt as suggested above

prusnak avatar Feb 01 '21 18:02 prusnak