From: Ben Bacarisse on
Phred Phungus <Phred(a)example.invalid> writes:

> Ian Collins wrote:
>> Phred Phungus wrote:
>>>
>>> I don't post to be told that I'm putting forth no effort. Why
>>> don't you tell me what I didn't read today,
>>
>> One of W. Richard Stevens Unix programming books? They will give
>> you the background to make better sense of man pages and other
>> documentation.
>
> It arrived today. It looks great:
>
> http://www.apuebook.com/
>
> $ ls *

Why?

<snip list of files from the book's source code>
The book's source code is available online at the link you posted.

--
Ben.
From: Phred Phungus on
Ben Bacarisse wrote:
> Phred Phungus <Phred(a)example.invalid> writes:
>
>> Ian Collins wrote:
>>> Phred Phungus wrote:
>>>> I don't post to be told that I'm putting forth no effort. Why
>>>> don't you tell me what I didn't read today,
>>> One of W. Richard Stevens Unix programming books? They will give
>>> you the background to make better sense of man pages and other
>>> documentation.
>> It arrived today. It looks great:
>>
>> http://www.apuebook.com/
>>
>> $ ls *
>
> Why?
>
> <snip list of files from the book's source code>
> The book's source code is available online at the link you posted.
>

To have the source available without a million keystrokes is huge. I'm
trying to get it set up, but I think I'm having problems with the
include directive:


$ gcc -D_GNU_SOURCE -std=c99 -Iinclude -Wall -Wextra fig1.10.1.c -o out
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
$ gcc -D_GNU_SOURCE -std=c99 -Iinclude -Wall -Wextra fig1.10.1.c -o out
fig1.10.1.c:38: warning: unused parameter �signo�
/tmp/ccCJrJLK.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
$ cat fig1.10.1.c
#include "apue.h"
#include <sys/wait.h>

static void sig_int(int); /* our signal-catching function */

int
main(void)
{
char buf[MAXLINE]; /* from apue.h */
pid_t pid;
int status;

if (signal(SIGINT, sig_int) == SIG_ERR)
err_sys("signal error");

printf("%% "); /* print prompt (printf requires %% to print %) */
while (fgets(buf, MAXLINE, stdin) != NULL) {
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = 0; /* replace newline with null */

if ((pid = fork()) < 0) {
err_sys("fork error");
} else if (pid == 0) { /* child */
execlp(buf, buf, (char *)0);
err_ret("couldn't execute: %s", buf);
exit(127);
}

/* parent */
if ((pid = waitpid(pid, &status, 0)) < 0)
err_sys("waitpid error");
printf("%% ");
}
exit(0);
}

void
sig_int(int signo)
{
printf("interrupt\n%% ");
}

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

It finds apue.h in the include subdirectory.

So /usr/include/sys has a wait.h:



$ ls
acct.h inotify.h personality.h sendfile.h sysinfo.h
ultrasound.h
bitypes.h ioctl.h poll.h shm.h syslog.h un.h
cdefs.h io.h prctl.h signalfd.h sysmacros.h unistd.h
debugreg.h ipc.h procfs.h signal.h termios.h user.h
dir.h kdaemon.h profil.h socket.h timeb.h ustat.h
elf.h kd.h ptrace.h socketvar.h time.h utsname.h
epoll.h klog.h queue.h soundcard.h timerfd.h vfs.h
errno.h mman.h quota.h statfs.h times.h vlimit.h
eventfd.h mount.h raw.h stat.h timex.h vm86.h
fcntl.h msg.h reboot.h statvfs.h ttychars.h vt.h
file.h mtio.h reg.h stropts.h ttydefaults.h vtimes.h
fsuid.h param.h resource.h swap.h types.h wait.h
gmon.h pci.h select.h syscall.h ucontext.h xattr.h
gmon_out.h perm.h sem.h sysctl.h uio.h
$ less wait.h
$ man err_sys
No manual entry for err_sys
$

.... and there's no man page for err_sys nor an entry in susv3.

What gives?
--
fred
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