1

I'm trying to use emacs for C development. From here, I understand that in order to see the definitions of functions, I need to use something called etags. My code is:

#include <stdlib.h>
#include <stdio.h>

int main()
{

  int i = 0;
  printf("i = ", i);

  return 0;
};

When I try to M-. the definition of printf, I see:

No definitions found for: printf

So, I try making an ETAGS file, with:

M-! RET etags main.c RET

And I see I now have a file in the directory called TAGS. However, this didn't change anything. When I M-. the function, I still see no definitions for it.

I can confirm that it works internally. That is, if I change my file to:

#include <stdlib.h>
#include <stdio.h>

int zero() {
  return 0;
};

int main()
{

  int i = 0;
  printf("i = ", i);

  i = zero();


  return 0;
};

And place my cursor on the line that calls zero(), and then M-. it takes me to the internal definition of zero().

My question is:

What do I need to do to see the definitions of dependencies?

2
  • What do you expect to see? The printf function is in a library that contains a bunch of compiled binaries. There is generally no source code available on a system. You can install the source code (at least on a Linux system) and then produce an etags file that contains those definitions, but the onus is on you: you'll have to find what library the function is part of, find where the source code for that library is, download it, keep it updated when new versions come out etc. – NickD May 14 '20 at 1:50
  • 2
    To see the definitions of dependencies, you need to run etags on the dependencies themselves: run etags in /usr/include. You can either combine those tags into the same file as your own code, or Emacs can load multiple tags files. The latter is what I do; set tags-table-list to the list of generated tags. I also recommend ctags – InHarmsWay May 14 '20 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.