0

I have a feeling this must be a stupid simple problem however I just can't seem to figure out what I'm doing wrong.

I'm using Doom emacs and trying to use noweb with org mode source code blocks to begin more literate programming.

For some reason using C-c C-c on the following:

#+BEGIN_SRC C :noweb-ref give-five
static int giveMeFive(void) {
    return 5;
}
#+END_SRC

#+BEGIN_SRC C :tangle my_c.c :noweb yes
#include <stdio.h>
<<give-five>>

int main() {
    printf("%d \n", giveMeFive());
return 0;
}
#+END_SRC

Returns:

/tmp/babel-0w53dG/C-src-zO1Y13.c: In function ‘main’:
/tmp/babel-0w53dG/C-src-zO1Y13.c:12:21: warning: implicit declaration of function ‘giveMeFive’ [-Wimplicit-function-declaration]
   12 |     printf("%d \n", giveMeFive());
      |                     ^~~~~~~~~~
/usr/bin/ld: /tmp/cctC6beq.o: in function `main':
C-src-zO1Y13.c:(.text+0xa): undefined reference to `giveMeFive'
collect2: error: ld returned 1 exit status
zsh:1: no such file or directory: /tmp/babel-0w53dG/C-bin-RgZiYw

I've tried also using the #+NAME: give-five and that doesn't seem to work either. Note that when I try just expanding with C-c C-v C-v I get this:

#include <stdio.h>


int main() {
    printf("%d \n", giveMeFive());
return 0;
}

So it seems like it's not even seeing my noweb-ref.

3
  • Both C-c C-c and C-c C-v C-v work fine here, so all I can think of is a bug in your version of Org mode. What is your version? – NickD Oct 6 '20 at 18:58
  • Works here as well. Did you try with emacs -q? Just evaluate M-: > (org-babel-do-load-languages 'org-babel-load-languages '((C . t))) beforehand. You can also use M-x > org-export-as-org to see what the code block will look like when the reference is expanded (might also not work in your case). – Hubisan Oct 6 '20 at 19:14
  • For some reason as soon as I copied the code into a new org file the issue went away. I'm using gccemacs (version 28.0.50). The previous file did not have conflictingly named code blocks so I'm not sure what the issue was. – Reginald Marr Oct 6 '20 at 19:26

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.