Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to compile #1

Open
kneardhead opened this issue Feb 14, 2023 · 3 comments
Open

Fails to compile #1

kneardhead opened this issue Feb 14, 2023 · 3 comments

Comments

@kneardhead
Copy link

I am beginner and I tried to compile it using the cmake .. and I get a pthread error.

CMake Error at cmake/sdl2/FindSDL2.cmake:243 (message):
  Could NOT find Threads (Threads is required by SDL2).
Call Stack (most recent call first):
  CMakeLists.txt:51 (find_package)

And the CMakeOutput.log is,

Determining if the include file pthread.h exists passed with the following output:
Change Dir: /home/zabit/Documents/study/code-learn/sdl-lazy-foo/sdl2-pointerless/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_8ee73/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_8ee73.dir/build.make CMakeFiles/cmTC_8ee73.dir/build
gmake[1]: Entering directory '/home/zabit/Documents/study/code-learn/sdl-lazy-foo/sdl2-pointerless/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_8ee73.dir/CheckIncludeFile.c.o
/usr/bin/cc    -o CMakeFiles/cmTC_8ee73.dir/CheckIncludeFile.c.o -c /home/zabit/Documents/study/code-learn/sdl-lazy-foo/sdl2-pointerless/build/CMakeFiles/CMakeTmp/CheckIncludeFile.c
Linking C executable cmTC_8ee73
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_8ee73.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/cmTC_8ee73.dir/CheckIncludeFile.c.o -o cmTC_8ee73
gmake[1]: Leaving directory '/home/zabit/Documents/study/code-learn/sdl-lazy-foo/sdl2-pointerless/build/CMakeFiles/CMakeTmp'



Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD succeeded with the following output:
Change Dir: /home/zabit/Documents/study/code-learn/sdl-lazy-foo/sdl2-pointerless/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_58b33/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_58b33.dir/build.make CMakeFiles/cmTC_58b33.dir/build
gmake[1]: Entering directory '/home/zabit/Documents/study/code-learn/sdl-lazy-foo/sdl2-pointerless/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_58b33.dir/src.c.o
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD   -o CMakeFiles/cmTC_58b33.dir/src.c.o -c /home/zabit/Documents/study/code-learn/sdl-lazy-foo/sdl2-pointerless/build/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_58b33
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_58b33.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/cmTC_58b33.dir/src.c.o -o cmTC_58b33
gmake[1]: Leaving directory '/home/zabit/Documents/study/code-learn/sdl-lazy-foo/sdl2-pointerless/build/CMakeFiles/CMakeTmp'


Source file was:
#include <pthread.h>

static void* test_func(void* data)
{
  return data;
}

int main(void)
{
  pthread_t thread;
  pthread_create(&thread, NULL, test_func, NULL);
  pthread_detach(thread);
  pthread_cancel(thread);
  pthread_join(thread, NULL);
  pthread_atfork(NULL, NULL, NULL);
  pthread_exit(NULL);

  return 0;
}

I have downloaded the required dependencies.

@kneardhead
Copy link
Author

And yes, I am using Ubuntu 22.04 LTS (if that's necessary)

@ghost
Copy link

ghost commented Jun 14, 2023

if you cannot compile src/main.c using gcc then try to simply use g++ due main.c is actually contain c++ specific code

@ej159
Copy link

ej159 commented Dec 21, 2023

I changed the Threads dependency checking in FindSDL2.cmake to this code and it compiles, though I don't know if this causes bugs in other systems:

if(NOT APPLE)
  set(CMAKE_THREAD_PREFER_PTHREAD ON)
  find_package(Threads QUIET)
  if(CMAKE_USE_PTHREADS_INIT)
    set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-pthread")
  elseif(NOT CMAKE_THREAD_LIBS_INIT)
    set(SDL2_THREADS_NOT_FOUND "Could NOT find Threads (Threads is required by SDL2).")
    if(SDL2_FIND_REQUIRED)
      message(FATAL_ERROR ${SDL2_THREADS_NOT_FOUND})
    else()
        if(NOT SDL2_FIND_QUIETLY)
          message(STATUS ${SDL2_THREADS_NOT_FOUND})
        endif()
      return()
    endif()
    unset(SDL2_THREADS_NOT_FOUND)
  endif()
endif()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants