|
From: | address@hidden |
Subject: | Re: [O] ob-C doesn't support load libraries |
Date: | Mon, 13 Jun 2016 08:23:29 +0800 |
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.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 statuszsh: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/
[Prev in Thread] | Current Thread | [Next in Thread] |