ericw-tools icon indicating copy to clipboard operation
ericw-tools copied to clipboard

master-branch compile issue on elementary (Ubuntu variant) -- FindTBB.cmake

Open neogeographica opened this issue 4 years ago • 7 comments

I don't think this is specific to elementary, but FWIW this is happening on elementary 5.1.2 which is based on Ubuntu 18.04.4 LTS.

I've successfully built an older version of things here before. (Sorry my comment here originally mentioned wxWidgets, my brain is scrambling this with my separate look at compiling TB.)

On current master branch however the compile process fails like this:

joel@lazarus:~/Source/ericw-tools/build$ cmake .. -DCMAKE_BUILD_TYPE=Release -Dembree_DIR="$(pwd)/embree-2.17.5.x86_64.linux"
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
CMake Error at CMakeLists.txt:125 (find_package):
  By not providing "FindTBB.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "TBB", but
  CMake did not find one.

  Could not find a package configuration file provided by "TBB" with any of
  the following names:

    TBBConfig.cmake
    tbb-config.cmake

  Add the installation prefix of "TBB" to CMAKE_PREFIX_PATH or set "TBB_DIR"
  to a directory containing one of the above files.  If "TBB" provides a
  separate development package or SDK, be sure it has been installed.


-- Configuring incomplete, errors occurred!
See also "/home/joel/Source/ericw-tools/build/CMakeFiles/CMakeOutput.log".
See also "/home/joel/Source/ericw-tools/build/CMakeFiles/CMakeError.log".

I'm not enough of a CMake guru to 100% know what's going on here, but here's what I found.

My /usr/share/cmake-3.10/Modules directory does not include any FindTBB.cmake file, and it doesn't look like any vanilla version of cmake comes with that file.

There are several versions of FindTBB.cmake around the net as part of various projects that use TBB. Some look like they set up the variables/targets needed by this compile, and some don't. I tried (apparently successfully) to use this one FWIW: https://raw.githubusercontent.com/Kitware/VTK/master/CMake/FindTBB.cmake

I dropped that file into the main ericw-tools directory, and then modified CMakeLists.txt to add this line before it tries to find TBB: list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR})

I don't really know if that's the right thing to do, but it did make the compile succeed, so maybe it's a data point.

neogeographica avatar Apr 04 '20 23:04 neogeographica

I tried using instructions from readme on Arch Linux and it worked, with embree-2.17.5 and embree-2.17.7. But on my other device with Ubuntu 16.04 I also encountered the issue. So maybe its some libraries being too old? I'm not sure but i don't have the resources to test on Ubuntu 20.04.

micwoj92 avatar Jun 01 '20 05:06 micwoj92

Hmm!

On Arch, can you see where your FindTBB.cmake file is, and what package it came from?

neogeographica avatar Jun 01 '20 05:06 neogeographica

