folly icon indicating copy to clipboard operation
folly copied to clipboard

Undefined reference to pthread_create

Open traversc opened this issue 4 years ago • 5 comments
trafficstars

I got the following error when running ./build.sh

I'm on Ubuntu 20 with WSL. GCC 9.3.0

Another person posted the same issue earlier, but closed it: https://github.com/facebook/folly/issues/1377

How do I fix it?

Determining if the pthread_create exist failed with the following output:
Change Dir: /tmp/fbcode_builder_getdeps-ZhomeZtchingZDownloadsZfollyZbuildZfbcode_builder/build/folly/CMakeFiles/CMakeTmp

Run Build Command(s):/tmp/fbcode_builder_getdeps-ZhomeZtchingZDownloadsZfollyZbuildZfbcode_builder/installed/ninja-bbPkhaVDuJph3FgUpWo0w7J2R7ybohnLl2-cJn2LsPM/bin/ninja cmTC_0b481
[1/2] Building C object CMakeFiles/cmTC_0b481.dir/CheckSymbolExists.c.o
[2/2] Linking C executable cmTC_0b481
FAILED: cmTC_0b481
: && /usr/bin/cc   -rdynamic CMakeFiles/cmTC_0b481.dir/CheckSymbolExists.c.o  -o cmTC_0b481   && :
/usr/bin/ld: CMakeFiles/cmTC_0b481.dir/CheckSymbolExists.c.o: in function `main':
CheckSymbolExists.c:(.text+0x1f): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

File /tmp/fbcode_builder_getdeps-ZhomeZtchingZDownloadsZfollyZbuildZfbcode_builder/build/folly/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef pthread_create
  return ((int*)(&pthread_create))[argc];
#else
  (void)argc;
  return 0;
#endif
}

traversc avatar Aug 13 '21 16:08 traversc

My business account Global network

rangelsfr avatar Aug 15 '21 10:08 rangelsfr

Hi, I'm not sure but it could be that a link to the pthread library (-lpthread) is missing at linking time. By adding "-v" to the compiler options it should be possible to check if that is the case.

ChristopherBignamini avatar Oct 13 '21 08:10 ChristopherBignamini

This affects me also. So what is the decision on how to change libfolly regarding this issue?

dimalit avatar Mar 04 '22 13:03 dimalit

Focus on cmake error before this, which told me that Openssl is dependency and not found, after install openssl this pthread undefined problem resolved.

lushengguo avatar Oct 27 '22 02:10 lushengguo

Before error is can not find openssl so solution is sudo apt install libssl-dev

hyperbolic-c avatar Apr 11 '23 07:04 hyperbolic-c