Attached is Oz's patch adding optional :libs support to Babel C++
Thanks Oz.
Thierry


Le 11/03/2016 20:14, Oz Ben-Ami a écrit :
> Thanks for the response.
>
> On my machine, I get the undefined references even with GCC 5 (gcc
> version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2)), if I put -lm before
> the source file name.
>
> As far as a patch, I can try but this would be my first time really
> playing with org-mode code. As far as I can see, I would need to add
> the following lines in ob-C.el:
> L133: (libs (cdr (assoc :libs params)))
>          (libs (mapconcat 'identity
>                (if (listp libs) libs (list libs)) " "))
> L142: (format "%s -o %s %s %s %s" ;; (added %s)
> L147: libs
>
> Am I missing anything?
>
> Oz
>

>From 69661d4406c51f678dad6f14aaa8f3447c398825 Mon Sep 17 00:00:00 2001
From: Thierry Banel <tbanelweb...@free.fr>
Date: Sun, 20 Mar 2016 14:50:17 +0100
Subject: [PATCH] Add :libs to babel C++

* lisp/ob-C.el (org-babel-C-execute): add support for :libs header
  parameter to specify libraries to link with.
---
 lisp/ob-C.el | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index dd34b0b..d5855ab 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -130,6 +130,12 @@ or `org-babel-execute:C++' or `org-babel-execute:D'."
 	 (flags (cdr (assoc :flags params)))
 	 (flags (mapconcat 'identity
 			   (if (listp flags) flags (list flags)) " "))
+	 (libs (org-babel-read
+		(or (cdr (assoc :libs params))
+		    (org-entry-get nil "libs" t))
+		nil))
+	 (libs (mapconcat 'identity
+			   (if (listp libs) libs (list libs)) " "))
 	 (full-body
 	  (case org-babel-c-variant
 	    (c   (org-babel-C-expand-C   body params))
@@ -139,13 +145,15 @@ or `org-babel-execute:C++' or `org-babel-execute:D'."
     (case org-babel-c-variant
       ((c cpp)
        (org-babel-eval
-	(format "%s -o %s %s %s"
+	(format "%s -o %s %s %s %s"
 		(case org-babel-c-variant
 		 (c   org-babel-C-compiler)
 		 (cpp org-babel-C++-compiler))
 		(org-babel-process-file-name tmp-bin-file)
 		flags
-		(org-babel-process-file-name tmp-src-file)) ""))
+		(org-babel-process-file-name tmp-src-file)
+		libs)
+	""))
       (d nil)) ;; no separate compilation for D
     (let ((results
 	   (org-babel-eval
-- 
2.1.4

Reply via email to