Visual C++命令行编译器 (CL.EXE) 重定向 OBJ 文件

发布于 2024-12-08 23:07:32 字数 168 浏览 0 评论 0原文

编译器 (CL.EXE) 可以获取多个源文件,但喜欢在调用它的目录中生成所有 OBJ 文件。我找不到用于设置输出目录的编译器标志,但我确实为单个 OBJ 找到了一个,但它不能采用多个源。

无需指定每个文件来重定向输出,并且无需为 NMAKE 提供大量目标,是否有一种简单的方法可以通过 CL 来完成此操作?

The compiler (CL.EXE) can take multiple source files, but likes to generate all the OBJ files in the directory that it is invoked. I couldn't find the compiler flag to set an output directory but I did find one for an individual OBJ, but it can't take multiple sources.

Without having to specify each file to redirect the output and having lots of targets for NMAKE, is there an easy way to do it through CL?

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

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

发布评论

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

评论(2

可是我不能没有你 2024-12-15 23:07:32

事实证明 /Fo 选项确实有效,但您指定的目录必须以反斜杠结尾。因此

cl  /Fo.\obj\  -c foo.c fee.c

可以工作,但 cl /Fo.\obj -c ... 会失败。

It turns out the /Fo option actually works, but the directory you specify must end with a backslash. Thus

cl  /Fo.\obj\  -c foo.c fee.c

Works but cl /Fo.\obj -c ... would fail.

眼泪也成诗 2024-12-15 23:07:32

只是为了添加唯一的答案。如果引用 obj 路径,则必须在路径结束引号之后添加尾部反斜杠,或者如果在引号之前添加则将其转义。

cl  /Fo"quoted path\obj"\  -c foo.c fee.c

OR

cl  "/Foquoted path\obj"\  -c foo.c fee.c

OR

cl  /Fo"quoted path\obj\\"  -c foo.c fee.c

说到 NMAKE,在 NMAKE 上传递带引号的宏值时需要类似的语法
命令行。结尾的反斜杠似乎是需要注意的关键部分。

nmake SOMEDIR="quoted path\obj"\

OR

nmake SOMEDIR="quoted path\obj\\"

OR

nmake "SOMEDIR=quoted path\obj"

NOT

nmake SOMEDIR="quoted path\obj\"

,因为这会导致转义引号 \" 并会抓取命令行上后面的任何内容并将其放入 $(SOMEDIR) 中。花了我一段时间诊断这种行为,希望这可以节省其他人的时间。

Just to add to the only answer. In case when the obj path is quoted, the trailing backslash has to be either added after the path closing quote, or escaped if added before the quote.

cl  /Fo"quoted path\obj"\  -c foo.c fee.c

OR

cl  "/Foquoted path\obj"\  -c foo.c fee.c

OR

cl  /Fo"quoted path\obj\\"  -c foo.c fee.c

Speaking of NMAKE, similar syntax is expected when passing quoted macro values on NMAKE
command line. The trailing backslash seems to be the crucial bit to watch for.

nmake SOMEDIR="quoted path\obj"\

OR

nmake SOMEDIR="quoted path\obj\\"

OR

nmake "SOMEDIR=quoted path\obj"

NOT

nmake SOMEDIR="quoted path\obj\"

as this would result in an escaped quote \" and would grab whatever else followed on the command line and put it into $(SOMEDIR). Took me a while to diagnose such a behavior, hope this would save time to someone else.

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