Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7737323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:58:00+00:00 2026-06-01T07:58:00+00:00

I am reading APUE (Stevens’ Advanced Programming in the UNIX Environment ), so there

  • 0

I am reading APUE (Stevens’ “Advanced Programming in the UNIX Environment“), so there is a file “apue.h” which includes some self-definition function declared. I write a file named “wait.c” which defines functions WAIT_CHILD, WAIT_PARENT declared in “apue.h”, and 14.6.c is the main function.

tmp/cciYhMd7.o: In function `err_ret':
14.6.c:(.text+0x0): multiple definition of `err_ret'
/tmp/ccO4WyJS.o:wait.c:(.text+0x0): first defined here

err_ret is just used not defined, so what’s the problem??

wait.c

#include "apue.h"

static volatile sig_atomic_t sigflag;
static sigset_t newmask, oldmask, zeromask;

static void
sig_usr(int signo)
{
    sigflag = 1;
}

void
TELL_WAIT(void)
{
    if(signal(SIGUSR1, sig_usr) == SIG_ERR)
      err_sys("signal(SIGUSR1) error");
    if(signal(SIGUSR2, sig_usr) == SIG_ERR)
      err_sys("signal(SIGUSR2) error");

    sigemptyset(&zeromask);
    sigemptyset(&newmask);

    sigaddset(&newmask, SIGUSR1);
    sigaddset(&newmask, SIGUSR2);

    if(sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
      err_sys("SIG_BLOCK error");
}

void
TELL_PARENT(pid_t pid)
{
    kill(pid, SIGUSR2);
}

void
WAIT_PARENT(void)
{
    while(sigflag == 0)
      sigsuspend(&zeromask);
    sigflag = 0;

    if(sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
      err_sys("SIG_SETMASK error");
}

void
TELL_CHILD(pid_t pid)
{
    kill(pid, SIGUSR2);
}

void
WAIT_CHILD(void)
{
    while(sigflag == 0)
      sigsuspend(&zeromask);
    sigflag = 0;

    if(sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
      err_sys("SIG_SETMASK error");
}

The code above is my “wait.c” source file. I just use err_sys. Below is the linking command line and the linker error messages I’m getting:

$ gcc -o a.out wait.c 14.6.c
/tmp/ccZ5F3Pn.o: In function `err_ret':
14.6.c:(.text+0x0): multiple definition of `err_ret'
/tmp/cc5EXGbf.o:wait.c:(.text+0x0): first defined here
/tmp/ccZ5F3Pn.o: In function `err_sys':
14.6.c:(.text+0x38): multiple definition of `err_sys'
/tmp/cc5EXGbf.o:wait.c:(.text+0x38): first defined here
/tmp/ccZ5F3Pn.o: In function `err_exit':
14.6.c:(.text+0x76): multiple definition of `err_exit'
/tmp/cc5EXGbf.o:wait.c:(.text+0x76): first defined here
/tmp/ccZ5F3Pn.o: In function `err_dump':
14.6.c:(.text+0xaf): multiple definition of `err_dump'
/tmp/cc5EXGbf.o:wait.c:(.text+0xaf): first defined here
/tmp/ccZ5F3Pn.o: In function `err_msg':
14.6.c:(.text+0xe6): multiple definition of `err_msg'
/tmp/cc5EXGbf.o:wait.c:(.text+0xe6): first defined here
/tmp/ccZ5F3Pn.o: In function `err_quit':
14.6.c:(.text+0x116): multiple definition of `err_quit'
/tmp/cc5EXGbf.o:wait.c:(.text+0x116): first defined here
/tmp/ccZ5F3Pn.o: In function `TELL_WAIT':
14.6.c:(.text+0x5fe): multiple definition of `TELL_WAIT'
/tmp/cc5EXGbf.o:wait.c:(.text+0x272): first defined here
/tmp/ccZ5F3Pn.o: In function `TELL_CHILD':
14.6.c:(.text+0x72e): multiple definition of `TELL_CHILD'
/tmp/cc5EXGbf.o:wait.c:(.text+0x3a2): first defined here
/tmp/ccZ5F3Pn.o: In function `WAIT_PARENT':
14.6.c:(.text+0x6d8): multiple definition of `WAIT_PARENT'
/tmp/cc5EXGbf.o:wait.c:(.text+0x34c): first defined here
/tmp/ccZ5F3Pn.o: In function `TELL_PARENT':
14.6.c:(.text+0x6bd): multiple definition of `TELL_PARENT'
/tmp/cc5EXGbf.o:wait.c:(.text+0x331): first defined here
/tmp/ccZ5F3Pn.o: In function `WAIT_CHILD':
14.6.c:(.text+0x749): multiple definition of `WAIT_CHILD'
/tmp/cc5EXGbf.o:wait.c:(.text+0x3bd): first defined here
collect2: ld returned 1 exit status
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:58:01+00:00Added an answer on June 1, 2026 at 7:58 am

    The source from the APUE book’s web site has these three declarations (amongst many others) in apue.h:

    void    err_ret(const char *, ...);
    
    void    WAIT_PARENT(void);
    void    WAIT_CHILD(void);
    

    Judging from the error message from your compiler, not only is err_ret() defined, it is in fact defined twice, once in your source file wait.c and once in your source file 14.6.c. You will need to decide which (if either) of those definitions is correct, and remove the other, or decide that you can’t use the code in wait.c with your program in 14.6.c. It might be better still to put err_ret() and friends into their own source file. In the source, the err_*() functions are in lib/error.c.


    I didn’t redefine the functions err_*(), so I think I use the lib/error.c source file. And in apue.h there’s:

    #ifndef _APUE_H
    #define _APUE_H
    

    so I think it won’t defined twice.

    If your TU (translation unit) does #include "lib/error.c", then your TU is defining the functions. The C compiler sees the source code containing your source plus the headers you include plus (hypothetically) the code in lib/error.c. You simply shouldn’t be including that source file; you should compile it separately and link the object file into your program. The apue.h header declares the err_*() functions so you can use them in your code. You are expected to compile lib/error.c separately and link it with your wait.o and 14.6.o files.

    It is crucial to understand the difference between defining a variable or function (actually allocating the storage for it) and declaring a variable or function (telling the compiler that the function or variable exists, but that it is not defined here — as in ‘this declaration does not define it’, even if the next line in the source file does define it). Headers should provide declarations and should not provide definitions (most of the time — it’s a good enough rule for now, until you know enough to know when and how to break the rule).


    But what I do is just #include "apue.h" when I write my source file. I don’t quite understand how to separately compile lib/error.c.

    So, it sounds like you need three source files in your compile and link line:

    gcc -o 14.6 14.6.c wait.c lib/error.c
    

    Or you might do it in separate operations:

    gcc -c 14.6.c
    gcc -c wait.c
    gcc -c lib/error.c -o error.o
    gcc -o 14.6 14.6.o wait.o error.o
    

    You might need extra compiler flags (-I or -D options for example), or extra libraries and linker options (-llib and -L /directory/lib options, for example).

    If your source files 14.6.c and wait.c contain #include "apue.h" and do not include other source files (so no #include "lib/error.c" or anything similar — and 14.6.c does not include your wait.c nor vice versa), then you should not run into problems.

    However, you are running into problems, and we can’t see your source or your linking command, which means we have to try and guess what you’ve done wrong. We can devise all sorts of outlandish examples of what you might be doing, but we’re most likely to be wrong.

    So, keeping the code to a minimum, show us which files you are compiling and how you are compiling them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

a strange idea comes to me when I'm reading APUE(Advanced Programming in UNIX Environment).
Reading some questions here on SO about conversion operators and constructors got me thinking
Reading some posts from Jimmy Boggard and wondering - how exactly is it possible
Reading Java Concurrency In Practice, there's this part in section 3.5: public Holder holder;
Reading through some of the questions here, the general concensus seems to be that
Reading source code of my current project, I see: [self retain] in one class,
Reading over some example Objective C code just now. @property (nonatomic, strong) IBOutlet UILabel
Reading through this question on multi-threaded javascript, I was wondering if there would be
reading the SCJP book, I've found something like this in the chapter 1 self-test
Reading some related questions made me think about the theoretical nature of HTML. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.