I received a large code file, that I didn't write. There's a function being used in that code that I want to use myself in a separate code file. Is there a quick and simple way to find which of the (many) includes in the original code file makes this function available?
The fastest way is usually to grep for the function name (pro tip: use grep -rw to search recursively and for whole-word matches only). That assumes you have some idea which directories the header file may be in.
If that won't work, you can preprocess the file. With GCC that's the -E option instead of -c. This will output what the actual compiler sees, after #includes are resolved. Then you can easily search in the preprocessed file for the function declaration and look above that for which file it came from.
This completely depends on your developmnet environment. I often use ack tool (consider it as "better grep" for programmers) for that purpose, beside that I know that some IDEs have "go to definition" or "go to declaration" feature, so you can directly look for function's definition or its prototype.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With