在 Visual C 中的编译时更改程序的工作目录

发布于 2024-09-16 09:55:48 字数 84 浏览 3 评论 0原文

在 Visual C++ 上,有没有办法在编译时将程序的工作目录定义为不同于当前目录?老板们希望可执行文件位于根目录中,但所有 DLL 位于单独的目录中。

Is there a way to define a program's working directory to be different from its current directory at compile-time, on Visual C++? The bosses want the executable to be on the root directory but all DLLs to be in a separate dir.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

热血少△年 2024-09-23 09:55:48

您可以使用 SetCurrentDirectory Win32 API 来在运行时更改工作目录,但除了硬编码某些路径并使用相同的 API 调用之外,在编译时不应该(也不可能)执行任何操作。

You can use the SetCurrentDirectory Win32 API to change the working directory at runtime, but there's nothing that should be (nor could be) done at compile-time other than hard-code some path and use the same API call.

无法言说的痛 2024-09-23 09:55:48

为什么不直接使用构建事件将可执行文件移动或复制到根目录?如果您个人反对构建事件(也许 MSBuild 在您的构建系统中不考虑它们?),那么使用构建系统本身(例如 msbuild)来创建复制/移动可执行文件的目标。

Why not just use a build event that moves or copies the executable to the root? If you are personally against build events (perhaps MSBuild does not account for them in your build system?), then use the build system itself (such as msbuild) to make a target that copies / moves the executable.

天邊彩虹 2024-09-23 09:55:48

只需设置路径以包含所需的目录即可。应用程序将使用该路径来查找您的 dll。

Just set the path to include the desired directory. The application will use the path to find your dlls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文