LabVIEW Build Specifications: Relative Path Resolution in Runtime Engine
0 reputation · 07 Feb 2024, 21:10 UTC
0 reputation · 07 Feb 2024, 21:10 UTC
In a LabVIEW development environment, the IDE manages VI search paths and directory references dynamically. When transitioning a project to a production environment via Build Specifications, the application relies on the LabVIEW Runtime Engine, which lacks the IDE's integrated search path mechanisms.
A common challenge occurs when utilizing relative paths for configuration files or external dependencies. While these paths resolve correctly during local execution within the project directory, they may fail when the application is packaged as a standalone executable and deployed to a different directory structure on a target machine.
Given the difference in how the Runtime Engine handles the application directory compared to the development environment, there is uncertainty regarding the most reliable method to ensure dynamic path resolution without hard-coding absolute strings.
30775 reputation · 08 Feb 2024, 06:47 UTC
Relative paths in file I/O VIs inside a built LabVIEW executable resolve against the process current working directory, not against the folder that contains the executable. When you launch from a shortcut, the working directory is the shortcut’s “Start in” folder if set, otherwise the folder that contains the .lnk file. Launching by double-clicking the exe in Explorer sets the working directory to the executable’s folder. That difference is why a relative path that works in the IDE or when running from the project folder fails after deployment.
Consistent dependency loading is achieved by never relying on the working directory. Build an absolute path at runtime from the Application Directory and use that as the base for all relative sub-paths.
In the IDE the current working directory is typically the project root, so a relative path like config/settings.ini appears to work. In the Runtime Engine the working directory is set by the OS launch context. A shortcut with an empty “Start in” will make the working directory the folder containing the shortcut, not the exe. Any prior file operation that changes the current directory, e.g., a File Dialog VI configured to change current directory, will also shift the base for subsequent relative paths.
config and settings.ini.Verification: log Application Directory and the resolved absolute path at startup, then run the built exe directly from its folder, via a shortcut with blank Start in, and via a shortcut with Start in set to a different folder. The same file should be found in all three cases and no error 7 file not found should occur.
One diagnostic detail that changes the recommendation: do you currently use File Dialog VIs or other code that explicitly changes the current working directory? If yes, those calls must be removed or isolated, otherwise even Application Directory-based paths can be undermined by later relative operations.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.