ingowald / cudaKDTree

189 stars 12 forks source link

Problem Adding Library to CMake project #24

Open nico-mayora opened 20 hours ago

nico-mayora commented 20 hours ago

Hi, we've been making an OptiX path tracer with photon mapping for a university project. Using CMake for building and CLion for writing our code, we've decided to use this library for storing and retrieving the photons (thanks for developing this, and OWL, very helpful!).

We've been able to succesfully build and run the tests for this library stand-alone. However, when adding it to our existing codebase and running it all, it fails miserably, printing out errors like these:

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\cmath(38): error: the global scope has no "acosf"
      return :: acosf(_Xx);
                ^

(there's hundreds of lines like these).

This is preceded by a call to nvcc.exe, so my theory is that nvcc is attempting to complile C++ code for MSVC's implementation for some reason, and running into problems.

We've been trying everything we've come up with to fix this issue, but to no avail. We'd be very grateful if you could lend a hand coming up with a solution. The code in question is in https://github.com/nico-mayora/photon-mapping. To attempt to add CudaKDTree, we've done the exact same as with OWL in CMakeLists.txt. In addition, we included a include_directories(${cudakdtree_dir}/cukd) to be able to see the header files. If you need more information I'd be happy to provide it.

ingowald commented 10 hours ago

Hey - thanks for reporting this, I'll have a look. I"m more of a linux user, so not an expert in VS, but I can reproduce that on another machine when i get home. First guess is that it's some missing include of "math.h" - when I look at cmath it seems to have "acos(double)", but maybe(?) not "acosf(float)" ... but i'll have to have a look to be sure.

ingowald commented 9 hours ago

Could you check if you have c++-11 enabled?

According to cppreference (https://en.cppreference.com/w/cpp/numeric/math/acos) the float version of acos (acosf) is only in cmath since c++-11. Kind-of ridiculous if cmath is supposed to replace math.h (in which cosf exists since before dinosaurs roamed the earth), but hey .... if that's what cppreference says it's worth checking.

nico-mayora commented 9 hours ago

We were using C++17 features so I think we we're sorted in that aspect. FWIW I added set_property(TARGET rayTracer PROPERTY CXX_STANDARD 17) to our CMakeLists.txt just in case, but the issue persists. For replicating the problem you can refer to https://github.com/nico-mayora/photon-mapping/tree/kdtree. Thanks for your swift response.