# Code runs when built with CMake but not Meson

**URL:** <https://community.stereolabs.com/t/code-runs-when-built-with-cmake-but-not-meson/159>\
**Category:** Uncategorized\
**Created:** [March 19, 2021, 12:58am UTC](https://community.stereolabs.com/t/code-runs-when-built-with-cmake-but-not-meson/159 "2021-03-19T00:58:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![niwhsa9](https://community.stereolabs.com/user_avatar/community.stereolabs.com/niwhsa9/32/97_2.png) [@niwhsa9](https://community.stereolabs.com/u/niwhsa9)\
**Post date:** [March 19, 2021, 12:58am UTC](https://community.stereolabs.com/t/code-runs-when-built-with-cmake-but-not-meson/159/1 "2021-03-19T00:58:50Z")

</div>

I have a program which runs perfectly fine when built with CMake, but the same program built w/ meson, I get the following errors when trying to use copyTo (cpu to gpu) and updateGPUfromCPU()

> in sl::ERROR\_CODE sl::Mat::copyTo(sl::Mat&, sl::COPY\_TYPE) const : cuda error [30]: unknown error.  
> in sl::ERROR\_CODE sl::Mat::updateGPUfromCPU() : cuda error [30]: unknown error.  
> in sl::ERROR\_CODE sl::Mat::updateGPUfromCPU() : cuda error [30]: unknown error.

Its pretty weird because it builds and links just fine, but then has a runtime error even though the change is in how its compiled. Relevant parts of my meson.build and CMakeLists shown below. Any idea how to fix this?  
**Meson.build**

> zed\_include\_dirs = include\_directories(‘/usr/local/zed/include’, ‘/usr/local/cuda/include’)  
> zed = declare\_dependency(  
> include\_directories : zed\_include\_dirs,  
> link\_args : [  
> # ZED SDK  
> ‘-L/usr/local/zed/lib’,  
> ‘-lsl\_zed’,  
> # CUDA  
> ‘-L/usr/local/cuda/lib64’,  
> ‘-lcuda’, ‘-lnppial’, ‘-lnppisu’, ‘-lnppicc’,  
> ‘-lnppicom’, ‘-lnppidei’, ‘-lnppif’, ‘-lnppig’,  
> ‘-lnppim’, ‘-lnppist’, ‘-lnppitc’, ‘-lnppc’  
> ])  
> all\_deps = [zed]

**CMakeLists.txt**

> cmake\_minimum\_required(VERSION 3.8 FATAL\_ERROR)  
> SET(CMAKE\_CUDA\_COMPILER\_ENV\_VAR /usr/local/cuda-10.0/bin/nvcc)  
> SET(CMAKE\_CUDA\_COMPILER /usr/local/cuda-10.0/bin/nvcc)  
> enable\_language(CUDA)  
> project(obs\_detection)
> 
> find\_package(ZED 3 REQUIRED)  
> include\_directories(${ZED\_INCLUDE\_DIRS})  
> include\_directories(${CUDA\_INCLUDE\_DIRS})  
> include\_directories(${CMAKE\_CURRENT\_SOURCE\_DIR}/include)
> 
> link\_directories(${ZED\_LIBRARY\_DIR})  
> link\_directories(${CUDA\_LIBRARY\_DIRS})
> 
> …  
> add\_executable (driver src/test-filter.cu src/obs-detector.cpp src/GLViewer.cpp src/common.cu src/plane-ransac.cu src/pcl.cpp src/euclidean-cluster.cu src/pass-through.cu src/find-clear.cu)  
> target\_link\_libraries (driver ${ZED\_LIBRARIES})  
> target\_link\_libraries(driver  
> ${SPECIAL\_OS\_LIBS}  
> ${ZED\_LIBS} )  
> target\_compile\_options(driver PRIVATE $\<$\<COMPILE\_LANGUAGE:CUDA\>:  
> -res-usage  
> –use\_fast\_math  
> \>)

---

<div class="post-metadata">

**Author:** ![obraun-sl](https://community.stereolabs.com/user_avatar/community.stereolabs.com/obraun-sl/32/17_2.png) [@obraun-sl](https://community.stereolabs.com/u/obraun-sl)\
**Post date:** [March 23, 2021, 7:23am UTC](https://community.stereolabs.com/t/code-runs-when-built-with-cmake-but-not-meson/159/2 "2021-03-23T07:23:57Z")

</div>

Hi,  
If you add \*.cu files to your executable, you probably need to setup cuda arch/options in meson build file since cu files must be compiled with nvcc.  
You can check the link here :  
[https://mesonbuild.com/Cuda-module.html](https://mesonbuild.com/Cuda-module.html)

hope this helps
