* Problem compiling C++ in Org-mode
@ 2011-11-18 4:56 Michael Hannon
2011-11-18 7:38 ` Olaf Meeuwissen
0 siblings, 1 reply; 8+ messages in thread
From: Michael Hannon @ 2011-11-18 4:56 UTC (permalink / raw)
To: Org-Mode List
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. I.e., a program that
includes only standard files, such as:
#include <iostream>
works fine. But Org-mode seems to be unable to find a file included from the
current directory, such as:
#include "OtherStuff.cpp"
I've appended the Org source code and associated error message.
I've also appended the log of a successful compilation of the same source code
in the shell, as well as the details of my configuration.
What am I missing?
Thanks,
-- Mike
########## Unsuccessful attempt to compile in Org-mode
* Test
#+begin_src cpp
#include <iostream>
#include <memory>
#include "OtherStuff.cpp"
using namespace std;
int main() {
cout << "Hello!" << endl;
}
#+end_src
#+results:
/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
########## Successful compilation in linux shell
$ cat junk.cpp
#include <iostream>
#include <memory>
#include "OtherStuff.cpp"
using namespace std;
int main() {
cout << "Hello!" << endl;
}
$ g++ -o junk -std=c++0x junk.cpp
$ ./junk
Hello!
########## 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"
Documentation:
Command used to compile a C++ source code file into an
executable.
########## My configuration
Emacs : GNU Emacs 23.3.1 (x86_64-redhat-linux-gnu, GTK+ Version 2.24.5)
of 2011-06-29 on x86-01.phx2.fedoraproject.org
Package: Org-mode version 7.7 (release_7.7.328.g1a97.dirty)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem compiling C++ in Org-mode
2011-11-18 4:56 Problem compiling C++ in Org-mode Michael Hannon
@ 2011-11-18 7:38 ` Olaf Meeuwissen
2011-11-18 8:39 ` Michael Hannon
0 siblings, 1 reply; 8+ messages in thread
From: Olaf Meeuwissen @ 2011-11-18 7:38 UTC (permalink / raw)
To: Michael Hannon; +Cc: Org-Mode List
Michael Hannon <jm_hannon@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".
Hope this helps,
--
Olaf Meeuwissen, LPIC-2 FLOSS Engineer -- AVASYS CORPORATION
FSF Associate Member #1962 Help support software freedom
http://www.fsf.org/jf?referrer=1962
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem compiling C++ in Org-mode
2011-11-18 7:38 ` Olaf Meeuwissen
@ 2011-11-18 8:39 ` Michael Hannon
2011-11-18 9:32 ` Olaf Meeuwissen
2011-11-18 19:59 ` Michael Hannon
0 siblings, 2 replies; 8+ messages in thread
From: Michael Hannon @ 2011-11-18 8:39 UTC (permalink / raw)
To: Olaf Meeuwissen; +Cc: Org-Mode List
Olaf Meeuwissen wrote:
> Michael Hannon <jm_hannon@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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem compiling C++ in Org-mode
2011-11-18 8:39 ` Michael Hannon
@ 2011-11-18 9:32 ` Olaf Meeuwissen
2011-11-18 19:59 ` Michael Hannon
1 sibling, 0 replies; 8+ messages in thread
From: Olaf Meeuwissen @ 2011-11-18 9:32 UTC (permalink / raw)
To: Michael Hannon; +Cc: Org-Mode List
Michael Hannon <jm_hannon@yahoo.com> writes:
> Olaf Meeuwissen wrote:
>
>> Michael Hannon <jm_hannon@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
Of course, here's where Emacs would have to tell the compiler where that
starting directory would be and know what option that compiler takes to
do so. Here's hoping that -I works everywhere ... probably not.
> Obviously I was wrong, but it still seems a reasonable approach.
Hope this helps,
--
Olaf Meeuwissen, LPIC-2 FLOSS Engineer -- AVASYS CORPORATION
FSF Associate Member #1962 Help support software freedom
http://www.fsf.org/jf?referrer=1962
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem compiling C++ in Org-mode
2011-11-18 8:39 ` Michael Hannon
2011-11-18 9:32 ` Olaf Meeuwissen
@ 2011-11-18 19:59 ` Michael Hannon
2011-11-18 20:16 ` Eric Schulte
2011-11-18 22:57 ` Sebastien Vauban
1 sibling, 2 replies; 8+ messages in thread
From: Michael Hannon @ 2011-11-18 19:59 UTC (permalink / raw)
To: Michael Hannon, Olaf Meeuwissen; +Cc: Org-Mode List
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_hannon@yahoo.com>
>To: Olaf Meeuwissen <olaf.meeuwissen@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_hannon@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
>
>
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem compiling C++ in Org-mode
2011-11-18 19:59 ` Michael Hannon
@ 2011-11-18 20:16 ` Eric Schulte
2011-11-18 22:57 ` Sebastien Vauban
1 sibling, 0 replies; 8+ messages in thread
From: Eric Schulte @ 2011-11-18 20:16 UTC (permalink / raw)
To: Michael Hannon; +Cc: Org-Mode List, Olaf Meeuwissen
A slightly cleaner solution would be the following.
(add-to-list 'org-babel-default-header-args:C
(cons :flags (concat "-std=c++0x -I " (expand-file-name "."))))
But either the above or below configuration will likely only work if the
directory holding your .emacs is the same directory in which the
included files are held.
Best -- Eric
Michael Hannon <jm_hannon@yahoo.com> writes:
> 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_hannon@yahoo.com>
>>To: Olaf Meeuwissen <olaf.meeuwissen@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_hannon@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
>>
>>
>>
>>
>
--
Eric Schulte
http://cs.unm.edu/~eschulte/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem compiling C++ in Org-mode
2011-11-18 19:59 ` Michael Hannon
2011-11-18 20:16 ` Eric Schulte
@ 2011-11-18 22:57 ` Sebastien Vauban
2011-11-19 5:13 ` Michael Hannon
1 sibling, 1 reply; 8+ messages in thread
From: Sebastien Vauban @ 2011-11-18 22:57 UTC (permalink / raw)
To: emacs-orgmode-mXXj517/zsQ
Hi Michael,
Michael Hannon wrote:
> 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 ".")
> )
> )
Your previous version contained "-I~/...". I don't know why you changed it,
but this could eventually enlighten you:
┏━━━━[ from Cygwin's ML]
┃ "If a word begins with an unquoted tilde character (`~'), all of the
┃ characters up to the first unquoted slash (or all characters, if there
┃ is no unquoted slash) are considered a TILDE-PREFIX."
┃
┃ Note "word begins". I've been bitten by this in a makefile:
┃
┃ OPENSSL_DIR := ~/lib/openssl
┃ CPPFLAGS := -I$(OPENSSL_DIR)
┃
┃ The gcc command line then contained -I~/lib/openssl, and the ~ was not
┃ expanded by the shell. ${HOME}/lib/openssl would have worked.
┗━━━━
Best regards,
Seb
--
Sebastien Vauban
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Problem compiling C++ in Org-mode
2011-11-18 22:57 ` Sebastien Vauban
@ 2011-11-19 5:13 ` Michael Hannon
0 siblings, 0 replies; 8+ messages in thread
From: Michael Hannon @ 2011-11-19 5:13 UTC (permalink / raw)
To: Sebastien Vauban, emacs-orgmode@gnu.org
> From: Sebastien Vauban <wxhgmqzgwmuf@spammotel.com>
>> 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 ".")
>> )
>> )
> Your previous version contained "-I~/...". I don't know why you changed it,
> but this could eventually enlighten you:
>
> ┏━━━━[ from Cygwin's ML]
> ┃ "If a word begins with an unquoted tilde character (`~'), all of the
> ┃ characters up to the first unquoted slash (or all characters, if there
> ┃ is no unquoted slash) are considered a TILDE-PREFIX."
> ┃
> ┃ Note "word begins". I've been bitten by this in a makefile:
> ┃
> ┃ OPENSSL_DIR := ~/lib/openssl
> ┃ CPPFLAGS := -I$(OPENSSL_DIR)
> ┃
> ┃ The gcc command line then contained -I~/lib/openssl, and the ~ was not
> ┃ expanded by the shell. ${HOME}/lib/openssl would have worked.
> ┗━━━━
>
Hi, Seb. Thanks for the heads-up. The version that I have now seems to work,
but, just FYI, the explanation for the change of syntax is explained in the
little dialogue that I had with myself:
Hmm, to get this thing to compile, I have to tack on some "-I..." stuff to my
g++ command. This is tedious. How can I do this automatically?
I'll bet I know: there must be some way to concatenate strings in Emacs lisp.
(Google search for some terms vaguely related to "Emacs lisp concatenate".)
(Look at one of the Google hits and stumble across an example that turns out
to use "expand-file".)
What do you suppose expand-file does? (Try it.) Cool!
(Break from problem-solving loop)
-- Mike
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-11-19 5:13 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-18 4:56 Problem compiling C++ in Org-mode Michael Hannon
2011-11-18 7:38 ` Olaf Meeuwissen
2011-11-18 8:39 ` Michael Hannon
2011-11-18 9:32 ` Olaf Meeuwissen
2011-11-18 19:59 ` Michael Hannon
2011-11-18 20:16 ` Eric Schulte
2011-11-18 22:57 ` Sebastien Vauban
2011-11-19 5:13 ` Michael Hannon
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).