unofficial mirror of emacs-orgmode@gnu.org
 help / color / 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

* Re: Not working ob-C sample code
  2020-06-23  0:54 Not working ob-C sample code Naoya Yamashita
@ 2020-06-23  2:11 ` ian martins
  0 siblings, 0 replies; 2+ messages in thread
From: ian martins @ 2020-06-23  2:11 UTC (permalink / raw)
  To: Naoya Yamashita; +Cc: emacs-orgmode

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

Maybe you could use the C compiler instead of C++, or you could include the
c libraries you need. try these options:
----
#+begin_src C :var somedata=somedata
----
#+begin_src C++ :var somedata=somedata :includes '(<cstring> <stdlib.h>
<cstdio>)

On Mon, Jun 22, 2020 at 8:56 PM Naoya Yamashita <conao3@gmail.com> wrote:

> 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: 3799 bytes --]

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

end of thread, back to index

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

unofficial mirror of emacs-orgmode@gnu.org

Archives are clonable:
	git clone --mirror https://yhetil.org/orgmode/0 orgmode/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 orgmode orgmode/ https://yhetil.org/orgmode \
		emacs-orgmode@gnu.org
	public-inbox-index orgmode

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git