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?
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.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments