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
.
C-c C-c
andC-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:58emacs -q
? Just evaluateM-:
>(org-babel-do-load-languages 'org-babel-load-languages '((C . t)))
beforehand. You can also useM-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