emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "numbchild@gmail.com" <numbchild@gmail.com>
To: Org-mode <emacs-orgmode@gnu.org>
Subject: ob-C doesn't support load libraries
Date: Fri, 10 Jun 2016 20:01:03 +0800	[thread overview]
Message-ID: <CAL1eYuJ14Ghk6obucrx01Jn2UzOjQsTGe7dze2N=QbT58axMQg@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2016-06-10 12:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-10 12:01 numbchild [this message]
2016-06-10 16:44 ` ob-C doesn't support load libraries Thierry Banel
2016-06-13  0:23   ` numbchild

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAL1eYuJ14Ghk6obucrx01Jn2UzOjQsTGe7dze2N=QbT58axMQg@mail.gmail.com' \
    --to=numbchild@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).