Find function definition in C++

TOP KEK

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?

xryl669

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Find function definition in C++

From Dev

Definition of a function in a C program

From Dev

C function definition/prototype

From Dev

Function definition in C struct?

From Dev

C function definition and declaration

From Dev

function definition in BNF C grammar

From Dev

c, function definition following struct

From Dev

Weird declaration and definition of a function in C

From Dev

Elegant function definition in C++

From Dev

function definition in BNF C grammar

From Dev

Elegant function definition in C++

From Dev

Visual Studio C++ & Boost Lib: cannot find function definition only when BOOST_FOREACH is present

From Dev

sublime plugin - Find and go to function definition

From Dev

Find function/variable definition for a reference in source code

From Dev

Find the source file containing R function definition

From Dev

Linker can't find function definition in a namespace

From Dev

Linker can't find function definition in a namespace

From Dev

C - Mismatched function prototype and definition for "static" function

From Dev

Is the 'main' function classified as a function definition in C?

From Dev

Clang does not find function instantiated after function definition in template context

From Dev

Clang does not find function instantiated after function definition in template context

From Dev

Mixing pointers and references in function definition in C++

From Dev

What encompasses a function definition in C++?

From Dev

Order of definition for function signatures in C++

From Dev

C using a forward declaration within a function definition

From Dev

Preprocessor macro overriding function definition in c++

From Dev

Are these two styles of C function pointer definition different?

From Dev

C++ in function definition of abstract classes

From Dev

Function declaration vs. definition C

Related Related

  1. 1

    Find function definition in C++

  2. 2

    Definition of a function in a C program

  3. 3

    C function definition/prototype

  4. 4

    Function definition in C struct?

  5. 5

    C function definition and declaration

  6. 6

    function definition in BNF C grammar

  7. 7

    c, function definition following struct

  8. 8

    Weird declaration and definition of a function in C

  9. 9

    Elegant function definition in C++

  10. 10

    function definition in BNF C grammar

  11. 11

    Elegant function definition in C++

  12. 12

    Visual Studio C++ & Boost Lib: cannot find function definition only when BOOST_FOREACH is present

  13. 13

    sublime plugin - Find and go to function definition

  14. 14

    Find function/variable definition for a reference in source code

  15. 15

    Find the source file containing R function definition

  16. 16

    Linker can't find function definition in a namespace

  17. 17

    Linker can't find function definition in a namespace

  18. 18

    C - Mismatched function prototype and definition for "static" function

  19. 19

    Is the 'main' function classified as a function definition in C?

  20. 20

    Clang does not find function instantiated after function definition in template context

  21. 21

    Clang does not find function instantiated after function definition in template context

  22. 22

    Mixing pointers and references in function definition in C++

  23. 23

    What encompasses a function definition in C++?

  24. 24

    Order of definition for function signatures in C++

  25. 25

    C using a forward declaration within a function definition

  26. 26

    Preprocessor macro overriding function definition in c++

  27. 27

    Are these two styles of C function pointer definition different?

  28. 28

    C++ in function definition of abstract classes

  29. 29

    Function declaration vs. definition C

HotTag

Archive