CesiumGS / cesium-native

Apache License 2.0
414 stars 210 forks source link

Undefined reference to Cesium3DTilesSelection::ViewState::create #925

Closed arkel-77 closed 1 month ago

arkel-77 commented 1 month ago

main.cpp:

#include <Cesium3DTilesSelection/ViewState.h>

int main() {
    auto v = Cesium3DTilesSelection::ViewState::create(glm::dvec3(0), glm::dvec3(1,0,0), glm::dvec3(0,0,1), glm::dvec2(600,600), 90, 90);
    return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.15)

project(cesium-test VERSION 0.1.0 LANGUAGES CXX)

add_executable(main main.cpp)

target_link_libraries(main PUBLIC Cesium3DTilesSelection CesiumGeospatial)

CMake output:

$ cmake -B build -S . && cmake --build build
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /home/arkel/3d-tiles-test/build
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable main
/usr/bin/ld: CMakeFiles/main.dir/main.cpp.o: in function `main':
main.cpp:(.text+0xd4): undefined reference to `Cesium3DTilesSelection::ViewState::create(glm::vec<3, double, (glm::qualifier)0> const&, glm::vec<3, double, (glm::qualifier)0> const&, glm::vec<3, double, (glm::qualifier)0> const&, glm::vec<2, double, (glm::qualifier)0> const&, double, double, CesiumGeospatial::Ellipsoid const&)'
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/main.dir/build.make:97: main] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/main.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2

related: #567

arkel-77 commented 1 month ago

The above occurs when trying to use global shared libraries obtained by building cesium-native with sudo cmake --build build --target install, and does not occur when cesium-native is added as a subdirectory.

kring commented 1 month ago

Hi @arkelley77, we unfortunately have never really built cesium-native dynamically, nor have we tried installing it and then referencing it as a system library. So I don't know what problems you might run into there, or how to solve them. I think that add_subdirectory is probably the best way to use cesium-native for now, though we do welcome reasonable pull requests that make it usable in other ways!

arkel-77 commented 1 month ago

@kring I've figured out some patches to various CMakeLists.txt files throughout the repo that allow for building & installing shared libs instead of using the subdirectory workflow. Tried to push a branch but realized I don't have access to the repo, any chance you could give me just the permissions to make a PR?

kring commented 1 month ago

@arkelley77 the way it's typically done on GitHub is that you fork our repo, push your changes to your fork, and then open a pull request into our repo. You shouldn't need any special permissions to do that. GitHub has some documention on this here: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork

(the earlier topics in the same section may be useful as well)

Let us know if you have any questions.

arkel-77 commented 1 month ago

I figured out how to do it with only cmake flags on the command line. Turns out the original error in this thread is because cesium-native uses the GLM_FORCE_SIZE_T_LENGTH macro by default, which breaks interop with code that doesn't use that macro. I opted to define the macro in my code, but specifying -DCESIUM_GLM_STRICT_ENABLED=OFF when configuring cesium-native would work too.