Sorry it's a bit of a mess that I use TBB - not sure if it's worth keeping long term - because embree also depends on it (at least, their precompiled binaries do - I think if you build embree from source it's optional).

Probably the best bet if you just want to compile on your system is to get the exact binaries of TBB and embree that I use in the CI script: https://github.com/ericwa/ericw-tools/blob/master/build-linux-64.sh

ericwa avatar Jun 01 '20 06:06 ericwa

I have no idea where that file is, but it is most definitely intel-tbb package, without it get same error, you can find which files does it provide here if you click on "View the file list for intel-tbb" https://www.archlinux.org/packages/extra/x86_64/intel-tbb/

micwoj92 avatar Jun 01 '20 08:06 micwoj92

@neogeographica package "libtbb-dev" seems to provide similiar file but its only on ubuntu eoan, focal and groovy. https://packages.ubuntu.com/search?suite=eoan&arch=any&mode=filename&searchon=contents&keywords=TBBConfig But I did test that 'build-linux-64.sh' script and it works on my 16.04 machine. So maybe the temporary workaround is to point users to use that script?

micwoj92 avatar Jun 01 '20 08:06 micwoj92

I just encountered this same error on Slackware Current. This is in CMakeError.log:

Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /home/alexa/src/ericw-tools/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/gmake cmTC_5ede4/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_5ede4.dir/build.make CMakeFiles/cmTC_5ede4.dir/build
gmake[1]: Entering directory '/home/alexa/src/ericw-tools/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_5ede4.dir/src.c.o
/usr/bin/cc   -O2 -fPIC -DCMAKE_HAVE_LIBC_PTHREAD -o CMakeFiles/cmTC_5ede4.dir/src.c.o -c /home/alexa/src/ericw-tools/build/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_5ede4
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_5ede4.dir/link.txt --verbose=1
/usr/bin/cc -O2 -fPIC -DCMAKE_HAVE_LIBC_PTHREAD -rdynamic CMakeFiles/cmTC_5ede4.dir/src.c.o -o cmTC_5ede4 
/usr/bin/ld: CMakeFiles/cmTC_5ede4.dir/src.c.o: in function `main':
src.c:(.text.startup+0x15): undefined reference to `pthread_create'
/usr/bin/ld: src.c:(.text.startup+0x1f): undefined reference to `pthread_detach'
/usr/bin/ld: src.c:(.text.startup+0x29): undefined reference to `pthread_cancel'
/usr/bin/ld: src.c:(.text.startup+0x35): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
gmake[1]: *** [CMakeFiles/cmTC_5ede4.dir/build.make:106: cmTC_5ede4] Error 1
gmake[1]: Leaving directory '/home/alexa/src/ericw-tools/build/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:140: cmTC_5ede4/fast] Error 2


Source file was:
#include <pthread.h>

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;
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/alexa/src/ericw-tools/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/gmake cmTC_11540/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_11540.dir/build.make CMakeFiles/cmTC_11540.dir/build
gmake[1]: Entering directory '/home/alexa/src/ericw-tools/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_11540.dir/CheckFunctionExists.c.o
/usr/bin/cc   -O2 -fPIC -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_11540.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.18/Modules/CheckFunctionExists.c
Linking C executable cmTC_11540
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_11540.dir/link.txt --verbose=1
/usr/bin/cc -O2 -fPIC -DCHECK_FUNCTION_EXISTS=pthread_create -rdynamic CMakeFiles/cmTC_11540.dir/CheckFunctionExists.c.o -o cmTC_11540  -lpthreads 
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
gmake[1]: *** [CMakeFiles/cmTC_11540.dir/build.make:106: cmTC_11540] Error 1
gmake[1]: Leaving directory '/home/alexa/src/ericw-tools/build/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:140: cmTC_11540/fast] Error 2

I noticed that it's trying to use -lpthreads (which always fails when I run GCC by hand) instead of -lpthread (which always works).

BUT.... if I manually grab a copy of TBB instead of using the one supplied by my package manager, it works. I have a shell script to build everything on another machine that does this. Relavent snippit:

wget https://github.com/intel/tbb/releases/download/2017_U7/tbb2017_20170604oss_lin.tgz -O tbb.tgz
tar xf tbb.tgz
cmake .. \
    -DCMAKE_C_FLAGS="-O2 -march=native -mtune=native -fPIC" \
    -DCMAKE_CXX_FLAGS="-O2 -march=native -mtune=native -fPIC" \
    -Dembree_DIR="$(pwd)/embree-2.17.7.x86_64.linux" \
    -DTBB_DIR="$(pwd)/tbb2017_20170604oss/cmake" \
    -DCMAKE_BUILD_TYPE="Release"
make -j9

MistressRemilia avatar Jul 30 '20 01:07 MistressRemilia

I believe the lpthread error in that log is to be expected as it probes what works and what doesn't. The TBB thing was the actual showstopper.

joel-bluedata avatar Jul 30 '20 05:07 joel-bluedata