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 8906087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:33:39+00:00 2026-06-15T02:33:39+00:00

Some one can informe me how to solve this compile error : tarek.c: In

  • 0

Some one can informe me how to solve this compile error :

tarek.c: In function ‘main’:
tarek.c:33: warning: incompatible implicit declaration of built-in function ‘exit’
/tmp/ccAEGS6k.o: In function `main':
tarek.c:(.text+0x45): undefined reference to `pthread_mutexattr_init'
tarek.c:(.text+0x56): undefined reference to `pthread_mutexattr_setpshared'
collect2: ld returned 1 exit status

when i compile this program (Two process shared the same value using critical section) :

#include <sys/types.h>
#include <pthread.h>
#include <sys/mman.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>

int main () {

int stat;

pthread_mutex_t *mutex = (pthread_mutex_t*)mmap (0, sizeof (pthread_mutex_t) + sizeof (long),PROT_READ | PROT_WRITE,
                            MAP_SHARED ,-1, 0);

long *data = (long*)(&mutex[1]); /* map 'data' after mutex */
int pid;

pthread_mutexattr_t attr;
pthread_mutexattr_init (&attr);
pthread_mutexattr_setpshared (&attr, PTHREAD_PROCESS_SHARED);
pthread_mutex_init (mutex, &attr);

*data = 0;

pid = fork ();

pthread_mutex_lock (mutex);
(*data)++;
pthread_mutex_unlock (mutex);

if (!pid) /* child exits */
exit (0);
else
waitpid (pid, &stat, 0);
printf ("data is %ld\n", *data);

}
  • 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-15T02:33:40+00:00Added an answer on June 15, 2026 at 2:33 am

    Explicitly mention -pthread library .

    Do compilation like this:

    gcc -Wall program.c -o program -pthread
    

    It will solve your

    `tarek.c:(.text+0x45): undefined reference to `pthread_mutexattr_init'
    tarek.c:(.text+0x56): undefined reference to `pthread_mutexattr_setpshared'`
    

    For exit() include #include <stdlib.h>

    For waitpid() include #include <sys/wait.h>

    for more man exit() and man waitpid()

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

Sidebar

Related Questions

If some one can point me in the right direction for this code for
Can some one please explain why this loop never 'breaks' and goes on forever
How much some one can modify a javascript to intercept the post parameters to
What are some tips one can keep in mind to speed up jSoup? I
Can some one please tell me why exactly classes were introduced in C++. Are
Can some one clarify the space complexity of Node Relationship and property in the
Can some one recommend any free program which counts the number of clicks Clicked
Can some one please guide me to understand which jar file i need to
Can some one shed some light on the difference between XML and XMI? Can
Can some one tell me how do i display real time in c++. what

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.