Just for the record, adding the following to my .emacs file seems to solve the 
problem I was having, where the C++ compiler was compiling a source block 
(written  to a temporary file in /tmp/...) and was unable to find an include 
file in the current working directory:

(setq org-babel-C++-compiler
    (concat "g++ -std=c++0x "
            "-I"
            (expand-file-name ".")
    )
)

-- Mike



>________________________________
>From: Michael Hannon <jm_han...@yahoo.com>
>To: Olaf Meeuwissen <olaf.meeuwis...@avasys.jp>
>Cc: Org-Mode List <emacs-orgmode@gnu.org>
>Sent: Friday, November 18, 2011 12:39 AM
>Subject: Re: [O] Problem compiling C++ in Org-mode
>
>Olaf Meeuwissen wrote:
>
>>  Michael Hannon <jm_han...@yahoo.com> writes:
>
>>> Greetings.  I'm having a problem compiling a C++ source-code block in
>>> Org-mode.  The same C++ code compiles and runs in the shell.
>>>
>>> The issue seems to relate to local include files.  [...snip...]
>>> What am I missing?
>>
>>> /tmp/babel-245846_d/C-src-24584NIQ.cpp:7:26: fatal error: OtherStuff.cpp: No
>>> such file or directory
>>> compilation terminated.
>>> /bin/bash: /tmp/babel-245846_d/C-bin-24584aSW: Permission denied
>
>> Compilation is taking place in a temporary directory, miles away from
>> where your org file lives.
>
>>> ########## Org-mode compile uses same option as shell compile:
>>>
>>> org-babel-C++-compiler is a variable defined in `ob-C.el'.
>>> Its value is "g++ -std=c++0x"
>
>> The current directory is not specified in the include path.  You would
>> need to add a -I option to set the (absolute path to the) directory the
>> org file is in.  If you have all your org files in ~/org, you could try
>> "g++ -std=c++0x -I~/org".
>
>Thanks, Olaf.  That does fix the problem, and in some sense that's the obvious
>solution.  On the other hand, it does seem strange to me that the end user
>should have to specify the include directory.  I.e., Emacs clearly knows the
>current directory ("M-x pwd", for instance), and the C++ compiler "knows" to
>look in the current directory for include files enclosed in quote marks.  I
>assumed that the compilation process in Org-mode would include steps similar
>to:
>
>    + remember current directory
>    + write contents of source block to obscure location in /tmp
>    + compile source block in obscure location,
>          but remembering the starting directory for such things
>          as include files
>
>Obviously I was wrong, but it still seems a reasonable approach.
>
>-- Mike
>
>
>
>

Reply via email to