Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to `pthread_create' CLion

Tags:

linux

cmake

clion

I'm trying to compile my program using CLion under Linux (Ubuntu) OS.

My CMake file:

# cmake_minimum_required(VERSION 3.5)
  project(untitled2 C)

  set(CMAKE_C_STANDARD 99)
  set(CMAKE_CXX_FLAGS -pthread)
  add_executable(untitled2 main.c)

My pragram using threads so I've added set(CMAKE_CXX_FLAGS -pthread) that required to compile my program. I got a compilation error: "undefined reference to pthread_create"

I can compile the program via the terminal using the following:

gcc main.c -o main -pthread

I think that my issue is with the CMake file. Can someone please help my with that matter ?

Thank you!

like image 551
Ido Segal Avatar asked Dec 15 '18 17:12

Ido Segal


Video Answer


1 Answers

You have to change set(CMAKE_CXX_FLAGS -pthread) in set(CMAKE_C_FLAGS -pthread), because CXX stay for C++. Hope this will help you.

like image 172
gianluca gabriele Avatar answered Oct 29 '22 23:10

gianluca gabriele