最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - How to setup environment for compilation mode on Windows so that it recognizes a compilation command - Stack Overflow

programmeradmin1浏览0评论

In order to compile a C++ project I need to first run this in the command line:

"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64

then call emacs from that same command line, then compilation mode recognizes cl compiler command. How can I configure emacs so that I don't need to run it from a command line, instead this would be initialized for compilation mode so that it recognizes cl.

In order to compile a C++ project I need to first run this in the command line:

"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64

then call emacs from that same command line, then compilation mode recognizes cl compiler command. How can I configure emacs so that I don't need to run it from a command line, instead this would be initialized for compilation mode so that it recognizes cl.

Share Improve this question asked Jan 29 at 11:24 o_luka02o_luka02 33 bronze badges 12
  • 5 Why are you using Emacs, of all possible editors? These days it's only used by old bearded men close to (or even beyond) retirement. Visual Studio Community is free, and you don't need to worry about things like that. Not to mention that the knowledge you learn about that environment will be usable in the future. – Some programmer dude Commented Jan 29 at 11:29
  • 2 You could use a build system (such as CMake) and/or switch to a different compiler (such as Clang, which I think is a better option anyway). – HolyBlackCat Commented Jan 29 at 11:31
  • 1 As for your problem, create a BAT file that runs the vcvarsall.bat command and starts Emacs. Create a shortcut to it on your desktop. Now you can run it as any other program by double-clicking its icon. – Some programmer dude Commented Jan 29 at 11:32
  • @HolyBlackCat a build system is not the problem, I already have a build.bat file which I call in emacs automatically, the problem is that in that build file I use cl to compile, and when I run this by default compilation mode doesn't recognize it, so I have to run emacs from a command line that already recognizes cl. Also I would like to keep using MSVC. – o_luka02 Commented Jan 29 at 11:34
  • 1 A good build system doesn't need to rely on pack of heuristics to figure out compiler when it is known in advance. i.sstatic/f5XaYLL6.png – user7860670 Commented Jan 29 at 11:43
 |  Show 7 more comments

1 Answer 1

Reset to default 0

Applying user7860670's idea, I was able to achieve the desired functionality (even though my original question asked for something else), although now compilation is slower by about 1-2 seconds. Add code that initializes environment at the beginning of your build script, in my case I added:

call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64

But this will run with every compile making it a bit slower.

发布评论

评论列表(0)

  1. 暂无评论