×

C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

Error - undefined reference to 'pthread_create' with C program in GCC Linux

Fixing undefined reference to 'pthread_create' in Linux

This is a common error while compiling C program in GCC/G++ Linux. This error occurs when you are using pthread_create function to create threads in your programs.

To fix this problem ensure following points

  • Include header file pthread.h in your program.
  • Add –lpthread linker flag with compilation command.

1- Include Header file

    #include <stdio.h>
    #include <pthread.h>
    ...
    ...

2- Compile command

    gcc  main.c -o main -lpthread

To more explanation : C program with pthread.h library in Linux.



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.