Has anyone set up a CMakeList.txt to support the build of a stand-alone depthai C++ project?
In other words: to enable a single example application to be built in isolation rather than a full build of the entire depthai-core infrastructure.
Hope that makes sense. Congratulations on a great product.
C++ Development
Hello @mikegardner , I am forwarding this question to our lead firmware dev, as I am not sure.
Thanks Eric.
- Edited
Hi mikegardner
There are a couple of ways of achieving this.
- Build only 1 target -
cmake --build [build/dir] --target rgb_preview
- Integrate into your own project with either
add_subdirectory
orfind_package
calls. Documentation for integration is available here: https://github.com/luxonis/depthai-core#integration. Also seetests/integration
for that kind of usage + there is alsodepthai-core-example
repo showcasing theadd_subdirectory
case.
I presume you want to create your own app and use DepthAI as a dependant library, in that case go for option 2, to cleanly decouple your app and library codebases.
Let me know if that helps,
Martin
themarpe That's great, thanks Martin. I'll give it a try and post back the results later this week.
Yes, ultimately I want to develop an app, but I only got the hardware this week and I'd like to set up a C++ development environment with eclipse / Ubuntu on a laptop, with a view to to cross compiling for the Pi4 as the end goal.
BTW: I did try the depthai-core-example earlier, but all of the link and include paths seemed to be out of line with the latest example code in the depthai-core repo.
Cheers guys, great product.
mikegardner
The depthai-core-example isn't necessarily up to date. For that, update submodule to latest version. You can do that using the following:
cd depthai-core
git checkout main
Great to see cross compiling as part of your workflow - if you'll have any questions around that feel free to reach out.
Thanks for kind words,
Martin
Thanks Martin, I'll give that a try first.
OK, tried the suggestion. First as a sanity check I build the myapp from scratch in a fresh directory, following the instructions in the depthai-core-example. Eveything built fine and executed on an OAK-1 plugged into a laptop with VMWare. I just needed to add the OpenCV source path to the Makefiles,txt
I then tried the above suggestion and got
M shared/depthai-bootloader-shared
M shared/depthai-shared
Previous HEAD position was 230fd52 Added a change to default dependency build type for MSVC
Switched to branch 'main'
Your branch is up-to-date with 'origin/main'.
Then went through the build steps again and got the following error...
[ 13%] Building CXX object depthai-core/CMakeFiles/depthai-core.dir/src/device/Device.cpp.o
In file included from /home/mike/oak/depthai-core-example/depthai-core/include/depthai/device/Device.hpp:14,
from /home/mike/oak/depthai-core-example/depthai-core/src/device/Device.cpp:1:
/home/mike/oak/depthai-core-example/depthai-core/include/depthai/common/UsbSpeed.hpp:5:10: fatal error: depthai-shared/common/UsbSpeed.hpp: No such file or directory
5 | #include "depthai-shared/common/UsbSpeed.hpp"
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
It seems that the include paths are now misaligned. I know the team is super busy so this is just for info, it's not holding me up. My main goal is to get my head around the specifics required for the CMakefiles.txt to support a stand-alone C++ build so I can import into eclipse and cross compile, but had it worked it would have given me a bit of an insight as the CMakefiles.txt was quite simple. I'll try your earlier suggestion during the week and report back.
Best Regards.
mikegardner sorry for late response - these messages don't ping me by default.
I should've mentioned that you must update the submodules as well:
cd depthai-core
git checkout main
git pull
git submodule update --init --recursive
The last command is the one that will update the dependent submodules to correct commits, otherwise those stay as they were before (which is what caused the issue of not finding a new UsbSpeed.hpp
in depthai-shared
submodule)
Regards,
Martin
themarpe Thanks Martin, I've tried that and made a step forward. However, I think I need to do some serious study into CMake. I'm now getting an error at the linking stage, but no idea where the relevant entry needs to be placed to link in the OpenCV. I already have put a set(OpenCV_DIR ... entry at the start of the CMakelist.txt file, which was sufficient to successfully build the myapp from the original code before the checkout and pull.
Here's the log, any hints appreciated, but I suspect this is my lack of knowledge of cmake rather than any depthai issues.
96%] Linking CXX static library libdepthai-core.a
[ 96%] Built target depthai-core
Scanning dependencies of target myapp
[ 98%] Building CXX object CMakeFiles/myapp.dir/src/main.cpp.o
/home/mike/oak/depthai-core-example/src/main.cpp: In function ‘int main()’:
/home/mike/oak/depthai-core-example/src/main.cpp:47:9: error: ‘cv’ has not been declared
47 | cv::imshow("rgb", inRgb->getCvFrame());
| ~
/home/mike/oak/depthai-core-example/src/main.cpp:49:19: error: ‘cv’ has not been declared
49 | int key = cv::waitKey(1);
| ~
In file included from /home/mike/oak/depthai-core-example/depthai-core/include/depthai/pipeline/datatype/ImageManipConfig.hpp:8,
from /home/mike/oak/depthai-core-example/depthai-core/include/depthai/pipeline/node/ImageManip.hpp:4,
from /home/mike/oak/depthai-core-example/depthai-core/include/depthai/pipeline/nodes.hpp:9,
from /home/mike/oak/depthai-core-example/depthai-core/include/depthai/depthai.hpp:17,
from /home/mike/oak/depthai-core-example/src/main.cpp:4:
/home/mike/oak/depthai-core-example/depthai-core/include/depthai/pipeline/datatype/ImgFrame.hpp: In instantiation of ‘void dai::ImgFrame::getCvFrame(T ...) [with T = {}]’:
/home/mike/oak/depthai-core-example/src/main.cpp:47:45: required from here
/home/mike/oak/depthai-core-example/depthai-core/include/depthai/pipeline/datatype/ImgFrame.hpp:178:46: error: static assertion failed: Library not configured with OpenCV support
178 | static_assert(dependent_false<T...>::value, "Library not configured with OpenCV support");
| ~~~~
make[2]: *** [CMakeFiles/myapp.dir/build.make:63: CMakeFiles/myapp.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:126: CMakeFiles/myapp.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
- Edited
mikegardner
Example app requires OpenCV as well as DepthAI built with OpenCV support. To set it for both use the following CMake define when configuring:
-D OpenCV_DIR=[path/to/opencv]
This will build both depthai-opencv (required to provide opencv related functions) as well as myapp with opencv available.
Thanks Martin, I'll look into that and contrast it against why it builds and operates perfectly fine prior to performing the checkout and pull. Hopefully it will help me understand the workflow requirements and relationship between the depthai-core components and the cmake configuration and generation steps.
OK, spent some time studying cmake, checked through the configurations, can't see anything obviously wrong, and followed the suggested -D during configuration of depthai-core-example/depthai-core/build and depthai-core-example/build
I'm seeing exactly the same error, even though the build reports the OpenCV and required libraries being found and OpenCV Support enabled successfully being built (see output below).
However, cloning and building the original depthai-core-example/ works perfectly fine (but obviously limited to using the back level example code)
To me it looks as though there's still something mis-aligned after the git checkout etc steps. I've followed all of the suggestions. Any ideas or hints would be greatly appreciated. Thanks.
Here's the detailed output...
Configuration of depthai-core-example/depthai-core/ build
cmake .. -D OpenCV_DIR=/home/mike/dev/libs
-- [hunter] Calculating Toolchain-SHA1
-- [hunter] Calculating Config-SHA1
-- [hunter] HUNTER_ROOT: /home/mike/.hunter
-- [hunter] [ Hunter-ID: 062a19a | Toolchain-ID: 64dcd41 | Config-ID: f3a139e ]
-- [hunter] NLOHMANN_JSON_ROOT: /home/mike/.hunter/Base/062a19a/64dcd41/f3a139e/Install (ver.: 3.9.1)
-- [hunter] XLINK_ROOT: /home/mike/.hunter/Base/062a19a/64dcd41/f3a139e/Install (ver.: luxonis-2021.3-master)
-- [hunter] BZIP2_ROOT: /home/mike/.hunter/Base/062a19a/64dcd41/f3a139e/Install (ver.: 1.0.8-p0)
-- [hunter] FP16_ROOT: /home/mike/.hunter/Base/062a19a/64dcd41/f3a139e/Install (ver.: luxonis-0.0.0)
-- [hunter] LIBARCHIVE-LUXONIS_ROOT: /home/mike/.hunter/Base/062a19a/64dcd41/f3a139e/Install (ver.: 3.4.2-p2)
-- [hunter] SPDLOG_ROOT: /home/mike/.hunter/Base/062a19a/64dcd41/f3a139e/Install (ver.: 1.8.2)
-- Performing Test FLAG-Wformat=2
-- Performing Test FLAG-Wformat=2 - Success
-- Performing Test FLAG-Werror=self-assign-field
-- Performing Test FLAG-Werror=self-assign-field - Failed
-- Performing Test FLAG-Werror=unused-lambda-capture
-- Performing Test FLAG-Werror=unused-lambda-capture - Failed
-- Performing Test FLAG-Werror=return-type
-- Performing Test FLAG-Werror=return-type - Success
-- Performing Test FLAG-Werror=non-virtual-dtor
-- Performing Test FLAG-Werror=non-virtual-dtor - Success
-- Performing Test FLAG-Werror=sign-compare
-- Performing Test FLAG-Werror=sign-compare - Success
-- Performing Test FLAG-Werror=reorder
-- Performing Test FLAG-Werror=reorder - Success
-- Performing Test FLAG-Werror=switch-enum
-- Performing Test FLAG-Werror=switch-enum - Success
-- Compiling depthai-core resources in PATCH_ONLY mode
-- Downloading Depthai device side binaries from server...
-- Downloading depthai and patch
-- commit: 2bd2bb926ceb9f52969ab42f64689e79d067b311
-- File already downloaded (resources): depthai-shared-commit-hash-7131affa2c01ecd34506e9c3dd8ea9198ed874f1.txt
-- depthai-shared between device and host MATCH!. (device: 2bd2bb926ceb9f52969ab42f64689e79d067b311, host: 2bd2bb926ceb9f52969ab42f64689e79d067b311
-- Downloading and checking depthai-device-fwp.tar.xz
-- File already downloaded (resources): depthai-device-fwp-7131affa2c01ecd34506e9c3dd8ea9198ed874f1.tar.xz
-- Downloading depthai bootloader
-- folder: /home/mike/oak/depthai-core-example/depthai-core/build/resources
-- maturity: release
-- commit_version_arg: 0.0.12
-- bootloader shared commit: 7efb3e188715844d7b2b0e50861e4bfc36087370
-- File already downloaded (resources): depthai-bootloader-shared-commit-hash-0.0.12.txt
-- depthai-bootloader-shared between device and host MATCH!. (device: 7efb3e188715844d7b2b0e50861e4bfc36087370, host: 7efb3e188715844d7b2b0e50861e4bfc36087370
-- Downloading and checking depthai-bootloader-fwp.tar.xz
-- File already downloaded (resources): depthai-bootloader-fwp-0.0.12.tar.xz
-- LIST OF RESOURCE COMPILED FILES: /home/mike/oak/depthai-core-example/depthai-core/build/resources/depthai-device-fwp-7131affa2c01ecd34506e9c3dd8ea9198ed874f1.tar.xz;/home/mike/oak/depthai-core-example/depthai-core/build/resources/depthai-bootloader-fwp-0.0.12.tar.xz
-- ClangFormat: clang-format not found! Target 'clangformat' not available...
-- ClangFormat: clang-format not found! Target 'clangformat' not available...
-- OpenCV and required libraries (opencv_core;opencv_imgproc) found. OpenCV Support enabled
-- BUILD_DATETIME: 2021-08-27 23:40:14 +0000, BUILD_COMMIT: 57bb84ad209825f181744f2308b8ac6f52a37604, BUILD_COMMIT_DATETIME: 2021-08-24 18:49:14 +0300
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mike/oak/depthai-core-example/depthai-core/build
Build of depthai-core-example/depthai-core
cmake --build .
[ 10%] Built target depthai-resources
Scanning dependencies of target depthai-core
[ 12%] Building CXX object CMakeFiles/depthai-core.dir/src/utility/Initialization.cpp.o
[ 14%] Linking CXX static library libdepthai-core.a
[ 96%] Built target depthai-core
[100%] Built target depthai-opencv
**Configuration of depthai-core-example/build **
cd ../../build
cmake .. -D OpenCV_DIR=/home/mike/dev/libs
-- Eclipse version is set to 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.
-- [hunter] Calculating Toolchain-SHA1
-- [hunter] Calculating Config-SHA1
-- [hunter] HUNTER_ROOT: /home/mike/.hunter
-- [hunter] [ Hunter-ID: 062a19a | Toolchain-ID: 64dcd41 | Config-ID: f3a139e ]
-- [hunter] NLOHMANN_JSON_ROOT: /home/mike/.hunter/Base/062a19a/64dcd41/f3a139e/Install (ver.: 3.9.1)
-- [hunter] XLINK_ROOT: /home/mike/.hunter/Base/062a19a/64dcd41/f3a139e/Install (ver.: luxonis-2021.3-master)
-- [hunter] BZIP2_ROOT: /home/mike/.hunter/Base/062a19a/64dcd41/f3a139e/Install (ver.: 1.0.8-p0)
-- [hunter] FP16_ROOT: /home/mike/.hunter/Base/062a19a/64dcd41/f3a139e/Install (ver.: luxonis-0.0.0)
-- [hunter] LIBARCHIVE-LUXONIS_ROOT: /home/mike/.hunter/Base/062a19a/64dcd41/f3a139e/Install (ver.: 3.4.2-p2)
-- [hunter] SPDLOG_ROOT: /home/mike/.hunter/Base/062a19a/64dcd41/f3a139e/Install (ver.: 1.8.2)
-- Performing Test FLAG-Wformat=2
-- Performing Test FLAG-Wformat=2 - Success
-- Performing Test FLAG-Werror=self-assign-field
-- Performing Test FLAG-Werror=self-assign-field - Failed
-- Performing Test FLAG-Werror=unused-lambda-capture
-- Performing Test FLAG-Werror=unused-lambda-capture - Failed
-- Performing Test FLAG-Werror=return-type
-- Performing Test FLAG-Werror=return-type - Success
-- Performing Test FLAG-Werror=non-virtual-dtor
-- Performing Test FLAG-Werror=non-virtual-dtor - Success
-- Performing Test FLAG-Werror=sign-compare
-- Performing Test FLAG-Werror=sign-compare - Success
-- Performing Test FLAG-Werror=reorder
-- Performing Test FLAG-Werror=reorder - Success
-- Performing Test FLAG-Werror=switch-enum
-- Performing Test FLAG-Werror=switch-enum - Success
-- Compiling depthai-core resources in PATCH_ONLY mode
-- Downloading Depthai device side binaries from server...
-- Downloading depthai and patch
-- commit: 2bd2bb926ceb9f52969ab42f64689e79d067b311
-- File already downloaded (resources): depthai-shared-commit-hash-7131affa2c01ecd34506e9c3dd8ea9198ed874f1.txt
-- depthai-shared between device and host MATCH!. (device: 2bd2bb926ceb9f52969ab42f64689e79d067b311, host: 2bd2bb926ceb9f52969ab42f64689e79d067b311
-- Downloading and checking depthai-device-fwp.tar.xz
-- File already downloaded (resources): depthai-device-fwp-7131affa2c01ecd34506e9c3dd8ea9198ed874f1.tar.xz
-- Downloading depthai bootloader
-- folder: /home/mike/oak/depthai-core-example/depthai-core/resources
-- maturity: release
-- commit_version_arg: 0.0.12
-- bootloader shared commit: 7efb3e188715844d7b2b0e50861e4bfc36087370
-- File already downloaded (resources): depthai-bootloader-shared-commit-hash-0.0.12.txt
-- depthai-bootloader-shared between device and host MATCH!. (device: 7efb3e188715844d7b2b0e50861e4bfc36087370, host: 7efb3e188715844d7b2b0e50861e4bfc36087370
-- Downloading and checking depthai-bootloader-fwp.tar.xz
-- File already downloaded (resources): depthai-bootloader-fwp-0.0.12.tar.xz
-- LIST OF RESOURCE COMPILED FILES: /home/mike/oak/depthai-core-example/depthai-core/resources/depthai-device-fwp-7131affa2c01ecd34506e9c3dd8ea9198ed874f1.tar.xz;/home/mike/oak/depthai-core-example/depthai-core/resources/depthai-bootloader-fwp-0.0.12.tar.xz
-- ClangFormat: clang-format not found! Target 'clangformat' not available...
-- ClangFormat: clang-format not found! Target 'clangformat' not available...
-- OpenCV and required libraries (opencv_core;opencv_imgproc) found. OpenCV Support enabled
-- BUILD_DATETIME: 2021-08-28 00:09:44 +0000, BUILD_COMMIT: 57bb84ad209825f181744f2308b8ac6f52a37604, BUILD_COMMIT_DATETIME: 2021-08-24 18:49:14 +0300
-- Eclipse version is set to 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mike/oak/depthai-core-example
Build step
cmake --build .
[ 10%] Built target depthai-resources
Scanning dependencies of target depthai-core
[ 12%] Building CXX object depthai-core/CMakeFiles/depthai-core.dir/src/utility/Initialization.cpp.o
[ 14%] Linking CXX static library libdepthai-core.a
[ 96%] Built target depthai-core
[ 98%] Building CXX object CMakeFiles/myapp.dir/src/main.cpp.o
/home/mike/oak/depthai-core-example/src/main.cpp: In function ‘int main()’:
/home/mike/oak/depthai-core-example/src/main.cpp:47:9: error: ‘cv’ has not been declared
47 | cv::imshow("rgb", inRgb->getCvFrame());
| ~
/home/mike/oak/depthai-core-example/src/main.cpp:49:19: error: ‘cv’ has not been declared
49 | int key = cv::waitKey(1);
| ~
In file included from /home/mike/oak/depthai-core-example/depthai-core/include/depthai/pipeline/datatype/ImageManipConfig.hpp:8,
from /home/mike/oak/depthai-core-example/depthai-core/include/depthai/pipeline/node/ImageManip.hpp:4,
from /home/mike/oak/depthai-core-example/depthai-core/include/depthai/pipeline/nodes.hpp:9,
from /home/mike/oak/depthai-core-example/depthai-core/include/depthai/depthai.hpp:17,
from /home/mike/oak/depthai-core-example/src/main.cpp:4:
/home/mike/oak/depthai-core-example/depthai-core/include/depthai/pipeline/datatype/ImgFrame.hpp: In instantiation of ‘void dai::ImgFrame::getCvFrame(T ...) [with T = {}]’:
/home/mike/oak/depthai-core-example/src/main.cpp:47:45: required from here
/home/mike/oak/depthai-core-example/depthai-core/include/depthai/pipeline/datatype/ImgFrame.hpp:178:46: error: static assertion failed: Library not configured with OpenCV support
178 | static_assert(dependent_false<T...>::value, "Library not configured with OpenCV support");
| ~~~~
make[2]: *** [CMakeFiles/myapp.dir/build.make:63: CMakeFiles/myapp.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:128: CMakeFiles/myapp.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
mikegardner Sorry for not making this clearer - the example app actually builds depthai-core
along side it.
So to do this, just configure depthai-core-example
with -D OpenCV_DIR=[path/to/opencv]
and build.
Something along the lines of:
# current directory depthai-core-example
cmake -S . -B build -D OpenCV_DIR=[path/to/opencv]
cmake --build build
themarpe Thanks for the reply.
Yes, that's exactly what I've been doing...
cmake -S .. -B build -D OpenCV_DIR=/home/mike/dev/lib
cmake --build build
And as I've been saying, this builds and executes perfectly well if I clone the original example, but if I bring it up to date to be able to use the latest code by following your earlier suggestion (25 Aug 19:14)...
cd depthai-core
git checkout main
git pull
git submodule update --init --recursive
I get the error above ("Library not configured with OpenCV support"). even though as you can see from the output during the configuration stage it reports...
"-- OpenCV and required libraries (opencv_core;opencv_imgproc) found. OpenCV Support enabled"
mikegardner You are right - I have glanced too quickly over the output message.
This seems odd - testing on my end now and will get back to you soon
mikegardner Pushed and fixed the issue.
https://github.com/luxonis/depthai-core-example/commit/3519111f712b7f480895809921fcd18c800a1ba0
The CMakeLists.txt
change was most likely the culprit.
The depthai-core
target (new naming: depthai::core
) doesn't tell the downstream target that opencv is available. (As the core target alone doesn't actually depend on OpenCV and also disables all OpenCV related API)
Meanwhile on the other hand depthai-opencv
(new naming: depthai::opencv
) target does depend on OpenCV and does enable the OpenCV API
Feel free to test this out and thanks for digging into
themarpe Thanks for the explanation. Yes that's fixed it.