emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* ob-C doesn't support load libraries
@ 2016-06-10 12:01 numbchild
  2016-06-10 16:44 ` Thierry Banel
  0 siblings, 1 reply; 3+ messages in thread
From: numbchild @ 2016-06-10 12:01 UTC (permalink / raw)
  To: Org-mode

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

I have a code example like this:

#+BEGIN_SRC C
#include <stdio.h>
#include <math.h>

/* define complex struct */
struct complex_struct {
  double x, y;
};

/* some helper functions on complex struct */
double real_part(struct complex_struct z) {
  return z.x;
}
double img_part(struct complex_struct z) {
  return z.y;
}
double magnitude(struct complex_struct z) {
  return sqrt(z.x * z.x + z.y * z.y);
}
double angle(struct complex_struct z) {
  return atan2(z.y, z.x);
}

/* helper functions to construct complex variable */
struct complex_struct make_from_real_img(double x, double y) {
  struct complex_struct z;
  z.x = x;
  z.y = y;
  return z;
}

struct complex_struct make_from_mag_ang(double r, double A) {
  struct complex_struct z;
  z.x = r * cos(A);
  z.y = r * sin(A);
  return z;
}

/* implement complex arithemtic */
struct complex_struct add_complex(struct complex_struct z1, struct
complex_struct z2) {
  return make_from_real_img(real_part(z1) + real_part(z2), img_part(z1) +
img_part(z2));
}

int main(int argc, char *argv[]) {
  struct complex_struct z1, z2 = {1.1, 2.4};

  struct complex_struct z;
  z = add_complex(z1, z2);

  printf("%f", z);
  return 0;
}
#+END_SRC

But evaluate it got error:

```
/tmp/cckFlXlJ.o: In function `magnitude':
C-src-18467gDZ.c:(.text+0xa8): undefined reference to `sqrt'
/tmp/cckFlXlJ.o: In function `angle':
C-src-18467gDZ.c:(.text+0xfe): undefined reference to `atan2'
/tmp/cckFlXlJ.o: In function `make_from_mag_ang':
C-src-18467gDZ.c:(.text+0x174): undefined reference to `cos'
C-src-18467gDZ.c:(.text+0x190): undefined reference to `sin'
collect2: error: ld returned 1 exit status
zsh:1: no such file or directory: /tmp/babel-18467-Yn/C-bin-18467tNf
```

So I think `ob-C.el` doesn't support to load included header files.

[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

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

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

* Re: ob-C doesn't support load libraries
  2016-06-10 12:01 ob-C doesn't support load libraries numbchild
@ 2016-06-10 16:44 ` Thierry Banel
  2016-06-13  0:23   ` numbchild
  0 siblings, 1 reply; 3+ messages in thread
From: Thierry Banel @ 2016-06-10 16:44 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/html, Size: 10370 bytes --]

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

* Re: ob-C doesn't support load libraries
  2016-06-10 16:44 ` Thierry Banel
@ 2016-06-13  0:23   ` numbchild
  0 siblings, 0 replies; 3+ messages in thread
From: numbchild @ 2016-06-13  0:23 UTC (permalink / raw)
  To: Thierry Banel; +Cc: Org-mode

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

Thanks.

[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

On Sat, Jun 11, 2016 at 12:44 AM, Thierry Banel <tbanelwebmin@free.fr>
wrote:

> Change the first line to
>
>   #+BEGIN_SRC C *:libs -lm*
>
> This instructs the C++ compiler to link with the "m" library (mathematical
> functions).
>
> You need a pretty new version of ob-C.el, as the :libs parameter was
> introduced recently.
>
>
>
> Le 10/06/2016 14:01, numbchild@gmail.com a écrit :
>
> I have a code example like this:
>
> #+BEGIN_SRC C
> #include <stdio.h>
> #include <math.h>
>
> /* define complex struct */
> struct complex_struct {
>   double x, y;
> };
>
> /* some helper functions on complex struct */
> double real_part(struct complex_struct z) {
>   return z.x;
> }
> double img_part(struct complex_struct z) {
>   return z.y;
> }
> double magnitude(struct complex_struct z) {
>   return sqrt(z.x * z.x + z.y * z.y);
> }
> double angle(struct complex_struct z) {
>   return atan2(z.y, z.x);
> }
>
> /* helper functions to construct complex variable */
> struct complex_struct make_from_real_img(double x, double y) {
>   struct complex_struct z;
>   z.x = x;
>   z.y = y;
>   return z;
> }
>
> struct complex_struct make_from_mag_ang(double r, double A) {
>   struct complex_struct z;
>   z.x = r * cos(A);
>   z.y = r * sin(A);
>   return z;
> }
>
> /* implement complex arithemtic */
> struct complex_struct add_complex(struct complex_struct z1, struct
> complex_struct z2) {
>   return make_from_real_img(real_part(z1) + real_part(z2), img_part(z1) +
> img_part(z2));
> }
>
> int main(int argc, char *argv[]) {
>   struct complex_struct z1, z2 = {1.1, 2.4};
>
>   struct complex_struct z;
>   z = add_complex(z1, z2);
>
>   printf("%f", z);
>   return 0;
> }
> #+END_SRC
>
> But evaluate it got error:
>
> ```
> /tmp/cckFlXlJ.o: In function `magnitude':
> C-src-18467gDZ.c:(.text+0xa8): undefined reference to `sqrt'
> /tmp/cckFlXlJ.o: In function `angle':
> C-src-18467gDZ.c:(.text+0xfe): undefined reference to `atan2'
> /tmp/cckFlXlJ.o: In function `make_from_mag_ang':
> C-src-18467gDZ.c:(.text+0x174): undefined reference to `cos'
> C-src-18467gDZ.c:(.text+0x190): undefined reference to `sin'
> collect2: error: ld returned 1 exit status
> zsh:1: no such file or directory: /tmp/babel-18467-Yn/C-bin-18467tNf
> ```
>
> So I think `ob-C.el` doesn't support to load included header files.
>
> [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
> IRC(freeenode): stardiviner                     Twitter:  @numbchild
> Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
> Blog: http://stardiviner.github.io/
>
>
>

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

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

end of thread, other threads:[~2016-06-13  0:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-10 12:01 ob-C doesn't support load libraries numbchild
2016-06-10 16:44 ` Thierry Banel
2016-06-13  0:23   ` numbchild

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).