Daniel Paczuski Bak
Daniel Paczuski Bak

Reputation: 4080

Finding file in which global variable is declared

I am trying to learn a fairly large open source codebase. In this file, a variable m is referenced many times without ever being declared (see line 819). So I figure it has to be a global variable.

However, this file includes roughly two dozen .h files. From what I understand, m could have been declared in any of these files. Is there any way I can determine which file declared it, or do I need to search through each .h file?

Is this the kind of thing you need a tool for? Does Eclipse have such a function?

Upvotes: 0

Views: 192

Answers (2)

Jack Deeth
Jack Deeth

Reputation: 3357

I'd download the source code and make a project from it in my IDE. I can then find the declaration via a context menu.

If there's a more elegant way I'd like to hear it!

Upvotes: 1

Peter
Peter

Reputation: 328

If you have the codebase downloaded locally, you could use grep: https://www.gnu.org/software/grep/manual/grep.html

Note that grep is a Unix based command, so depending on your shell it may not be available. If you're on Windows, FINDSTR (https://technet.microsoft.com/en-us/library/bb490907.aspx) does something similar but isn't as flexible.

A quick example using grep would be something like this:

grep -l -R "some_string" /usr/local/SomeDirectory

Upvotes: 1

Related Questions