all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Compilation in C and ADA
@ 2016-07-19 11:11 Edward Zacharek
  2016-07-19 17:36 ` B.V. Raghav
  2016-07-23 16:23 ` Kendall Shaw
  0 siblings, 2 replies; 12+ messages in thread
From: Edward Zacharek @ 2016-07-19 11:11 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I tried to compile two files, one in ADA, the other in C, and both have
failed.

The ADA file was a simple one, a basic "Hello World" code, which I found
over here:
https://gcc.gnu.org/onlinedocs/gnat_ugn/Running-a-Simple-Ada-Program.html

In order to compile the adb file, I click on tools->compile, and press on
"enter", and this is the error message that I receive:
"make -k
make: *** No targets specified and no makefile found.  Stop.

Compilation exited abnormally with code 2 at Tue Jul 19 14:10:18".

As for a C file, this is what I get:

"make -k
make: *** No targets specified and no makefile found.  Stop.

Compilation exited abnormally with code 2 at Tue Jul 19 14:11:04",
So I get exactly the same error.
I think I am doing something wrong.

Can you please help me out?

Best Regards
Roman Edward Zacharek


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

* Re: Compilation in C and ADA
  2016-07-19 11:11 Edward Zacharek
@ 2016-07-19 17:36 ` B.V. Raghav
  2016-07-20  2:50   ` Francis Belliveau
  2016-07-23 16:23 ` Kendall Shaw
  1 sibling, 1 reply; 12+ messages in thread
From: B.V. Raghav @ 2016-07-19 17:36 UTC (permalink / raw)
  To: Edward Zacharek; +Cc: help-gnu-emacs

Edward Zacharek <zacharekedward@gmail.com> writes:

> In order to compile the adb file, I click on tools->compile, and press on
> "enter", and this is the error message that I receive:
> "make -k
`make -k' is a shell command that shall be run by emacs and the output
`rendered' in a compilation buffer. What you require is to clear this in
the `minibuffer', using `C-a C-k', and enter something like:

gnatmake hello.adb

or whatever be the filename instead of hello.adb

