I’m trying to compile an application that utilizes cstdint. Since Apple deprecated the gcc, I wanted to try compiling it with clang, but i get the error:
fatal error: 'cstdint' file not found
I know that the gcc 4.6.2 version has the option for -std=c++0x, to include the library, but since the os x version is 4.2 that’s not much of an option here. Any suggestions on how I can move forward? I have tried to install 4.6.2, but ran into a variety of issues when compiling some of the needed libraries before building gcc.
Presumably, you have the source code to this application, so you can modify the headers to include the correct
cstdintheader, as Clang 3.0 (which Lion’s tools come with) does have the header.Quick Solution
The header is under the
tr1directory, so you will want to do either of these includes:Or
Longer, boring explanation
After doing some additional reading since I remember you can do this without the tr1 directory:
By default, you are going to be including C++ headers from
/usr/include/c++/4.2.1, which are the GNU GCC headers./usr/include/c++/4.2.1/tr1includes the TR1 header files, likecstdint.The alternative method is to compile using the Clang++ frontend and passing the
-stdlib=libc++flag, which will use the headers from/usr/include/c++/v1, which are Clang’s C++ header implementations. It hascstdint.Example:
Compile this with:
or
And it will do what you want.
If you don’t want to use the
tr1version (which is roughly the same, if not exactly):This is compiled like this:
Though if you use
-stdlib=libc++, it means you’re linking to Clang’s C++ librarylibc++, rather than GCC’slibstdc++.