Finding C header files on OS X
This is a very simple yet interesting problem. By the way; simple things are interesting a lot of times, because simple does not mean easy. The problem I had at hand was to determine the range of different data types on my ibook. Yes, that is right, on my ibook with PowerPC architecture.
I know that I should be able to find the answer in limits.h file. So my task was to find limits.h file. Hmmm.. sounds too easy right. You bet!
I started with searching for limits.h in spotlight. But alas, spotlight does not search in 'hidden' folders by default and I got pretty useless results. Then I used 'find' command on the terminal. But it gave me a scrolling screen of results and I realized that this approach was not going to work optimally. So I needed a different thought process. OK. Lets step back and think what I want. I want to find a header file that gcc would use. So I searched where all header files would be stored. This location will be /usr/include. Now this directory will have a bunch of folders such as gcc, ppc etc. This /usr/include folder will contain the header files required for C. If you go to gcc folder, you will be able to go to the folder for the C++ compiler on your machine e.g. /usr/include/gcc/darwin/4.0/c++ etc. You will notice that the C++ header files do not display the .h extension the way C header files do.
Well anyways, so I opened the limits.h file in /usr/include. But hey.. wait a minute. where are all the variables in this file i.e. where is, CHAR_BIT or CHAR_MAX? That means there must be another limits.h file. To find the correct file, you have to go to the folder /usr/include/ppc. There was another limits.h file. Now this file had all the variables that I needed.
Now it falls into place. The parent folder /usr/include is correct. But since my ibook has PowerPC architecture, the relevant header files would be stored in a separate folder which is ppc.
Although this exercise took some time out of my weekend , it was worth it. I always wanted to find where all these files are stored. The joy of finding something on your own is unique and now I am sure I will never forget it. And I should acknowledge help of web search in the process.
Labels: C header files, OS X
3 Comments:
"Although this exercise took some time out of my weekend , it was worth it. I always wanted to find where all these files are stored. The joy of finding something on your own is unique and now I am sure I will never forget it. And I should acknowledge help of Google search in the process. " These sentences were enough for inspiring the researcher in me too.Thanks , I have been able to find the location of all these files for my system too. Thanks to google too.
You can do this extremely simply using the 'open' command. The -h flag searches all header files.
open -a Textmate (or whatever app) -h yourheader.h
Or you could write simple program:
#include <vector>
using namespace std;
int main(){
vector<double> a;
int b = a.at(1,2,3);//Nonsense
return 0;
}
Compile this and g++ will say: that vector has no at(int, int, int) function but in
/path/to/headerfile/vector.h
there is at(size_t)
Post a Comment
<< Home