From: Seebs on
On 2010-03-20, Phred Phungus <Phred(a)example.invalid> wrote:
> Ben Bacarisse wrote:
>> Phred Phungus <Phred(a)example.invalid> writes:
>>> http://www.apuebook.com/

>>> $ ls *

>> Why?

>> <snip list of files from the book's source code>

> To have the source available without a million keystrokes is huge.

I think the point of the question is:

Why did you post the huge output of an 'ls' command that was of no
possible use to anyone?

> I'm
> trying to get it set up, but I think I'm having problems with the
> include directive:

What makes you think that?

> $ gcc -D_GNU_SOURCE -std=c99 -Iinclude -Wall -Wextra fig1.10.1.c -o out

Were these options specified for the source you're using? If not, why
are you using them?

> fig1.10.1.c:38: warning: unused parameter �signo�
> /tmp/ccsCEfpI.o: In function `main':
> fig1.10.1.c:(.text+0x40): undefined reference to `err_sys'
> fig1.10.1.c:(.text+0xa7): undefined reference to `err_sys'
> fig1.10.1.c:(.text+0xe8): undefined reference to `err_ret'
> fig1.10.1.c:(.text+0x12f): undefined reference to `err_sys'
> collect2: ld returned 1 exit status

Nothing here refers to any inclusions. What makes you think you are having
problems with the include directive?

> It finds apue.h in the include subdirectory.

Yes.

> ... and there's no man page for err_sys nor an entry in susv3.
>
> What gives?

Since you are getting "undefined reference to...", rather than complaints
about the implicit declaration (which is what you'd get if there were
no declaration), the most likely inference would be that the program
is intended to rely on an "err_sys" function defined elsewhere in the
associated source, rather than being a standalone program.

It's truly a shame that this package doesn't come with a README, a Makefile,
and fairly straightforward instructions for how to compile everything
automatically, including the necessary compiler flags and options to first
create, and then link everything against, the library defining these
functions.

Oh, wait. It does.

Seriously, you would save SO much time if you would just start with
obvious things like "read the file called README first". The provided
Makefiles do indeed build from source (although some components may not
work on some systems, as there's always a bit of change going on in
the fringes of the specs).

Again, the problem is that you're not *thinking*. You're trying stuff
for no obvious reason, and then when it doesn't work, instead of reading
the error message, thinking about it, and trying to solve the problem, you
just post on Usenet.

The flags you specified should generate a warning for any function called
without a prototype. Therefore, a prototype was declared. Where was it
declared? Find the prototype, and that may give you ideas. Oh, hey, it
was declared in "apue.h". It takes all of five seconds to find err_sys:

$ grep '^err_sys' */*.c
lib/error.c:err_sys(const char *fmt, ...)

Well, there you have it. It's in lib/error.c. Hmm. That's in a directory
called "lib", which probably contains a LIBrary of functionality. Again,
if you'd used the Makefile, this woulda just worked. But it shouldn't be
too hard to figure out how to build the library providing the helper functions
used by the apue code and link against it.

Did anything, anywhere, claim that the examples were intended to be standalone
code? No. Did anything, anywhere, claim that you should compile them as C99
source? No. Did anything, anywhere, tell you to use -D_GNU_SOURCE for the
APUE code? Why, no.

Your problem is that you don't follow instructions, and you don't think. You
can get pretty far thinking about things without following the instructions.
You can get pretty far following the instructions without thinking. You can
get very far indeed if you follow the instructions, while continuing to think
all the time in case the instructions are flawed. But if you neither follow
the instructions nor think, you're never gonna get anywhere.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Lew Pitcher on
Warning:

Lew Pitcher, who posts to this newsgroup, is a domain thief.

Read the full story at http://www.lewpitcher.ca

From: Phred Phungus on
Seebs wrote:
> On 2010-03-20, Phred Phungus <Phred(a)example.invalid> wrote:
>> Ben Bacarisse wrote:
>>> Phred Phungus <Phred(a)example.invalid> writes:
>>>> http://www.apuebook.com/
>
>>>> $ ls *
>
>>> Why?
>
>>> <snip list of files from the book's source code>
>
>> To have the source available without a million keystrokes is huge.
>
> I think the point of the question is:
>
> Why did you post the huge output of an 'ls' command that was of no
> possible use to anyone?
>
>> I'm
>> trying to get it set up, but I think I'm having problems with the
>> include directive:
>
> What makes you think that?
>
>> $ gcc -D_GNU_SOURCE -std=c99 -Iinclude -Wall -Wextra fig1.10.1.c -o out
>
> Were these options specified for the source you're using? If not, why
> are you using them?
>
>> fig1.10.1.c:38: warning: unused parameter �signo�
>> /tmp/ccsCEfpI.o: In function `main':
>> fig1.10.1.c:(.text+0x40): undefined reference to `err_sys'
>> fig1.10.1.c:(.text+0xa7): undefined reference to `err_sys'
>> fig1.10.1.c:(.text+0xe8): undefined reference to `err_ret'
>> fig1.10.1.c:(.text+0x12f): undefined reference to `err_sys'
>> collect2: ld returned 1 exit status
>
> Nothing here refers to any inclusions. What makes you think you are having
> problems with the include directive?
>
>> It finds apue.h in the include subdirectory.
>
> Yes.
>
>> ... and there's no man page for err_sys nor an entry in susv3.
>>
>> What gives?
>
> Since you are getting "undefined reference to...", rather than complaints
> about the implicit declaration (which is what you'd get if there were
> no declaration), the most likely inference would be that the program
> is intended to rely on an "err_sys" function defined elsewhere in the
> associated source, rather than being a standalone program.
>
> It's truly a shame that this package doesn't come with a README, a Makefile,
> and fairly straightforward instructions for how to compile everything
> automatically, including the necessary compiler flags and options to first
> create, and then link everything against, the library defining these
> functions.
>
> Oh, wait. It does.
>
> Seriously, you would save SO much time if you would just start with
> obvious things like "read the file called README first". The provided
> Makefiles do indeed build from source (although some components may not
> work on some systems, as there's always a bit of change going on in
> the fringes of the specs).
>
> Again, the problem is that you're not *thinking*. You're trying stuff
> for no obvious reason, and then when it doesn't work, instead of reading
> the error message, thinking about it, and trying to solve the problem, you
> just post on Usenet.
>
> The flags you specified should generate a warning for any function called
> without a prototype. Therefore, a prototype was declared. Where was it
> declared? Find the prototype, and that may give you ideas. Oh, hey, it
> was declared in "apue.h". It takes all of five seconds to find err_sys:
>
> $ grep '^err_sys' */*.c
> lib/error.c:err_sys(const char *fmt, ...)
>
> Well, there you have it. It's in lib/error.c. Hmm. That's in a directory
> called "lib", which probably contains a LIBrary of functionality. Again,
> if you'd used the Makefile, this woulda just worked. But it shouldn't be
> too hard to figure out how to build the library providing the helper functions
> used by the apue code and link against it.
>
> Did anything, anywhere, claim that the examples were intended to be standalone
> code? No. Did anything, anywhere, claim that you should compile them as C99
> source? No. Did anything, anywhere, tell you to use -D_GNU_SOURCE for the
> APUE code? Why, no.
>
> Your problem is that you don't follow instructions, and you don't think. You
> can get pretty far thinking about things without following the instructions.
> You can get pretty far following the instructions without thinking. You can
> get very far indeed if you follow the instructions, while continuing to think
> all the time in case the instructions are flawed. But if you neither follow
> the instructions nor think, you're never gonna get anywhere.
>
> -s


$ gcc -D_GNU_SOURCE -std=c99 -Iinclude -Wall -Wextra lib/error.o
fig1.10.1.c -o out
fig1.10.1.c:38: warning: unused parameter �signo�
$ ./out
% 5
couldn't execute: 5: Permission denied
% ^Cinterrupt
^C% interrupt


I thank you for the tip about including error.o, but I find your
condescension insufferable.

The garbage you spew above ranges from right to wrong to unknowable but
never veers from smug.

http://i39.tinypic.com/wb2sue.jpg
--
fred
From: Ben Bacarisse on
[Not really a shell issue so I've trimmed the groups.]

Phred Phungus <Phred(a)example.invalid> writes:

> Seebs wrote:
<snip>
>> The flags you specified should generate a warning for any function called
>> without a prototype. Therefore, a prototype was declared. Where was it
>> declared? Find the prototype, and that may give you ideas. Oh, hey, it
>> was declared in "apue.h". It takes all of five seconds to find err_sys:
>>
>> $ grep '^err_sys' */*.c
>> lib/error.c:err_sys(const char *fmt, ...)
>>
>> Well, there you have it. It's in lib/error.c. Hmm. That's in a directory
>> called "lib", which probably contains a LIBrary of functionality. Again,
>> if you'd used the Makefile, this woulda just worked. But it shouldn't be
>> too hard to figure out how to build the library providing the helper functions
>> used by the apue code and link against it.
<snip>
> $ gcc -D_GNU_SOURCE -std=c99 -Iinclude -Wall -Wextra lib/error.o
> fig1.10.1.c -o out
> fig1.10.1.c:38: warning: unused parameter 'signo'
> $ ./out
> % 5
> couldn't execute: 5: Permission denied
> % ^Cinterrupt
> ^C% interrupt
>
>
> I thank you for the tip about including error.o, but I find your
> condescension insufferable.

