I have a C++ project on remote machine which compiles with makefile. No ide available, only vim and commandline. I found a function in the sourcecode and want to find its definition. How can I do that without manually looking all -I directories and source files? Is it possible to stop makefile after preprocessing phase and lookup in the resulting sourcefiles?
You can use ctag and cscop to browse the code on vi. If you are not comfortable with that then use a
grep -rn funtion_name ./
in the home dir of the source code, and manually look for the definition in the result set.
The easiest solution would be to use grep (with find to get results very fast) like this:
find srcDir -name "*.c" -o -name "*.cpp" -print0 | xargs -0 grep "functionName"
The Makefile based solution is to change the linking so you ask for a verbose location of a function definition like this (if you use GCC) (you can also do that on the command line with "make LDFLAGS=...seebelow...")
# In your makefile, locate this:
LDFLAGS:= ...
# Replace by this
LDFLAGS:= -Wl,--trace-symbol=functionName
This results in:
$ gcc -o test main.o -Wl,--trace-symbol=main
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o: reference to main
main.o: definition of main
This solution is useful if you have plenty of similar function name, and you actually want the one that's used in the final binary.
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