I know that everyone uses an IDE nowadays, but I just find it simpler to write my code in notepad++, compile it using a command prompt command, and run it from there too. At least that works for Java and Python. I've tried to get my head around how to do that with C++, and haven't been able to find anything good. Is there any compiler (like Java's JDK) that I can stick into my path and use the C++ equivalent of javac
and java
to run and compile my code from CMD?
我知道现在每个人都使用IDE,但我发现用notepad++编写代码、使用命令提示符命令编译代码、并从那里运行代码更简单。至少对Java和Python来说是这样。我一直在思考如何用c++实现这个目标,但一直找不到什么好东西。是否有任何编译器(如Java的JDK)可以在我的路径中使用,并使用c++的javac和Java来运行和编译我的CMD代码?
Note: please don't post answers and comments about how IDEs are better - I know they are. I'm just used to doing it the old way :D
注意:请不要发布关于ide如何更好的答案和评论——我知道它们是。我只是习惯了老方法:D
5 个解决方案
#1
20
It depends on what compiler you're using.
这取决于您使用的编译器。
For example, if you are using Visual C++ .NET 2010 Express, run Visual C++ 2010 Express Command Prompt from the start menu, and you can simply compile and run the code.
例如,如果您正在使用Visual c++ . net 2010 Express,请在开始菜单中运行Visual c++ 2010 Express命令提示符,您可以简单地编译并运行代码。
> cl /EHsc mycode.cpp
> mycode.exe
or from the regular command line, you can run vcvars32.bat
first to set up the environment. Alternatively search for setvcvars.cmd
(part of a FLOSS project) and use that to even locate the installed VS and have it call vcvars32.bat
for you.
或者从常规命令行运行vcvars32。bat首先设置环境。或者寻找setvcvars。cmd (FLOSS项目的一部分),并使用它来定位已安装的VS,并将其称为vcvars32。蝙蝠。
Please check your compiler's manual for command lines.
请检查编译器手册中的命令行。
#2
15
Steps to perform the task:
执行任务的步骤:
-
Yes, first install a compiler: Download from here
是的,首先安装一个编译器:从这里下载
-
Then type the C program, save it.
然后输入C程序,保存它。
-
Then open the command line and change directory, using 'cd' to the particular directory where the source file is stored.
然后打开命令行并更改目录,使用“cd”到存储源文件的特定目录。
like: cd C:\Documents and Settings...
例如:cd C:\文档和设置…
-
Then to compile/run type in the command prompt,
然后在命令提示符中编译/运行类型,
"gcc sourcefile_name.c" or "gcc -o outputfile.exe"
“gcc sourcefile_name。c"或"gcc -o outputfile.exe"
#3
8
I really don't see what your problem is, the question is rather unspecific. Given Notepad++ I assume you use Windows.
我真的不明白你的问题是什么,这个问题相当不具体。假设你用的是记事本++。
You have so many options here, from the MinGW (using the GCC tool chain and GNU make
) to using a modern MSVC. You can use the WDK (ddkbuild.bat/.cmd
or plain build.exe
), the Windows SDK (nmake.exe
), other tools such as premake and CMake, or msbuild
that comes with MSVC and the Windows SDK.
这里有很多选项,从MinGW(使用GCC工具链和GNU make)到现代MSVC。你可以使用WDK (ddkbuild.bat/)。cmd或普通build.exe)、Windows SDK (nmake.exe)、premake和CMake等其他工具,或者MSVC和Windows SDK附带的msbuild。
I mean the compiler names will differ, cl.exe
for MSVC and the WDK and Windows SDK, gcc.exe
for MinGW, but even from the console it is customary to organize your project in some way. This is what make
and friends were invented for after all.
我的意思是编译器名称会不同,cl。exe为MSVC和WDK和Windows SDK, gcc。exe为MinGW,但即使是来自控制台,也习惯以某种方式组织您的项目。这就是交友和交友的初衷。
So to know the command line switches of your particular compiler consult the manual of that very compiler. To find ways to automate your build (i.e. the ability to run a simple command instead of a complex command line), you could sift through the list on Wikipedia or pick one of the tools I mentioned above and go with that.
要了解特定编译器的命令行开关,请参阅该编译器的手册。要想找到自动化构建的方法(例如,能够运行简单的命令而不是复杂的命令行),您可以仔细查看Wikipedia上的列表,或者选择上面提到的工具之一,然后继续进行。
Side-note: it isn't necessary to ask people not to mention IDEs. Most professional developers have automated their builds to run from a command line and not from within the IDE (as during the development cycle for example), because there are so many advantages to that approach.
附加说明:没有必要要求人们不要提及ide。大多数专业开发人员已经自动化了他们的构建从命令行运行,而不是从IDE中运行(例如在开发周期中),因为这种方法有很多优点。
#4
8
If you're running windows then make use of this:
如果你正在运行windows,那么就利用这个:
g++ -o program program.cpp
g++ is the name of the compiler and -o is the command for creating a .o file. program (without .cpp suffix) is the exe file and program.cpp is your file that you want to compile.
g++是编译器的名称,-o是创建.o文件的命令。程序(没有.cpp后缀)是exe文件和程序。cpp是您希望编译的文件。
g++ -o program program.cpp&program.exe
Use this shortcut to run the .exe file of the program. This may run in Ubuntu but you may have to use .out suffix instead of .exe. Use this handy batch script I made to execute your programs on windows:
使用此快捷方式运行程序的.exe文件。这可能在Ubuntu中运行,但是您可能需要使用.out后缀而不是.exe。我在windows上执行您的程序时,使用了这个方便的批处理脚本:
@echo off&&cls
set /p pathName=Enter The Path where the file is located:%=%
cd %pathName%
REM set /p exec=Enter The Name of the executable you want to make:%=%
set /p file=Enter The Name of the file you want to compile:%=%
g++ -o %file% %file%.cpp
%file%.exe
save it as cppExecutor.bat
将其保存为cppExecutor.bat
Also you could use the following commands on unix (Linux and Mac) os:
您还可以在unix (Linux和Mac) os上使用以下命令:
CC program.cc
If you want to use gcc:
如果你想使用gcc:
gcc -o program program.cpp
With the shortcut:
快捷方式:
gcc -o program program.cpp&program.exe
#5
7
Sure, it's how most compilers got started. GCC is probably the most popular (comes with most flavors of *nix). Syntax is just gcc my_source_code.cpp
, or gcc -o my_executable.exe my_source_code.cpp
. It gets more complicated, of course, when you have multiple source files (as in implementation; anything #include
d works automatically as long as GCC can find it).
当然,大多数编译器就是这样开始的。GCC很可能是最受欢迎的(带有*nix的大多数口味)。语法就是gcc my_source_code。cpp,或gcc -o my_可执行文件。exe my_source_code.cpp。当然,当您有多个源文件时(如在实现中;只要GCC能找到,任何包含#的内容都会自动生效)。
MinGW appears to be a version of GCC for Windows, if that's what you're using. I haven't tried it though.
如果您正在使用的是Windows,那么MinGW似乎是GCC的一个版本。我还没试过。
Pretty sure most IDEs also include a command line interface. I know Visual Studio does, though I have never used it.
几乎可以肯定的是,大多数ide都包含命令行接口。我知道Visual Studio有,虽然我从来没有使用过它。
#1
20
It depends on what compiler you're using.
这取决于您使用的编译器。
For example, if you are using Visual C++ .NET 2010 Express, run Visual C++ 2010 Express Command Prompt from the start menu, and you can simply compile and run the code.
例如,如果您正在使用Visual c++ . net 2010 Express,请在开始菜单中运行Visual c++ 2010 Express命令提示符,您可以简单地编译并运行代码。
> cl /EHsc mycode.cpp
> mycode.exe
or from the regular command line, you can run vcvars32.bat
first to set up the environment. Alternatively search for setvcvars.cmd
(part of a FLOSS project) and use that to even locate the installed VS and have it call vcvars32.bat
for you.
或者从常规命令行运行vcvars32。bat首先设置环境。或者寻找setvcvars。cmd (FLOSS项目的一部分),并使用它来定位已安装的VS,并将其称为vcvars32。蝙蝠。
Please check your compiler's manual for command lines.
请检查编译器手册中的命令行。
#2
15
Steps to perform the task:
执行任务的步骤:
-
Yes, first install a compiler: Download from here
是的,首先安装一个编译器:从这里下载
-
Then type the C program, save it.
然后输入C程序,保存它。
-
Then open the command line and change directory, using 'cd' to the particular directory where the source file is stored.
然后打开命令行并更改目录,使用“cd”到存储源文件的特定目录。
like: cd C:\Documents and Settings...
例如:cd C:\文档和设置…
-
Then to compile/run type in the command prompt,
然后在命令提示符中编译/运行类型,
"gcc sourcefile_name.c" or "gcc -o outputfile.exe"
“gcc sourcefile_name。c"或"gcc -o outputfile.exe"
#3
8
I really don't see what your problem is, the question is rather unspecific. Given Notepad++ I assume you use Windows.
我真的不明白你的问题是什么,这个问题相当不具体。假设你用的是记事本++。
You have so many options here, from the MinGW (using the GCC tool chain and GNU make
) to using a modern MSVC. You can use the WDK (ddkbuild.bat/.cmd
or plain build.exe
), the Windows SDK (nmake.exe
), other tools such as premake and CMake, or msbuild
that comes with MSVC and the Windows SDK.
这里有很多选项,从MinGW(使用GCC工具链和GNU make)到现代MSVC。你可以使用WDK (ddkbuild.bat/)。cmd或普通build.exe)、Windows SDK (nmake.exe)、premake和CMake等其他工具,或者MSVC和Windows SDK附带的msbuild。
I mean the compiler names will differ, cl.exe
for MSVC and the WDK and Windows SDK, gcc.exe
for MinGW, but even from the console it is customary to organize your project in some way. This is what make
and friends were invented for after all.
我的意思是编译器名称会不同,cl。exe为MSVC和WDK和Windows SDK, gcc。exe为MinGW,但即使是来自控制台,也习惯以某种方式组织您的项目。这就是交友和交友的初衷。
So to know the command line switches of your particular compiler consult the manual of that very compiler. To find ways to automate your build (i.e. the ability to run a simple command instead of a complex command line), you could sift through the list on Wikipedia or pick one of the tools I mentioned above and go with that.
要了解特定编译器的命令行开关,请参阅该编译器的手册。要想找到自动化构建的方法(例如,能够运行简单的命令而不是复杂的命令行),您可以仔细查看Wikipedia上的列表,或者选择上面提到的工具之一,然后继续进行。
Side-note: it isn't necessary to ask people not to mention IDEs. Most professional developers have automated their builds to run from a command line and not from within the IDE (as during the development cycle for example), because there are so many advantages to that approach.
附加说明:没有必要要求人们不要提及ide。大多数专业开发人员已经自动化了他们的构建从命令行运行,而不是从IDE中运行(例如在开发周期中),因为这种方法有很多优点。
#4
8
If you're running windows then make use of this:
如果你正在运行windows,那么就利用这个:
g++ -o program program.cpp
g++ is the name of the compiler and -o is the command for creating a .o file. program (without .cpp suffix) is the exe file and program.cpp is your file that you want to compile.
g++是编译器的名称,-o是创建.o文件的命令。程序(没有.cpp后缀)是exe文件和程序。cpp是您希望编译的文件。
g++ -o program program.cpp&program.exe
Use this shortcut to run the .exe file of the program. This may run in Ubuntu but you may have to use .out suffix instead of .exe. Use this handy batch script I made to execute your programs on windows:
使用此快捷方式运行程序的.exe文件。这可能在Ubuntu中运行,但是您可能需要使用.out后缀而不是.exe。我在windows上执行您的程序时,使用了这个方便的批处理脚本:
@echo off&&cls
set /p pathName=Enter The Path where the file is located:%=%
cd %pathName%
REM set /p exec=Enter The Name of the executable you want to make:%=%
set /p file=Enter The Name of the file you want to compile:%=%
g++ -o %file% %file%.cpp
%file%.exe
save it as cppExecutor.bat
将其保存为cppExecutor.bat
Also you could use the following commands on unix (Linux and Mac) os:
您还可以在unix (Linux和Mac) os上使用以下命令:
CC program.cc
If you want to use gcc:
如果你想使用gcc:
gcc -o program program.cpp
With the shortcut:
快捷方式:
gcc -o program program.cpp&program.exe
#5
7
Sure, it's how most compilers got started. GCC is probably the most popular (comes with most flavors of *nix). Syntax is just gcc my_source_code.cpp
, or gcc -o my_executable.exe my_source_code.cpp
. It gets more complicated, of course, when you have multiple source files (as in implementation; anything #include
d works automatically as long as GCC can find it).
当然,大多数编译器就是这样开始的。GCC很可能是最受欢迎的(带有*nix的大多数口味)。语法就是gcc my_source_code。cpp,或gcc -o my_可执行文件。exe my_source_code.cpp。当然,当您有多个源文件时(如在实现中;只要GCC能找到,任何包含#的内容都会自动生效)。
MinGW appears to be a version of GCC for Windows, if that's what you're using. I haven't tried it though.
如果您正在使用的是Windows,那么MinGW似乎是GCC的一个版本。我还没试过。
Pretty sure most IDEs also include a command line interface. I know Visual Studio does, though I have never used it.
几乎可以肯定的是,大多数ide都包含命令行接口。我知道Visual Studio有,虽然我从来没有使用过它。