1 line
2.7 KiB
Plaintext
1 line
2.7 KiB
Plaintext
<!-- SC_OFF --><div class="md"><p>Hey, I'm experimenting with literate coding. In the process I couldn't properly evaluate a block. I wanted to use both<code>:results output</code> and <code>:export both</code>, and I'm getting troubles to make those work with <code>:defines</code>. This is the code I have: </p> <pre><code>#+property: header-args :includes <stdio.h> #+property: header-args :defines cool_macro(x) x #+property: header-args :exports both #+property: header-args :results output #+begin_src C printf("cool_macro(7): %u\n", cool_macro(7)); printf("cool_macro(7): %u\n", cool_macro(7)); #+end_src </code></pre> <p>As it is, both <code>:exports</code> and <code>:results</code> have no effect. I figured that if I place them above the <code>:includes</code> then they'll have effect, but I get a compilation error because it cannot find the macro, as if now both <code>:includes</code> and <code>:defines</code> doesn't have effect.</p> <p>If I place those 2 after the <code>#+begin_src C</code> then everything works as expected, but it's inconvenient since I want those to affect the whole buffer..</p> <pre><code>#+property: header-args :includes <stdio.h> #+property: header-args :defines cool_macro(x) x #+begin_src C :results output :exports both printf("cool_macro(7): %u\n", cool_macro(7)); printf("cool_macro(7): %u\n", cool_macro(7)); #+end_src </code></pre> <p>Am I doing something really wrong or what?</p> <p>Thanks.</p> <p>Edit: Solution.</p> <p>Ok, of course the solution was in the docs: <a href="https://org-babel.readthedocs.io/en/latest/header-args/#buffer-or-file-level-header-arguments">https://org-babel.readthedocs.io/en/latest/header-args/#buffer-or-file-level-header-arguments</a> .The problem was that I was rewriting the headers, doing it multiline. The proper way to do it is in oneline or specifying that it should be appended to the existent headers with a <code>+</code>. This is how it looks when it works properly:</p> <pre><code>#+property: header-args :results output :exports both #+property: header-args+ :includes <stdio.h> #+property: header-args+ :defines cool_macro(x) x #+begin_src C printf("cool_macro(7): %u\n", cool_macro(7)); printf("cool_macro(7): %u\n", cool_macro(7)); #+end_src #+RESULTS: : cool_macro(7): 7 : cool_macro(7): 7 </code></pre> <p>Thanks for the help!</p> </div><!-- SC_ON -->   submitted by   <a href="https://www.reddit.com/user/mefff_"> /u/mefff_ </a> <br/> <span><a href="https://www.reddit.com/r/orgmode/comments/qwbk6b/orgbabel_c_and_cmacros/">[link]</a></span>   <span><a href="https://www.reddit.com/r/orgmode/comments/qwbk6b/orgbabel_c_and_cmacros/">[comments]</a></span> |