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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:15:44+00:00 2026-06-13T23:15:44+00:00

In my main() method in one source file, I have a call to pthread_create(),

  • 0

In my main() method in one source file, I have a call to pthread_create(), as follows:

pthread_t pth_chanrecv;
pthread_create(&pth_chanrecv, NULL, chanrecv_run, NULL);

“chanrecv_run” is a function in another source file that I have written.
This is the function prototype:

void *chanrecv_run(void *arg);

The function prototype is in a header file which I have included in the source file containing the main() method.

I’m compiling my program with the following statement:

gcc -lpthread -o bin/main2 src/main2.c

The chanrecv_run() function is in a file named “chanrecv.c”, also in the src folder.

Every time I try and compile it, I get the following error:

/tmp/ccHxRSTk.o: In function `main':
main2.c:(.text+0x256): undefined reference to `chanrecv_run'
collect2: ld returned 1 exit status

I have no idea what’s going wrong. I’ve scoured the web trying to find another instance of someone trying to call a function that was in another file with the pthread_create function and come up completely blank. Is this even possible, and if so, how?

  • 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-13T23:15:45+00:00Added an answer on June 13, 2026 at 11:15 pm

    The issue isn’t pthreads related. Since you’ve not linked your second .c file containing the chanrecv_run function the linker is moaning.

    You need:

    gcc -lpthread -o bin/main2 src/main2.c src/file_with_chanrecv_run_in.c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since at least D2007 a project file can have a main source file with
One of the main signifficant features of Corba is AMI (Asyncronous Method Invocation) in
I have 2 Classes. GUI (with main method in it) Parser (this reads files(csv),
I have 2 classes within same package. Both classes have main method in them.
I have a program that needs to move a file from one directory to
I have a java project with class having main method in package com.nik.mypackage. Only
I have a java code for copy file from one folder to another folder.
My main method: public static void main(String[] args) { Scanner input = new Scanner(System.in);
I am using jdk 1.6 My main method : exmp3<String , Integer> exmp3 =
I want to invoke the main method which is static. I got the object

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.