xtensor-stack / xtensor

C++ tensors with broadcasting and lazy computing
BSD 3-Clause "New" or "Revised" License
3.31k stars 392 forks source link

OpenMP::OpenMP_CXX_xtensor not found #2437

Open WenyinWei opened 2 years ago

WenyinWei commented 2 years ago

Platform: Windows xtensor: 0.23.10

Hi all, I have met some trouble when I use xtensor from my own code by target_link_libraries, could anybody tell me how to do it in the right way? I turned on XTENSOR_USE_OPENMP option when I cmake xtensor, it shall be linked when I cmake my library by targte_include_directory and target_link_libraries.

find_package(xtensor REQUIRED)
target_link_libraries(test_io PUBLIC xtensor xtensor-io)
CMake Error at test/CMakeLists.txt:9 (add_executable):
  Target "test_flt" links to target "OpenMP::OpenMP_CXX_xtensor" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?

It doesn't help for me to add OpenMP::OpenMP_CXX_xtensor in the lib list of target_link_libraries. The same CMakeLists works fine on Ubuntu with clang 13.0.

tdegeus commented 2 years ago

I don't think that we provide or ask any target OpenMP::OpenMP_CXX_xtensor. I see it being used here https://github.com/xtensor-stack/xtensor/blob/fe81957365ce7eb56ea417bea95476c1344d7c31/CMakeLists.txt#L83-L110 but I think that that is only for testing of xtensor.

My guess is that you are placing xtensor as a subfolder of your package, and I don't think that the CMake support was designed for it. Rather, I think that you should install xtensor

WenyinWei commented 2 years ago

Thank you for your prompt reply on the issue. I didn't put xtensor as a subpackage yet indeed, but installed it. let me try some more commands on linking xtensor.

tdegeus commented 2 years ago

Hi @WenyinWei . Your reply confuses me, if you installed it (using CMake or conda) I don't see for the moment how you could be faced with OpenMP::OpenMP_CXX_xtensor ?

WenyinWei commented 2 years ago

Yes! I am also pretty confused. How can I meet the error even after I have cmaked 'xtensor' and installed it by building INSTALL target in visual studio. Let me check once again when tomorrow I go back to my office desktop.

WenyinWei commented 2 years ago

I made sure that I did meet the trouble with the env:

As long as I wanna taget_link_libraries with xtensor, VS would tell me the error LNK110 that it fails opening OpenMP::OpenMP_CXX_xtensor.lib. The trouble could be avoided by XTENSOR_USE_OPENMP OFF brute-forcedly.

alexanderustinov commented 2 years ago

@tdegeus There is another mention of OpenMP::OpenMP_CXX_xtensor in https://github.com/xtensor-stack/xtensor/blob/fe81957365ce7eb56ea417bea95476c1344d7c31/CMakeLists.txt#L240-L243 Should it be removed?

ccoulombe commented 2 months ago

Hitting this as well when enabling XTENSOR to use OpenMP in v0.25. Could this be addressed @tdegeus ?