Running the complier from the Command Line

CC prog1.cc

For windows, it will generate the executable file named prog1.exe

For UNIX, it tends to put their executables in files named a.out

Remarks:

About cc and gcc

Cc refers to the C compiler in UNIX while gcc comes from Linux, which is the abbreviation of GNU compiler collection. Notice that gcc is a collection of compilers(not only related to C and C++).

Actually, in Linux, cc is the same as gcc. cc is just a soft link of gcc to make it easy to transfer the project from UNIX to Linux.

About gcc and g++

Gcc regards file with suffix .c as C program while g++ regards it as C++ program. cpp is regarded as C++ program for both commands.

In the compiling, g++ will invoke gcc command. Because gcc can not automatically connect to the libraries, while g++ can. So we usually use g++ instead of gcc.

In my Mac, when I enter gcc HelloWorld.cpp, it will throw a lot of error message for undefined symbols, which will not happen if you use g++ command.

The program in HelloWorld is very easy.

#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {

// insert code here...

std::cout << "Hello, World!\n";

return 0;

Referencehttp://www.cnblogs.com/xiedan/archive/2009/10/25/1589462.html

After compiling, we can directly run the executable file:

For windows, we just enter “prog1"

For Unix, we should use ./a.out.    (./ indicates the file is in the current directory)

In my Mac, the output is as below:

181-39:CppStudy luke$ ./a.out

Hello, World!

The value returnd from main is accessed in a system-dependent manner. On both UNIX and Windows systems, after executing the program, you must issue an appropriate echo command echo $?. In windows, we write echo %ERRORLEVEL%

In my Mac, the output of the echo $? command is as below:

181-39:CppStudy luke$ echo $?

0

Zero is the return value of the main function.

If you use g++ -o prog1 prog1.cc, it will generate an executable file named prog1 instead of a.out. For example, in my Mac, when I enter g++ -o lukewang main.cpp, then the it will generate a file named lukewang, you can use ./lukewang to run the file. The -o is an argument(参数) to the compiler, which can not be omitted.

Exercise 1.2: If the return value is -1, the result of command echo $? is 255.

Remarks: I use GDB as the debugging tool.

Here is the reference about gdb and gcc.

http://blog.163.com/[email protected]/blog/static/109968875201292625126644/

时间: 2024-10-11 12:01:54

Running the complier from the Command Line的相关文章

【IntellJ IDEA】idea启动测试类报错Error running &#39;Test1.test&#39;: Command line is too long. Shorten command line for Test1.test or also for JUnit default configuration.

idea启动测试类报错 Error running 'Test1.test': Command line is too long. Shorten command line for Test1.test or also for JUnit default configuration. 注意: 最简单的方法,就是你重新创建一个新的测试类,在里面重新写一遍测试方法,代码都可以粘贴过去. 解决方法: 1.打开本项目的.idea文件夹,找到文件夹中的workspace.xml文件 2.搜索 Proper

【转载】Data Science at the Command Line

Data Science at the Command Line Data Science at the Command Line is a new book written by Jeroen Janssens. This website contains information about the upcoming workshop in London, the webcast from August 20th, instructions on how to install the Data

Command Line Skills

Part 1: Command Line Interface(CLI) The Command Line Interface (CLI), is a text-based interface to the computer, where the user types in a command and the computer then executes it. The CLI environment is provided by an application on the computer kn

Command Line Android Application Debugging

http://codeseekah.com/2012/02/16/command-line-android-development-debugging/ I personally have a distaste towards IDEs, preferring lightweight solutions, with maybe less convenience. I addition to saving resources and having direct control over what

An A-Z Index of the Apple OS X command line

来源:http://ss64.com/osx/ An A-Z Index of the Apple OS X command line alias Create an alias • alloc List used and free memory apropos Search the whatis database for strings asr Apple Software Restore awk Find and Replace text within file(s) b basename

Enable rsh on MAC OS with command line

1. Enable rsh on macos. 1). os version (10.0) Enabling the "Allow remote login" option turns on telnet, rlogin (remote login), and rsh (remote shell) services. You can then connect remotely to your computer by using a client application for any

mac, xcode 6.1 安装command line tools 支持,autoconf,automake等

以下软件包 都去我的环境库找到 1 先安装 tcl库 2 安装macports /opt/local/bin/port 一般装到这里 安装autoconf时提示: Warning: The Xcode Command Line Tools don't appear to be installed; most ports will likely fail to build. Warning: Install them by running `xcode-select --install'.

Appendix D. Gradle Command Line

http://www.gradle.org/docs/current/userguide/gradle_command_line.html Appendix D. Gradle Command Line The gradle command has the following usage: gradle [option...] [task...] The command-line options available for the gradle command are listed below:

caffe command line

Command Line The command line interface – cmdcaffe – is the caffe tool for model training, scoring, and diagnostics. Run caffe without any arguments for help. This tool and others are found in caffe/build/tools. (The following example calls require c