emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Not working ob-C sample code
@ 2020-06-23  0:54 Naoya Yamashita
  2020-06-23  2:11 ` ian martins
  0 siblings, 1 reply; 2+ messages in thread
From: Naoya Yamashita @ 2020-06-23  0:54 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2445 bytes --]

Hi! I'm Naoya. This is the first mail to this ML.

First, thank you for developing such awesome packages!

I found ob-C sample[1] is not working for me, I report that to this ML.

[1]: https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-C.org.html

## Repro step
1. Require org and ob-C.
2. Write below in some org buffer.
```org
#+tblname: somedata
| nb    | sqr | noise |
|-------+-----+-------|
| zero  |   0 |  0.23 |
| one   |   1 |  1.31 |
| two   |   4 |  4.61 |
| three |   9 |  9.05 |
| four  |  16 | 16.55 |

#+name: c-table
#+header: :exports results
#+begin_src C++ :var somedata=somedata
  int main()
  {
    for (int i=0; i<somedata_rows; i++) {
      printf ("%2d %7s ", i, somedata_h(i,"nb"));
      for (int j=1; j<somedata_cols; j++) {
        const char* cell = somedata[i][j];
        printf ("%5s %5g ", cell, 1000*atof(cell));
      }
      printf("\n");
    }
    return 0;
  }
#+end_src
```
3. Babel src block via C-c C-c.
4. Error occurred.  I get below error output
```
/tmp/babel-kMPbac/C-src-KDQDdx.cpp: In function ‘int get_column_num(int,
const char**, const char*)’:
/tmp/babel-kMPbac/C-src-KDQDdx.cpp:17:9: error: ‘strcmp’ was not declared
in this scope
   17 |     if (strcmp(header[c],column)==0)
      |         ^~~~~~
/tmp/babel-kMPbac/C-src-KDQDdx.cpp:1:1: note: ‘strcmp’ is defined in header
‘<cstring>’; did you forget to ‘#include <cstring>’?
  +++ |+#include <cstring>
    1 |
/tmp/babel-kMPbac/C-src-KDQDdx.cpp: In function ‘int main()’:
/tmp/babel-kMPbac/C-src-KDQDdx.cpp:27:5: error: ‘printf’ was not declared
in this scope
   27 |     printf ("%2d %7s ", i, somedata_h(i,"nb"));
      |     ^~~~~~
/tmp/babel-kMPbac/C-src-KDQDdx.cpp:1:1: note: ‘printf’ is defined in header
‘<cstdio>’; did you forget to ‘#include <cstdio>’?
  +++ |+#include <cstdio>
    1 |
/tmp/babel-kMPbac/C-src-KDQDdx.cpp:30:38: error: ‘atof’ was not declared in
this scope
   30 |       printf ("%5s %5g ", cell, 1000*atof(cell));
      |                                      ^~~~
zsh:1: permission denied: /tmp/babel-kMPbac/C-bin-EfCzWt
```

## Some note
- These errors caused because a lack to include some library.
  - Add some include statement generate and insert it in
`org-babel-C-utility-header-to-C`?
  - Add new option for a user preamble and insert it in
`org-babel-C-expand-C`?

Regards,

[-- Attachment #2: Type: text/html, Size: 3104 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-23  2:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23  0:54 Not working ob-C sample code Naoya Yamashita
2020-06-23  2:11 ` ian martins

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).