emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Org Babel C/C++
@ 2012-03-23 18:12 Daimrod
  2012-03-26 11:39 ` Eric Schulte
  0 siblings, 1 reply; 6+ messages in thread
From: Daimrod @ 2012-03-23 18:12 UTC (permalink / raw)
  To: emacs-orgmode

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


Hi,

I've made a small patch to ob-C.el so it now includes the current
directory to the list of directories to be searched for header files.
Without this, I cannot include a local header file because the
compilation happens in /tmp and thus gcc or g++ doesn't search for
header files in the directory I currently work.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ob-C-include.patch --]
[-- Type: text/x-patch, Size: 899 bytes --]

diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index f1525aa..4f33fc4 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -96,15 +96,14 @@ or `org-babel-execute:C++'."
 	  (progn
 	    (with-temp-file tmp-src-file (insert full-body))
 	    (org-babel-eval
-	     (format "%s -o %s %s %s -I \"%s\""
+	     (format "%s -o %s %s %s"
 		     (cond
 		      ((equal org-babel-c-variant 'c) org-babel-C-compiler)
 		      ((equal org-babel-c-variant 'cpp) org-babel-C++-compiler))
 		     (org-babel-process-file-name tmp-bin-file)
 		     (mapconcat 'identity
 				(if (listp flags) flags (list flags)) " ")
-		     (org-babel-process-file-name tmp-src-file)
-		     (file-name-directory (expand-file-name (buffer-file-name)))) ""))))
+		     (org-babel-process-file-name tmp-src-file)) ""))))
     ((lambda (results)
        (org-babel-reassemble-table
 	(if (member "vector" (cdr (assoc :result-params params)))

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

* Re: Org Babel C/C++
  2012-03-23 18:12 Org Babel C/C++ Daimrod
@ 2012-03-26 11:39 ` Eric Schulte
  2012-03-28 23:01   ` Daimrod
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Schulte @ 2012-03-26 11:39 UTC (permalink / raw)
  To: Daimrod; +Cc: emacs-orgmode

Applied, Thanks!

Daimrod <daimrod@gmail.com> writes:

> Hi,
>
> I've made a small patch to ob-C.el so it now includes the current
> directory to the list of directories to be searched for header files.
> Without this, I cannot include a local header file because the
> compilation happens in /tmp and thus gcc or g++ doesn't search for
> header files in the directory I currently work.
>
> diff --git a/lisp/ob-C.el b/lisp/ob-C.el
> index f1525aa..4f33fc4 100644
> --- a/lisp/ob-C.el
> +++ b/lisp/ob-C.el
> @@ -96,15 +96,14 @@ or `org-babel-execute:C++'."
>  	  (progn
>  	    (with-temp-file tmp-src-file (insert full-body))
>  	    (org-babel-eval
> -	     (format "%s -o %s %s %s -I \"%s\""
> +	     (format "%s -o %s %s %s"
>  		     (cond
>  		      ((equal org-babel-c-variant 'c) org-babel-C-compiler)
>  		      ((equal org-babel-c-variant 'cpp) org-babel-C++-compiler))
>  		     (org-babel-process-file-name tmp-bin-file)
>  		     (mapconcat 'identity
>  				(if (listp flags) flags (list flags)) " ")
> -		     (org-babel-process-file-name tmp-src-file)
> -		     (file-name-directory (expand-file-name (buffer-file-name)))) ""))))
> +		     (org-babel-process-file-name tmp-src-file)) ""))))
>      ((lambda (results)
>         (org-babel-reassemble-table
>  	(if (member "vector" (cdr (assoc :result-params params)))

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

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

* Re: Org Babel C/C++
  2012-03-26 11:39 ` Eric Schulte
@ 2012-03-28 23:01   ` Daimrod
  2012-03-29  1:34     ` Michael Hannon
  2012-03-31 15:47     ` URGENT " Eric Schulte
  0 siblings, 2 replies; 6+ messages in thread
From: Daimrod @ 2012-03-28 23:01 UTC (permalink / raw)
  To: emacs-orgmode

Eric Schulte <eric.schulte@gmx.com> writes:

> Applied, Thanks!
>
> Daimrod <daimrod@gmail.com> writes:
>
>> Hi,
>>
>> I've made a small patch to ob-C.el so it now includes the current
>> directory to the list of directories to be searched for header files.
>> Without this, I cannot include a local header file because the
>> compilation happens in /tmp and thus gcc or g++ doesn't search for
>> header files in the directory I currently work.
>>
>> diff --git a/lisp/ob-C.el b/lisp/ob-C.el
>> index f1525aa..4f33fc4 100644
>> --- a/lisp/ob-C.el
>> +++ b/lisp/ob-C.el
>> @@ -96,15 +96,14 @@ or `org-babel-execute:C++'."
>>  	  (progn
>>  	    (with-temp-file tmp-src-file (insert full-body))
>>  	    (org-babel-eval
>> -	     (format "%s -o %s %s %s -I \"%s\""
>> +	     (format "%s -o %s %s %s"
>>  		     (cond
>>  		      ((equal org-babel-c-variant 'c) org-babel-C-compiler)
>>  		      ((equal org-babel-c-variant 'cpp) org-babel-C++-compiler))
>>  		     (org-babel-process-file-name tmp-bin-file)
>>  		     (mapconcat 'identity
>>  				(if (listp flags) flags (list flags)) " ")
>> -		     (org-babel-process-file-name tmp-src-file)
>> -		     (file-name-directory (expand-file-name (buffer-file-name)))) ""))))
>> +		     (org-babel-process-file-name tmp-src-file)) ""))))
>>      ((lambda (results)
>>         (org-babel-reassemble-table
>>  	(if (member "vector" (cdr (assoc :result-params params)))

Hum, I'm quite embarrassed, this doesn't work when the block is executed
during an export. I didn't track it down yet, but (buffer-file-name)
returns nil during the export probably because the buffer changes.

A workaround would be to use the :flags header argument though it's a
bit tedious because it doesn't seem possible to eval elisp during the
export.

i.e.

#+BEGIN_SRC cpp :flags -I (file-name-directory (buffer-file-name))
...
#+END_SRC

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

* Re: Org Babel C/C++
  2012-03-28 23:01   ` Daimrod
@ 2012-03-29  1:34     ` Michael Hannon
  2012-03-30 11:17       ` Daimrod
  2012-03-31 15:47     ` URGENT " Eric Schulte
  1 sibling, 1 reply; 6+ messages in thread
From: Michael Hannon @ 2012-03-29  1:34 UTC (permalink / raw)
  To: Daimrod, emacs-orgmode@gnu.org

On Wednesday, March 28, 2012 at 4:01 PM Daimrod wrote:

> Eric Schulte <eric.schulte@gmx.com> writes:
>
>> Applied, Thanks!
>>
>> Daimrod <daimrod@gmail.com> writes:
>>
>>> Hi,
>>>
>>> I've made a small patch to ob-C.el so it now includes the current
>>> directory to the list of directories to be searched for header files.
>>> Without this, I cannot include a local header file because the
>>> compilation happens in /tmp and thus gcc or g++ doesn't search for
>>> header files in the directory I currently work.
>>>
>>> diff --git a/lisp/ob-C.el b/lisp/ob-C.el
>>> index f1525aa..4f33fc4 100644
>>> --- a/lisp/ob-C.el
>>> +++ b/lisp/ob-C.el
>>> @@ -96,15 +96,14 @@ or `org-babel-execute:C++'."
>>>         (progn
>>>           (with-temp-file tmp-src-file (insert full-body))
>>>           (org-babel-eval
>>> -        (format "%s -o %s %s %s -I
> \"%s\""
>>> +        (format "%s -o %s %s %s"
>>>               (cond
>>>                 ((equal org-babel-c-variant 'c)
> org-babel-C-compiler)
>>>                 ((equal org-babel-c-variant 'cpp)
> org-babel-C++-compiler))
>>>               (org-babel-process-file-name tmp-bin-file)
>>>               (mapconcat 'identity
>>>                   (if (listp flags) flags (list flags)) " ")
>>> -            (org-babel-process-file-name tmp-src-file)
>>> -            (file-name-directory (expand-file-name
> (buffer-file-name)))) ""))))
>>> +            (org-babel-process-file-name tmp-src-file))
> ""))))
>>>       ((lambda (results)
>>>         (org-babel-reassemble-table
>>>       (if (member "vector" (cdr (assoc :result-params
> params)))
>
> Hum, I'm quite embarrassed, this doesn't work when the block is executed
> during an export. I didn't track it down yet, but (buffer-file-name)
> returns nil during the export probably because the buffer changes.
>
> A workaround would be to use the :flags header argument though it's a
> bit tedious because it doesn't seem possible to eval elisp during the
> export.
>
> i.e.
>
> #+BEGIN_SRC cpp :flags -I (file-name-directory (buffer-file-name))
> ...
> #+END_SRC
>

I ran into this problem a few months ago.  I don't have the elisp skills to
patch Org mode, but I found something that worked for me:

    http://article.gmane.org/gmane.emacs.orgmode/49356/

-- Mike

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

* Re: Org Babel C/C++
  2012-03-29  1:34     ` Michael Hannon
@ 2012-03-30 11:17       ` Daimrod
  0 siblings, 0 replies; 6+ messages in thread
From: Daimrod @ 2012-03-30 11:17 UTC (permalink / raw)
  To: emacs-orgmode

Michael Hannon <jm_hannon@yahoo.com> writes:

> On Wednesday, March 28, 2012 at 4:01 PM Daimrod wrote:
>
>> Eric Schulte <eric.schulte@gmx.com> writes:
>>
>>> Applied, Thanks!
>>>
>>> Daimrod <daimrod@gmail.com> writes:
>>>
>>>> Hi,
>>>>
>>>> I've made a small patch to ob-C.el so it now includes the current
>>>> directory to the list of directories to be searched for header files.
>>>> Without this, I cannot include a local header file because the
>>>> compilation happens in /tmp and thus gcc or g++ doesn't search for
>>>> header files in the directory I currently work.
>>>>
>>>> diff --git a/lisp/ob-C.el b/lisp/ob-C.el
>>>> index f1525aa..4f33fc4 100644
>>>> --- a/lisp/ob-C.el
>>>> +++ b/lisp/ob-C.el
>>>> @@ -96,15 +96,14 @@ or `org-babel-execute:C++'."
>>>>         (progn
>>>>           (with-temp-file tmp-src-file (insert full-body))
>>>>           (org-babel-eval
>>>> -        (format "%s -o %s %s %s -I
>> \"%s\""
>>>> +        (format "%s -o %s %s %s"
>>>>               (cond
>>>>                 ((equal org-babel-c-variant 'c)
>> org-babel-C-compiler)
>>>>                 ((equal org-babel-c-variant 'cpp)
>> org-babel-C++-compiler))
>>>>               (org-babel-process-file-name tmp-bin-file)
>>>>               (mapconcat 'identity
>>>>                   (if (listp flags) flags (list flags)) " ")
>>>> -            (org-babel-process-file-name tmp-src-file)
>>>> -            (file-name-directory (expand-file-name
>> (buffer-file-name)))) ""))))
>>>> +            (org-babel-process-file-name tmp-src-file))
>> ""))))
>>>>       ((lambda (results)
>>>>         (org-babel-reassemble-table
>>>>       (if (member "vector" (cdr (assoc :result-params
>> params)))
>>
>> Hum, I'm quite embarrassed, this doesn't work when the block is executed
>> during an export. I didn't track it down yet, but (buffer-file-name)
>> returns nil during the export probably because the buffer changes.
>>
>> A workaround would be to use the :flags header argument though it's a
>> bit tedious because it doesn't seem possible to eval elisp during the
>> export.
>>
>> i.e.
>>
>> #+BEGIN_SRC cpp :flags -I (file-name-directory (buffer-file-name))
>> ...
>> #+END_SRC
>>
>
> I ran into this problem a few months ago.  I don't have the elisp skills to
> patch Org mode, but I found something that worked for me:
>
>     http://article.gmane.org/gmane.emacs.orgmode/49356/
>
> -- Mike

This won't work if you use different directories, you'll have to set the
variable org-babel-C++-compiler every time.

IMHO a good solution would be to be able to specify the directory used
to compile, or maybe I should just use a Makefile.

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

* Re: URGENT Org Babel C/C++
  2012-03-28 23:01   ` Daimrod
  2012-03-29  1:34     ` Michael Hannon
@ 2012-03-31 15:47     ` Eric Schulte
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Schulte @ 2012-03-31 15:47 UTC (permalink / raw)
  To: Daimrod; +Cc: emacs-orgmode

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

Daimrod <daimrod@gmail.com> writes:

> Eric Schulte <eric.schulte@gmx.com> writes:
>
>> Applied, Thanks!
>>
>> Daimrod <daimrod@gmail.com> writes:
>>
>>> Hi,
>>>
>>> I've made a small patch to ob-C.el so it now includes the current
>>> directory to the list of directories to be searched for header files.
>>> Without this, I cannot include a local header file because the
>>> compilation happens in /tmp and thus gcc or g++ doesn't search for
>>> header files in the directory I currently work.
>>>
>>> diff --git a/lisp/ob-C.el b/lisp/ob-C.el
>>> index f1525aa..4f33fc4 100644
>>> --- a/lisp/ob-C.el
>>> +++ b/lisp/ob-C.el
>>> @@ -96,15 +96,14 @@ or `org-babel-execute:C++'."
>>>  	  (progn
>>>  	    (with-temp-file tmp-src-file (insert full-body))
>>>  	    (org-babel-eval
>>> -	     (format "%s -o %s %s %s -I \"%s\""
>>> +	     (format "%s -o %s %s %s"
>>>  		     (cond
>>>  		      ((equal org-babel-c-variant 'c) org-babel-C-compiler)
>>>  		      ((equal org-babel-c-variant 'cpp) org-babel-C++-compiler))
>>>  		     (org-babel-process-file-name tmp-bin-file)
>>>  		     (mapconcat 'identity
>>>  				(if (listp flags) flags (list flags)) " ")
>>> -		     (org-babel-process-file-name tmp-src-file)
>>> -		     (file-name-directory (expand-file-name (buffer-file-name)))) ""))))
>>> +		     (org-babel-process-file-name tmp-src-file)) ""))))
>>>      ((lambda (results)
>>>         (org-babel-reassemble-table
>>>  	(if (member "vector" (cdr (assoc :result-params params)))
>
> Hum, I'm quite embarrassed, this doesn't work when the block is executed
> during an export. I didn't track it down yet, but (buffer-file-name)
> returns nil during the export probably because the buffer changes.
>

I've reverted this commit, I should have been more cautious in its
application.  I've reverted this commit in both the hotfix-7.8.06 branch
and the master branch.

>
> A workaround would be to use the :flags header argument though it's a
> bit tedious because it doesn't seem possible to eval elisp during the
> export.
>
> i.e.
>
> #+BEGIN_SRC cpp :flags -I (file-name-directory (buffer-file-name))
> ...
> #+END_SRC

I don't believe the above statement is true, for example the following
code block evaluates its header argument on export.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: example.org --]
[-- Type: text/x-org, Size: 156 bytes --]

Example of code eval during export.

#+headers: :exports results
#+begin_src emacs-lisp :var this=(file-name-directory (buffer-file-name))
  this
#+end_src

[-- Attachment #3: Type: text/plain, Size: 54 bytes --]


Best,

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

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

end of thread, other threads:[~2012-03-31 17:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-23 18:12 Org Babel C/C++ Daimrod
2012-03-26 11:39 ` Eric Schulte
2012-03-28 23:01   ` Daimrod
2012-03-29  1:34     ` Michael Hannon
2012-03-30 11:17       ` Daimrod
2012-03-31 15:47     ` URGENT " Eric Schulte

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