You might probably be looking for "gnatmake " to be there in the
minibuffer instead of "make -k" everytime you compile ".adb" file.
(use `C-h v compile-command') or package `SmartCompile' or more...
https://www.emacswiki.org/emacs/CompileCommand

> As for a C file, this is what I get:
>
> "make -k
Here the command might be like "gcc hello_dolly.cpp"
You might be interested in automating the compile process for
c-project(s), in which case, google is the best friend
https://www.gnu.org/software/make/ or
https://cmake.org/ or
http://www.boost.org/build/tutorial.html#basic_tasks

In either of these cases, just customize the variable `compile-command'



Best

-- 
(B.V. Raghav)
Ph.D. Student,
Design Programme, IIT Kanpur



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

* Re: Compilation in C and ADA
  2016-07-19 17:36 ` B.V. Raghav
@ 2016-07-20  2:50   ` Francis Belliveau
  2016-07-20  4:30     ` B.V. Raghav
  0 siblings, 1 reply; 12+ messages in thread
From: Francis Belliveau @ 2016-07-20  2:50 UTC (permalink / raw)
  To: B.V. Raghav; +Cc: help-gnu-emacs

Although previous response described how to work around the problem, I believe that bit of clarity expansion is needed here with regard to what is actually happening.

I am no emacs expert, but from the evidence it seems clear to me that the emacs "compile" default is to make an entire application, not just compile a single file or the current buffer.

It has been a long time since I used Ada, so I cannot speak to how Ada applications are built these days, but I expect "make" can be used to do it.

However, both C and C++ developers commonly use make, or one of its many flavors, to describe the dependancies between application sources and how to build the applications.  Normally when you compile a C file you get an object file, not an executable program.  All the objects for the project, just the one in this case, then need to be linked with the appropriate set of libraries in order to create the program executable.  Again this is just a simple system library in the case of a "hello" application.

Since I do not use the menus either, I do not know what the various choices are.  
However, this sounds to me like a "Human Factors" ambiguity problem.  

Either the default for "compile" should be to execute "gcc" rather than "make", or the menu command "compile" should be changed to something like "make app".





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

* Re: Compilation in C and ADA
       [not found] <mailman.1680.1468936015.26859.help-gnu-emacs@gnu.org>
@ 2016-07-20  3:43 ` Rusi
  0 siblings, 0 replies; 12+ messages in thread
From: Rusi @ 2016-07-20  3:43 UTC (permalink / raw)
  To: help-gnu-emacs

On Tuesday, July 19, 2016 at 7:16:58 PM UTC+5:30, Edward Zacharek wrote:
> Hello,
> 
> I tried to compile two files, one in ADA, the other in C, and both have
> failed.
> 
> The ADA file was a simple one, a basic "Hello World" code, which I found
> over here:
> https://gcc.gnu.org/onlinedocs/gnat_ugn/Running-a-Simple-Ada-Program.html
> 
> In order to compile the adb file, I click on tools->compile, and press on
> "enter", and this is the error message that I receive:
> "make -k
> make: *** No targets specified and no makefile found.  Stop.
> 
> Compilation exited abnormally with code 2 at Tue Jul 19 14:10:18".
> 
> As for a C file, this is what I get:
> 
> "make -k
> make: *** No targets specified and no makefile found.  Stop.
> 
> Compilation exited abnormally with code 2 at Tue Jul 19 14:11:04",
> So I get exactly the same error.
> I think I am doing something wrong.
> 
> Can you please help me out?

This is not really an emacs question -- which is ok in general.
In this case it would be better if you followed the instructions of the link
you gave and run:
gcc -c hello.adb

after the prompt ($) as indicated. ie run it in a shell

Once you do that and it runs making it run in emacs is a small thing

If it doesn’t, solving that has nothing to do with emacs


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

* Re: Compilation in C and ADA
  2016-07-20  2:50   ` Francis Belliveau
@ 2016-07-20  4:30     ` B.V. Raghav
  2016-07-23 14:22       ` Francis Belliveau
       [not found]       ` <mailman.1922.1469283823.26859.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 12+ messages in thread
From: B.V. Raghav @ 2016-07-20  4:30 UTC (permalink / raw)
  To: Francis Belliveau; +Cc: help-gnu-emacs

Francis Belliveau <f.belliveau@comcast.net> writes:
[...]
> I am no emacs expert, but from the evidence it seems clear to me that
> the emacs "compile" default is to make an entire application, not just
> compile a single file or the current buffer.
>
`C-h f compile' details out how I can build over the compile command to
	suit my needs. 

For a higher order automation, here is an excerpt from `Info > ede >
Building and Debugging' (C-h i m ede RET m build TAB RET)

#+BEGIN_QUOTE

  EDE provides the following “project-aware” compilation and debugging
  commands:

  ‘C-c . c’
       Compile the current target (‘ede-compile-target’).
  ‘C-c . C’
       Compile the entire project (‘ede-compile-project’).
  ‘c-c . D’
       Debug the current target (‘ede-debug-target’).
  ‘M-x ede-make-dist’
       Build a distribution file for your project.

     These commands are also available from the ‘Development’ menu.

#+END_QUOTE

> It has been a long time since I used Ada, so I cannot speak to how Ada
> applications are built these days, but I expect "make" can be used to
> do it.
>
Eitherways, it seems to be `configurable' into my project system.
https://gcc.gnu.org/onlinedocs/gnat_ugn/Running-a-Simple-Ada-Program.html

> However, both C and C++ developers commonly use make, or one of its
> many flavors, to describe the dependancies between application sources
> and how to build the applications.  Normally when you compile a C file
> you get an object file, not an executable program.  All the objects
> for the project, just the one in this case, then need to be linked
> with the appropriate set of libraries in order to create the program
> executable.  Again this is just a simple system library in the case of
> a "hello" application.
>

Emacs does provide an interface to this shell command, with compile.
(Info > Emacs > Building > Compilation) details it out. Here is an
excerpt.

#+BEGIN_QUOTE
   The default compilation command is ‘make -k’, which is usually
correct for programs compiled using the ‘make’ utility (the ‘-k’ flag
tells ‘make’ to continue compiling as much as possible after an error).
*Note Make: (make)Top.  If you have done ‘M-x compile’ before, the
command that you specified is automatically stored in the variable
‘compile-command’; this is used as the default the next time you type
‘M-x compile’.  A file can also specify a file-local value for
‘compile-command’ (*note File Variables::).
#+END_QUOTE

> Since I do not use the menus either, I do not know what the various choices are.  
> However, this sounds to me like a "Human Factors" ambiguity problem.  
>
I do not understand the "Human Factors" ambiguity problem. So I refrain
speaking here

> Either the default for "compile" should be to execute "gcc" rather
> than "make", or the menu command "compile" should be changed to
> something like "make app".
>
You may try ply around with this:

(global-set-key (kbd "C-c C-c C-c")
                (lambda ()
                  (compile (format "gcc -c -o %s %s"
				   (replace-regexp-in-string "\\.[^\\.]*$"
							     ".o"
							     (buffer-file-name))
				   (buffer-file-name)))))


-- 
(B.V. Raghav)
Ph.D. Student,
Design Programme, IIT Kanpur



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

* Re: Compilation in C and ADA
  2016-07-20  4:30     ` B.V. Raghav
@ 2016-07-23 14:22       ` Francis Belliveau
  2016-07-23 17:52         ` Dale Snell
       [not found]         ` <mailman.1937.1469296394.26859.help-gnu-emacs@gnu.org>
       [not found]       ` <mailman.1922.1469283823.26859.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 12+ messages in thread
From: Francis Belliveau @ 2016-07-23 14:22 UTC (permalink / raw)
  To: B.V. Raghav; +Cc: help-gnu-emacs

I guess I need to clarify what I meant about "Human Factors Ambiguity" a bit.

If a menu selection says "compile" then "compile" is what it should be trying to do, not "make".  This is simply a matter if naming things so that they set expectations properly and eliminate the need to read documentation up front.

Put aside the ability to customize things.  That is necessary due to the diversity of development environments, etc.

If I see a command like "compile" in a menu, I expect it to call the compiler for me, not attempt to "make" my project.

Fran


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

* Re: Compilation in C and ADA
       [not found]       ` <mailman.1922.1469283823.26859.help-gnu-emacs@gnu.org>
@ 2016-07-23 15:05         ` Emanuel Berg
  2016-07-24  4:20           ` Francis Belliveau
       [not found]           ` <mailman.1955.1469334108.26859.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 12+ messages in thread
From: Emanuel Berg @ 2016-07-23 15:05 UTC (permalink / raw)
  To: help-gnu-emacs

Francis Belliveau wrote:

> If a menu selection says "compile" then
> "compile" is what it should be trying to do,
> not "make".

If there is a Makefile, I'd say compile and
make are synonymous because why else is there
a Makefile?

But isn't it a DWIM command, i.e., if there is
a Makefile, that is used, if there isn't,
a prompt for the compilation tool/command
appears, or if there is a default command
specified already it is executed? I don't know
because there have been ages since I compiled
anything without a Makefile!

> Put aside the ability to customize things.
> That is necessary due to the diversity of
> development environments, etc.

And the diversity of programmers...

But the make approach isn't the "least bad"
wich is tolerable because of its diversity.
It is the best I've seen to this date. I use it
with programming, but also with LaTeX, and
other types of processing which should happen
upon the update of files.

Why and how would anyone benefit from moving it
into Emacs? There is already a mode to edit the
Makefile itself.

One should not think of the Makefile as
something disassociated from the project. It is
as much part of the project as the source.
First thing when I start a new project is
create a Makefile and an Emacs shortcut to get
me there in a heartbeat.

> If I see a command like "compile" in a menu,
> I expect it to call the compiler for me, not
> attempt to "make" my project.

Write your own function!

-- 
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
                   - so far: 58 Blogomatic articles -                   


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

* Re: Compilation in C and ADA
  2016-07-19 11:11 Edward Zacharek
  2016-07-19 17:36 ` B.V. Raghav
@ 2016-07-23 16:23 ` Kendall Shaw
  1 sibling, 0 replies; 12+ messages in thread
From: Kendall Shaw @ 2016-07-23 16:23 UTC (permalink / raw)
  To: help-gnu-emacs

On 07/19/2016 04:11 AM, Edward Zacharek wrote:

> In order to compile the adb file, I click on tools->compile, and press on
> "enter", and this is the error message that I receive:
> "make -k
> make: *** No targets specified and no makefile found.  Stop.
>
> Compilation exited abnormally with code 2 at Tue Jul 19 14:10:18".

The other answers include this information, but the basic problem is 
that tools->compile isn't meant to be figuring out on it's own how to 
compile the file that is in your buffer.

By default, it is looking for a make file and not finding one. So, it 
says so.

Essentially, first figure out how to build your ada/c files from the 
command line, then figure out how to create a single command that does 
that, then have tools->compile use that command.

Kendall

> As for a C file, this is what I get:
>
> "make -k
> make: *** No targets specified and no makefile found.  Stop.
>
> Compilation exited abnormally with code 2 at Tue Jul 19 14:11:04",
> So I get exactly the same error.
> I think I am doing something wrong.
>
> Can you please help me out?
>
> Best Regards
> Roman Edward Zacharek
>
>




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

* Re: Compilation in C and ADA
  2016-07-23 14:22       ` Francis Belliveau
@ 2016-07-23 17:52         ` Dale Snell
       [not found]         ` <mailman.1937.1469296394.26859.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 12+ messages in thread
From: Dale Snell @ 2016-07-23 17:52 UTC (permalink / raw)
  To: help-gnu-emacs

On Sat, 23 Jul 2016 10:22:22 -0400, in message
1D8794DF-16FD-43C6-8F74-43EAFC1B6D0A@comcast.net, Francis Belliveau
wrote:

> 
> If I see a command like "compile" in a menu, I expect it to call the
> compiler for me, not attempt to "make" my project.

But which compiler would that be?  There are lots of different
compilers out there, for lots of different languages.  Emacs is
capable of many things, but it cannot read minds.  You have to
tell it which compiler to use.  It gives you the opportunity to do
when you select "Compile..." from the menu:

    "Compile command: make -k "

appears in the mini-buffer.  Delete the "make -k " and replace it
with whatever command line runs your compiler of choice.  Emacs
will retain this command until it is explicitly changed, or until
you restart Emacs.

You could create a Makefile that will call your compiler, but for
a single file project that's a bit of overkill, IMO.  If you're
going to be repeatedly compiling a single file, you could add
a file-local variable.  For example, put

// -*- mode: compile-command: "compile prognam.c > prognam.o" -*-

in the first line of your program file, substituting whatever
values of compile and prognam you require.  (Replace the leading
"//" with whatever comment delimiter you need.)  That will set the
compile command to whatever you need when the program file is
loaded.  (Note that it won't change if you change the file-local
variable _after_ you've loaded the file.)

I hope this helps.

--Dale

-- 
Pessimist:  The glass is half empty.
Optimist:   The glass is half full.
Engineer:   The glass is twice as big as it needs to be.



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

* Re: Compilation in C and ADA
       [not found]         ` <mailman.1937.1469296394.26859.help-gnu-emacs@gnu.org>
@ 2016-07-23 20:08           ` Emanuel Berg
  0 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2016-07-23 20:08 UTC (permalink / raw)
  To: help-gnu-emacs

Dale Snell wrote:

> You could create a Makefile that will call
> your compiler, but for a single file project
> that's a bit of overkill, IMO.

It is a good idea to have a Makefile even for
the short time when the project consists of
a single file, because even the smallest
project get by this state very fast, and if
there isn't a Makefile, the programmer may be
hesitant to split the program into two files
even when it is natural as this will imply the
extra work of setting up a Makefile.

It is good to do it day one and be done
with it!

With C, obviously there are the header files,
but even in Ada, IIRC from my schoolbook
experience of the language you'd similarly put
"definitions" in one file, and "implementations"
in a corresponding?

-- 
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
                   - so far: 58 Blogomatic articles -                   


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

* Re: Compilation in C and ADA
  2016-07-23 15:05         ` Emanuel Berg
@ 2016-07-24  4:20           ` Francis Belliveau
       [not found]           ` <mailman.1955.1469334108.26859.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 12+ messages in thread
From: Francis Belliveau @ 2016-07-24  4:20 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

A lot of good comments that I pretty much agree with, but there is a small difference of opinion and I am feeling incompletely understood.

1. I agree that most projects should have a makefile, regardless of the language(s) used, or the number of files that need to be "built".

2. Yes, the functional execution of the default is doing a good job of saying what it is looking for and why it is not functioning.  It says it is calling make and cannot find a makefile.

3. As far as which compiler to use, you might as well assume "gcc" since "make" is not always there either.  There are many flavors of make that "make -k" would not be compatible with.

The basic disagreement is that "make" or "build" is not synonymous with "compile".  I do consider both make" and "build" synonymous with each other in this context.

Compile is but one step toward building or making an executable or a project.  A makefile that only compiles sources without combining them together into a unit, such as a library, archive, or executable, is not worth writing.

Yes, many compilers, gcc included, can be fed a complex command line to compile a single file and turn it into an executable application.  However, even though you would be using a compiler to perform the function, that function is a "make" or "build" fiction that includes "compile" as one of the steps.

At this point I am either beating a dead horse, or trying to convince some of you that I am right when you will never agree.  I feel like I have said the same thing twice so if you do not agree with me then we should just agree to disagree and drop things there so that we do not turn this into some sort of war over what some readers may consider to be minor semantics.

No offense meant to any of you and none taken by me at this point.

73 to all,
Fran


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

* Re: Compilation in C and ADA
       [not found]           ` <mailman.1955.1469334108.26859.help-gnu-emacs@gnu.org>
@ 2016-07-24 12:48             ` Emanuel Berg
  0 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2016-07-24 12:48 UTC (permalink / raw)
  To: help-gnu-emacs

Francis Belliveau wrote:

> 3. As far as which compiler to use, you might
> as well assume "gcc" since "make" is not
> always there either. There are many flavors
> of make that "make -k" would not be
> compatible with.

3. You can change this by setting the variable
   `compile-command'. For example, I have that:

       (setq compile-command "make -j 4 -s -k ")
       (setq compilation-read-command nil)

   Danger! The docstring for
   `compilation-read-command' says:

       Note that changing this to nil may be
       a security risk, because a file might
       define a malicious `compile-command' as
       a file local variable, and you might not
       notice. Therefore, `compile-command' is
       considered unsafe if this variable
       is nil.

> Compile is but one step toward building or
> making an executable or a project. A makefile
> that only compiles sources without combining
> them together into a unit, such as a library,
> archive, or executable, is not worth writing.

OK:

    (defalias 'compile-and-link 'compile)

> 73 to all

Ham radio (amateur radio) lingo meaning hasta
la vista, baby.

--
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
                   - so far: 58 Blogomatic articles -


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

end of thread, other threads:[~2016-07-24 12:48 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1680.1468936015.26859.help-gnu-emacs@gnu.org>
2016-07-20  3:43 ` Compilation in C and ADA Rusi
2016-07-19 11:11 Edward Zacharek
2016-07-19 17:36 ` B.V. Raghav
2016-07-20  2:50   ` Francis Belliveau
2016-07-20  4:30     ` B.V. Raghav
2016-07-23 14:22       ` Francis Belliveau
2016-07-23 17:52         ` Dale Snell
     [not found]         ` <mailman.1937.1469296394.26859.help-gnu-emacs@gnu.org>
2016-07-23 20:08           ` Emanuel Berg
     [not found]       ` <mailman.1922.1469283823.26859.help-gnu-emacs@gnu.org>
2016-07-23 15:05         ` Emanuel Berg
2016-07-24  4:20           ` Francis Belliveau
     [not found]           ` <mailman.1955.1469334108.26859.help-gnu-emacs@gnu.org>
2016-07-24 12:48             ` Emanuel Berg
2016-07-23 16:23 ` Kendall Shaw

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.