OpenKinect / libfreenect2

Open source drivers for the Kinect for Windows v2 device
2.08k stars 752 forks source link

Build: target "Threads::Threads" was not found. #1110

Open oneandonlyoddo opened 4 years ago

oneandonlyoddo commented 4 years ago

I am trying to build libfreenect2 on Windows 10 with Visual Studio 2019 Community Edition. Configuring runs without problems. Then there are lots of CMake warnings like this one:

CMake Warning (dev) at examples/CMakeLists.txt:76 (ADD_EXECUTABLE):
Policy CMP0028 is not set: Double colon in target name means ALIAS or
IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
Use the cmake_policy command to set the policy and suppress this warning.

Target "Protonect" links to target "Threads::Threads" but the target was
not found.  Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

As far as I can tell these warnings come up for every target that lists Threads::Threads.lib in AdditionalDependencies.

Then it starts building but fails at some point due to a link error with Threads:

  -- Generating done
  -- Build files have been written to: C:/libfreenect2/build
  transfer_pool.cpp
  event_loop.cpp
  usb_control.cpp
  allocator.cpp
  frame_listener_impl.cpp
  packet_pipeline.cpp
  rgb_packet_stream_parser.cpp
  rgb_packet_processor.cpp
  depth_packet_stream_parser.cpp
  depth_packet_processor.cpp
  cpu_depth_packet_processor.cpp
  resource.cpp
  command_transaction.cpp
  registration.cpp
  logging.cpp
  libfreenect2.cpp
  tinythread.cpp
  turbo_jpeg_rgb_packet_processor.cpp
  flextGL.cpp
  opengl_depth_packet_processor.cpp
  Generating Code...
  Compiling...
  opencl_depth_packet_processor.cpp
  opencl_kde_depth_packet_processor.cpp
  Generating Code...
LINK : fatal error LNK1104: cannot open file 'Threads::Threads.lib' [C:\libfreenect2\build\freenect2.vcxproj]

Threads::Threads.lib doesn't produce any good Google results for me so I don't understand if I am missing something third party or if it is part of libfreenect2. Any ideas on how I can fix this link?

Edit: After reading this: https://github.com/OpenKinect/libfreenect2/issues/11 I checked the output again and the feature list names tinythread for Threading:

 -- Feature list:
  --   CUDA    yes
  --   CXX11    disabled
  --   Examples    yes
  --   OpenCL    yes
  --   OpenGL    yes
  --   OpenNI2    yes
  --   TegraJPEG    no
  --   Threading    tinythread
  --   TurboJPEG    yes
  --   VAAPI    no
  --   VideoToolbox    no (Apple only)
  --   streamer_recorder    disabled

Edit 2: In the meantime I tried building with VS 2015 instead of 2019 but I am running into the exact same Issue. With VS15 I can enable CXX11 which then lists Threading std::thread but the issue remains. CXX11 support fails with VS19.

oneandonlyoddo commented 4 years ago

I now opened the solution in VS 15 and removed Threads::Threads.lib from the additional dependencies for freenect2, freenect2-openni2 and Protonect. Managed to build and Protonect runs. I'll see if I run into any issues.

Andy-Cheng commented 4 years ago

I encountered the same problem on VS2019.

NicholasNelsonwood commented 4 years ago

Try adding find_package(Threads) to the CMake file, that seems to have worked for me - must be something about when the library is added vs when it is called?

Andy-Cheng commented 4 years ago

Try adding find_package(Threads) to the CMake file, that seems to have worked for me - must be something about when the library is added vs when it is called?

It works! Thanks for saving my time ^^

BTW, just as @NicholasNelsonwood mentioned, I added FIND_PACKAGE(Threads) before INCLUDE(SetupLibfreenect2Threading) in CMakeList.txt.