__STDC_FORMAT_MACROS error building LibCPU on Mac

89 views
Skip to first unread message

Uli Kusterer

unread,
Jan 4, 2012, 1:18:22 PM1/4/12
to lib...@googlegroups.com
Hi,

I'm getting weird errors trying to build libcpu on Mac OS X 10.7. Does anyone have an idea what this could be caused by? My guess is the CMake file somewhere causes __STDC_FORMAT_MACROS to be defined wrongly ... ?

I googled for that constant, but my google-fu is weak, it seems. Lots of other-project-specific issues and fixes, but nothing what it really does. And the inttypes.h header doesn't mention what it's for either.

Thanks for any google search terms, hints and suggestions any of you would want to supply. Here's the log:

thestarsmydestination:libcpu uli$ make
[ 0%] [ 0%] Building CXX object arch/6502/CMakeFiles/6502.dir/6502_arch.cpp.o
Building CXX object arch/fapra/CMakeFiles/fapra.dir/fapra_disasm.cpp.o
<command-line>: error: "__STDC_FORMAT_MACROS" redefined
<command-line>: error: this is the location of the previous definition
<command-line>: error: "__STDC_FORMAT_MACROS" redefined
<command-line>: error: this is the location of the previous definition
make[3]: *** [arch/fapra/CMakeFiles/fapra.dir/fapra_disasm.cpp.o] Error 1
make[2]: *** [arch/fapra/CMakeFiles/fapra.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
make[3]: *** [arch/6502/CMakeFiles/6502.dir/6502_arch.cpp.o] Error 1
make[3]: *** Waiting for unfinished jobs....
[ 1%] Building CXX object arch/6502/CMakeFiles/6502.dir/6502_disasm.cpp.o
<command-line>: error: "__STDC_FORMAT_MACROS" redefined
<command-line>: error: this is the location of the previous definition
make[3]: *** [arch/6502/CMakeFiles/6502.dir/6502_disasm.cpp.o] Error 1
make[2]: *** [arch/6502/CMakeFiles/6502.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [all] Error 2

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."

Pekka Enberg

unread,
Jan 4, 2012, 1:38:36 PM1/4/12
to lib...@googlegroups.com, witness.of...@gmx.net

Dunno why we define it. Does something like this fix it for you?

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bc2353c..721cf2f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -72,7 +72,7 @@ ENDMACRO(TARGET_LINK_LLVM)
# Add extra warnings for gcc/g++.
#
IF(CMAKE_COMPILER_IS_GNUCXX)
- ADD_DEFINITIONS(-W -Wall -Wextra -Wno-unused -Werror
-D__STDC_FORMAT_MACROS=1)
+ ADD_DEFINITIONS(-W -Wall -Wextra -Wno-unused -Werror)
ENDIF()

FOREACH(ARCHITECTURE ${GUEST_ARCHITECTURES})

Uli Kusterer

unread,
Jan 4, 2012, 3:23:24 PM1/4/12
to lib...@googlegroups.com
On 04.01.2012, at 19:38, Pekka Enberg wrote:
> Dunno why we define it. Does something like this fix it for you?
>
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index bc2353c..721cf2f 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -72,7 +72,7 @@ ENDMACRO(TARGET_LINK_LLVM)
> # Add extra warnings for gcc/g++.
> #
> IF(CMAKE_COMPILER_IS_GNUCXX)
> - ADD_DEFINITIONS(-W -Wall -Wextra -Wno-unused -Werror
> -D__STDC_FORMAT_MACROS=1)
> + ADD_DEFINITIONS(-W -Wall -Wextra -Wno-unused -Werror)
> ENDIF()

It gets me back to an error where it's looking for the wrong LLVM version, but that may be something I did in earlier attempts.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."

http://groups.yahoo.com/group/mac-gui-dev/

Pekka Enberg

unread,
Jan 4, 2012, 3:56:29 PM1/4/12
to lib...@googlegroups.com, witness.of...@gmx.net, Gianluca Guida
On Wed, Jan 4, 2012 at 10:23 PM, Uli Kusterer
<witness.of...@gmx.net> wrote:
> On 04.01.2012, at 19:38, Pekka Enberg wrote:
>> Dunno why we define it. Does something like this fix it for you?
>>
>> diff --git a/CMakeLists.txt b/CMakeLists.txt
>> index bc2353c..721cf2f 100644
>> --- a/CMakeLists.txt
>> +++ b/CMakeLists.txt
>> @@ -72,7 +72,7 @@ ENDMACRO(TARGET_LINK_LLVM)
>> # Add extra warnings for gcc/g++.
>> #
>> IF(CMAKE_COMPILER_IS_GNUCXX)
>> -  ADD_DEFINITIONS(-W -Wall -Wextra -Wno-unused -Werror
>> -D__STDC_FORMAT_MACROS=1)
>> +  ADD_DEFINITIONS(-W -Wall -Wextra -Wno-unused -Werror)
>> ENDIF()
>
>  It gets me back to an error where it's looking for the wrong LLVM version, but that may be something I did in earlier attempts.

It turns out I added __STDC_FORMAT_MACROS:

https://github.com/libcpu/libcpu/commit/eb320a5a00f47377caf7771c4779529555b83819

which seems to be required to use <inttypes.h> in C++ code on Linux. I
verified that on Ubuntu just now. Does the attached patch help?

Pekka

0001-Fix-__STDC_FORMAT_MACROS-redefinition-errors-on-Mac-.patch

Pekka Enberg

unread,
Jan 4, 2012, 4:45:41 PM1/4/12
to lib...@googlegroups.com, witness.of...@gmx.net, Gianluca Guida
On Wed, Jan 4, 2012 at 10:56 PM, Pekka Enberg <pen...@kernel.org> wrote:
> It turns out I added __STDC_FORMAT_MACROS:
>
> https://github.com/libcpu/libcpu/commit/eb320a5a00f47377caf7771c4779529555b83819
>
> which seems to be required to use <inttypes.h> in C++ code on Linux. I
> verified that on Ubuntu just now. Does the attached patch help?

Oh well, my patch doesn't seem to work on Linux, so no point in trying it out.

What compiler are you using, btw? Is this Xcode 4.2 or later? If so,
you should probably see if adding these options help:

-std=c++0x -stdlib=libc++ -U__STRICT_ANSI__ -D__STDC_FORMAT_MACROS

As suggested in http://libcxx.llvm.org/

Pekka

Reply all
Reply to author
Forward
0 new messages