ouster-lidar / ouster-sdk

Ouster, Inc. sample code
Other
468 stars 439 forks source link

Unable to build the sdk (C++) in Windows #610

Open hirenpatel1207 opened 2 months ago

hirenpatel1207 commented 2 months ago

Describe your question Building the sdk from source from C++ throws error in compilation.

Screenshots Screenshot 2024-09-03 142837

Platform (please complete the following information):

Goal: Use the C++ sdk to build an application in Windows to capture and store the Lidar data (without using ros2). I followed the instructions given at https://static.ouster.dev/sdk-docs/cpp/building.html . In the last step it is metioned to open https://github.com/ouster-lidar/ouster-sdk/archive/refs/tags/20240703.zip in Visual studio and build the project. But I am getting errors linkage errors. Is it possible to get prebuilt binaries for Windows platform?

Samahu commented 2 months ago

Hi @hirenpatel1207, can you try to see if this branch helps you build on Windows https://github.com/ouster-lidar/ouster-sdk/pull/608

matthew-lidar commented 2 months ago

The changes in the PR above were merged into master, so if you use: https://codeload.github.com/ouster-lidar/ouster-sdk/zip/refs/heads/master it should work.

hirenpatel1207 commented 2 months ago

@matthew-lidar I was able to build the master branch. Thanks. However the build directly generates the example executables. image By that way, I would have to import the ouster-sdk source code into my project and then build it together, which is not a great idea for versioning and keeping sdk's seperate. Is it possible to pre-built the sdk seperately and generate the .h, .lib and .dll s and then use them?

matthew-lidar commented 2 months ago

Usually what one would do is build the CMake package, then install it using a command like so run from your build directory:

cmake --install . --config x64-Release

If you used Visual studio, there's probably also a way to trigger this, but I was unable to find documentation saying specifically how.

This will copy the .h .lib and .dll files to a central directory and enable other CMake projects, such as your's to find_package it.

Then do something like the following in your project's CMake and it will automatically find and include those files:

project(your_project)
cmake_minimum_required(VERSION 3.10)

find_package(OusterSDK REQUIRED)

add_executable(your_project main.cpp)
target_link_libraries(your_project OusterSDK::ouster_client)
set_property(TARGET your_project PROPERTY CXX_STANDARD 14)
hirenpatel1207 commented 2 months ago

Do you mean this option in VS? Screenshot 2024-09-09 120218 install.zip

With that option, I was able to generate the header files and ouster_client.lib, ouster_osf.lib, ouster_pcap.lib, and ouster_viz.lib files (see the attached install.zip folder). But there are no dlls. Also I tried to use these header and .lib files in a QT project .pro file but I am getting the following error: image I think something related to networking stuff is not getting generated in the install step.

hirenpatel1207 commented 2 months ago

Do you mean this option in VS? Screenshot 2024-09-09 120218 install.zip

With that option, I was able to generate the header files and ouster_client.lib, ouster_osf.lib, ouster_pcap.lib, and ouster_viz.lib files (see the attached install.zip folder). But there are no dlls. Also I tried to use these header and .lib files in a QT project .pro file but I am getting the following error: image I think something related to networking stuff is not getting generated in the install step.

EDIT: I was able to solve the problem by including "-lws2_32". The build is successfull. But during runtime, i am getting "write access violation", I think it has something to do with the spdlog. The program crashes at line-> ouster::sensor::init_logger("info"); Here is the minimalistic example that I am trying: image

matthew-lidar commented 2 months ago

Yeah, that looks to have done it. Currently the SDK is only built statically, so you will not find any .dlls generated, only .libs.

As for the crash, do you have the full stacktrace?

hirenpatel1207 commented 2 months ago

Got it. My "Hello World" sample program runs now. I had linked wrong .libs from vcpkg. Thanks for the help.

hirenpatel1207 commented 2 months ago

Sorry for going back and forth on opening this issue as I was not sure on whether to open a new issue or keep this one. The build is successfully but the release library version has some problem I think. For e.g. if i run the client_example.exe of the debug version, it works fine. But the same client_example.exe of release version does not work. The method sensor::poll_client(*handle); returns value "0". What does Timed-out state actually mean?

matthew-lidar commented 2 months ago

On Windows you need to make sure you link debug builds of your program with debug builds of the SDK (and release builds with release builds) for things to work correctly generally. I would check to make sure that is occurring.

Timeout means that no packets were received in the timeout provided to the poll_client function. The default is 1 second.

hirenpatel1207 commented 2 months ago

Yes, I was getting problems with my programs during the release build. Then I had gone back to check if the release version demos work or not. I have tried the demos with no modifications. I had just followed the guide line in the docs to build the package. I had checkout vcpkg 2024.04.26(git checkout 2024.04.26) so that correct libraray versions are linked.