Seebs never suggested you include error.o. He suggested you use the
makefile. Failing that, he suggests you build the library and link
against it. Unless you do one or other of these, you will eventually
hit more problems.

<snip>
--
Ben.
From: Seebs on
On 2010-03-25, Phred Phungus <Phred(a)example.invalid> wrote:
> So I guess I'm to believe there's a make in here:

No.

> $ cat Make.defines.linux
> # Common make definitions, customized for each platform

Right.

The actual makefile incorporates these definitions in some way.
There is not "a make in here". It's just settings.

> I ran this and didn't really know what it would do, but I have since
> come to realize that it compiled all the .c files in subdirectories into
> object files:

Pretty much!

> [if you do not have the patience to skim or skip through this, I'd
> rather that you moved on]

It's not a question of patience, but of bandwidth. This "ls *" output
does not add any information or utility to the post.

> It is absolutely true that I would never have had an executable here
> without being informed that I had to link to error.o. I took a second
> look at the book and the website, and there was nothing in either.

The makefile shows it, but you actually have to read through it some,
or just look at the source files.

> My question is this. How do I alter this makefile to also compile,
> link, and a create an executable for C source in the parent directory?

Good question! One way to do that would be to look at the commands that
are run when make runs, and see if you can figure out, from what it's
already doing, how to do something else.

For instance, you might find that something pretty close to:

cc -o foo foo.o lib/libapue.a

or something similar would combine an object module with the library
in question. Of course, I may have the name of the library wrong; you'd
have to look at the makefiles to figure that out. But in general, it's
surprisingly straightforward. The trick is that you have to look, not
for a specific recipe to do a specific thing, but some kind of conception
of what the parts of the recipe do.

The compiler can, among other things, link multiple hunks of code together.
One obvious hunk of code to use would be the library containing the error
functions. Another would be the object code you created previously from
your source (using cc -c).

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!