An OpenCV CUDA build stops in Visual Studio with error MSB4023 before a single kernel compiles: MSBuild cannot evaluate the FullPath metadata of a generated object file, because the file's fully qualified path has outgrown the 260-character limit Windows applies to legacy paths. Deep source trees, doubled folder names from zip extraction and per-kernel wrapper names stack up fast, and opencv_world stacks every module's depth into one target. Count the characters in your own failing path, then fix it one of two ways: a short drive root, which removes the problem permanently, or the LongPathsEnabled registry key, which unblocks the build you have already started. The last sections cover where the finished DLLs land and how to keep the error from returning on the next machine.
Why does an OpenCV CUDA build fail with MSB4023?
MSB4023 fires when the fully qualified path of a generated CUDA object file exceeds the 260-character limit Windows applies to legacy paths, because MSBuild cannot evaluate the FullPath item metadata on a path that long while it assembles the opencv_world project.
For every CUDA kernel in every module, CMake generates a wrapper and names the object file after it. The file named in this class of report is cuda_compile_1_generated_column_filter.16sc1.cu.obj — the 16-bit signed column filter from the cudafilters contrib module — and it lives under the build directory, in modules\world\CMakeFiles\cuda_compile_1.dir, followed by the contrib source tree's own folders. The world library merges every module into one target, so that one chain carries the depth of the build tree plus the depth of each contrib source tree.
Release or Debug, x64 or not, changes nothing: the configuration folder adds the same few characters either way. The failure happens while MSBuild resolves item metadata, before the CUDA compiler runs anything, which is why the toolkit, the driver and the GPU are not the suspects here.
How many characters is too long for a Windows build path?
Windows draws the line at 260 characters for a fully qualified path wherever the MAX_PATH limit still applies, and MSBuild states it strictly: the fully qualified file name must be fewer than 260 characters, so a path of exactly 260 already fails.
Microsoft documents the MAX_PATH constant and the registry escape on its maximum path length limitation page. Here is an illustrative failing path, segment by segment, with a running count:
| Segment | Chars | Running total |
|---|---|---|
| C:\ | 3 | 3 |
| Users\ | 6 | 9 |
| alexander.fitzgerald\ | 21 | 30 |
| Downloads\ | 10 | 40 |
| opencv460\ | 10 | 50 |
| opencv-4.6.0\ | 13 | 63 |
| opencv-4.6.0\ (the zip's own folder, extracted into itself) | 13 | 76 |
| build\ | 6 | 82 |
| release\ | 8 | 90 |
| modules\ | 8 | 98 |
| world\ | 6 | 104 |
| CMakeFiles\ | 11 | 115 |
| cuda_compile_1.dir\ | 19 | 134 |
| opencv_contrib-4.6.0\ | 21 | 155 |
| opencv_contrib-4.6.0\ | 21 | 176 |
| modules\ | 8 | 184 |
| cudafilters\ | 12 | 196 |
| src\ | 4 | 200 |
| cuda\ | 5 | 205 |
| Release\ | 8 | 213 |
| cuda_compile_1_generated_column_filter.16sc1.cu.obj | 51 | 264 |
264 characters against a limit of fewer than 260: MSBuild refuses the file. The wrapper name alone costs 51 characters, and each doubled folder costs its full name a second time — 13 for opencv-4.6.0 and 21 for opencv_contrib-4.6.0, so 68 characters go to copies of names. A longer account name or one extra folder pushes a plausible setup over the line, which is how these builds fail in practice.
Why did moving the sources to a shorter folder not fix it?
Because the generated solution still carries the old paths: CMake baked the deep directories into the Visual Studio project files when you first configured, so MSBuild keeps failing on them until you delete the entire build directory and configure and generate again from the new location.
CMake records absolute paths at configure time and writes them into every generated project, so MSBuild resolves the FullPath metadata from the recorded locations, not from where your folders sit today. Renaming or moving the source folder leaves the stale build directory untouched and the error comes back identically. Delete and regenerate instead:
- Close Visual Studio.
- Delete the entire build directory — the folder holding OpenCV.sln and CMake's cache files. Every recorded path goes with it.
- Run CMake again: source directory at the new location, the contrib-modules setting pointed at the contrib tree's modules folder, and a fresh, short build directory.
- Configure until the red entries are gone, then Generate.
- Open the freshly generated OpenCV.sln and rebuild Release x64.
Configure-stage failures have their own article: CMake OpenCV submodule find_package error: build, install, then link.
How do you enable long paths in the registry?
Set LongPathsEnabled to DWORD 1 in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem, restart Windows, and rebuild: on Windows 10 version 1607 and later, and on Windows 11, that key removes the 260-character limit from the file functions MSBuild and the compiler rely on.
- Sign in as an administrator — HKLM writes need elevation, the same admin-rights wall other Windows tools hit; see the GigE configurator admin-rights fix.
- Open Registry Editor and go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem.
- Set LongPathsEnabled, type DWORD (32-bit), value 1.
- Restart Windows; the setting is read when the session starts.
- Delete the build directory, regenerate with CMake and rebuild.
One caveat: long paths only help applications that declare long-path awareness, and recent MSBuild does. If MSB4023 somehow survives a restart and a clean regeneration, use the short-root layout below — it needs no registry change and works for every tool in the chain.
Which folder layout keeps a CUDA build path short?
Put both source trees and the build directory directly off a drive root — C:\src\opencv, C:\src\opencv_contrib, C:\src\opencv\build — and the longest generated object path in the example above drops from 264 to 175 characters, leaving 85 characters of headroom.
The same object file lands at:
C:\src\opencv\build\release\modules\world\CMakeFiles\cuda_compile_1.dir\opencv_contrib\modules\cudafilters\src\cuda\Release\cuda_compile_1_generated_column_filter.16sc1.cu.obj
That is 124 characters before the file name plus the 51-character wrapper — 85 under the 260-character limit, enough to add modules, deeper contrib trees or a longer account name without counting again.
The rules that get you there:
- Extract each archive to exactly one folder: C:\src\opencv, not opencv-4.6.0\opencv-4.6.0. Every doubled folder pays its full name twice.
- Drop version suffixes from folder names; the version lives in the DLL name anyway.
- Build inside the source tree, at C:\src\opencv\build, so the object path is one short prefix plus short relative folders.
- Keep builds off the Desktop and any synced or redirected folders; those add invisible depth.
Should you build OpenCV on the controller or a workstation?
Build on whichever machine carries the CUDA-capable GPU your application targets, and give it 30 GB of free disk and several hours: thousands of generated kernel objects go into a CUDA build of opencv_world, and nvcc wants roughly 2 GB of RAM per parallel job.
Budget the parallel jobs by memory: an 8 GB machine builds four-at-a-time and a 32 GB machine eight to twelve. If the controller also carries the GPU, build on it; otherwise build at a desk and copy bin\Release and lib\Release across. If the build feeds depth-camera processing, size the whole machine with building OpenCV with CUDA for depth-camera streams.
The machines this code ends up running on are vision controllers — fanless computers with camera ports and light outputs that sit at the line, listed in the vision controllers category. Memory and drive size are the filters that matter here:
- LAN ports
- 5+ LAN ports
- USB 3 ports
- 3-4 USB 3 ports
- PoE
- PoE camera ports
- Light outputs
- 8 built-in channels
The MV-VC5525-256G70-NN pairs an Intel Core i5 with 32 GB RAM and a 256 GB SSD, and PCIe expansion is supported — headroom for the eight-to-twelve-job budget above.
- LAN ports
- 5+ LAN ports
- USB 3 ports
- 3-4 USB 3 ports
- Light outputs
- 4 built-in channels
- Memory
- 8 GB
The MV-VC3301H-128G66 runs an Intel Core i3 with 8 GB RAM and a 128 GB SSD, also with PCIe expansion supported. Treat it as the four-jobs-at-a-time case, and keep the build tree off the system drive if the SSD already carries the OS and your application.
Where do the built DLLs end up when opencv_world finishes?
CMake writes the runtime DLLs to the build directory's bin\Release — opencv_world460.dll when the world library is on — and the import libraries to its lib\Release; the lone opencv_videoio_ffmpeg460_64.dll in bin\Release is the bundled third-party dll CMake copies there.
When the build succeeds, bin\Release holds opencv_world460.dll next to the ffmpeg dll, and lib\Release holds opencv_world460.lib. To run your own program, add the build directory's bin\Release to PATH or copy opencv_world460.dll beside your executable, and link your project against opencv_world460.lib.
A DLL that is missing at run time on the deployed machine is a different, quieter failure with its own fixes: CMake prefix path set but DLL not found at run time and GenTL producer not listed: check Windows DLL paths.
Which fix should you pick — short paths or the registry key?
Use the registry key as the fast unblock and the short root as the permanent state: the key lifts the limit machine-wide in one edit but must follow every rebuild machine you own, while the short root needs no setting, no restart and no elevation.
| Short root (C:\src) | LongPathsEnabled = 1 | |
|---|---|---|
| What changes | Sources move; build directory deleted and regenerated | One registry DWORD, then restart |
| Admin rights | Not needed | Needed |
| Reboot | Not needed | Needed |
| Coverage | Every tool and every path | Long-path-aware applications only |
| Next machine | Repeat the habit | Reapply the key |
| Undo | Rename folders back | Flip the value to 0 |
For the build that is failing right now, the key plus a clean regeneration is the shortest route back. For a new machine, a shared build server or a re-imaged controller, start at C:\src and never count again. Doing both costs one registry edit and one folder move, and the counted paths stay under 200 characters.
The same wall stops other Windows engineering software: projects fail with TIA Portal path-too-long error at the same 260 characters, and driver tools report path-too-long error 1320 in RSLinx — the same Windows limit, so the same two fixes apply.
How do you keep MSB4023 from coming back on the next machine?
Standardise a build root on every Windows machine that touches CUDA — sources and build directly off C:, single-level extracted archives, long paths enabled once at provisioning — and the longest generated object path stays near 175 characters instead of creeping toward 260.
- Reserve one build root, C:\src, for every source and build tree on Windows machines that compile CUDA code.
- Extract archives to a single folder and delete any doubled nesting before configuring.
- Rename folders to drop version suffixes; the DLL name carries the version for you.
- Enable LongPathsEnabled once per machine as part of provisioning, not as an emergency edit.
- Before configuring a new module set, project the longest object path and keep it under 200 characters.
- After regenerating, confirm the new OpenCV.sln records paths under the short root before you start the build.
Once opencv_world460.dll builds clean, the rest of the station is selection work: configure a vision controller step by step with camera ports, memory and light channels matched to the inspection, and browse more build-side fixes under systems troubleshooting.
Questions
Does MSB4023 mean the CUDA toolkit or the GPU driver is broken?
No. MSB4023 is raised inside MSBuild while it resolves item metadata, before the CUDA compiler runs, and the message is only about a path exceeding the operating system's limit. Fix the path first; a genuine toolkit or driver problem will show itself once the build gets past this point.
How do you count the characters of a path from the error message?
Paste the path into a PowerShell string between single quotes and call .Length on the string, which returns the character count directly. Expect 260 or more on the failing path and under 200 once the build sits at a short drive root.
Will switching the generator to Ninja avoid the limit?
No. Ninja replaces MSBuild, so the MSB4023 code itself disappears and CUDA builds run faster, but the compiler still writes objects into the same deep folders and still fails past 260 characters wherever long paths are disabled. Keep the short root, the registry fix, or both.
Why does a CUDA build hit this when a CPU-only build of the same tree does not?
CUDA compilation generates one wrapper per kernel and per pixel type, with names like cuda_compile_1_generated_column_filter.16sc1.cu.obj, each under the module's CMakeFiles folder in the build tree. A CPU build compiles plain sources with short object names. The generated layer adds dozens of characters to every path, and the world library stacks every module's depth into one target.
Does enabling long paths change how deployed inspection software behaves?
The key only widens what the Windows file APIs accept; it does not alter files or permissions on disk, so running applications are unaffected. Enable it as a provisioning step on build machines first, and on controllers too if your own tooling walks deep trees — some older installers still enforce the old limit themselves.
Where does the contrib-modules setting point after the move to C:\src?
At the modules folder inside the contrib tree — C:\src\opencv_contrib\modules once you have renamed the folder to drop the version suffix. CMake writes the setting into its cache at configure time, so after any move you delete the build directory and configure fresh rather than trusting a cache that still holds the old path.

