在Linux上用C创建可执行的附加组件

时间:2016-09-30 13:54:31

标签: c linux

我是Linux新手。对不起,我问的是非常基本的问题。在Windows上,我有Main.cpp文件,其中包含添加两个数字的代码。在Visual Studio中给了我.exe。但是如何在Linux上做到这一点。在我的Linux机器上有gcc编译器没有IDE。 我在Make文件中写的内容以及如何运行。

Main.cpp的代码类似于

#include <stido.h>
#include <conio.h>
// Static library file included
//#include "Add.h"
int main()
{
    int a,b,c;

    a = 10;
    b = 20;

    c= a+b;
    //Add function in static lib (.a in case of linux)
    //c= Add(a,b);
    printf("Addition is :%d",c);


    return 0;
}

之后我想使用添加功能。如何使用以上程序删除注释代码?

1 个答案:

答案 0 :(得分:1)

对于c ++代码,命令通常类似于:

g++ Main.cpp -o FileNameToWriteTo

或者,如果您只是运行

g++ Main.cpp

它将输出到名为a.out的默认文件。

无论哪种方式,您都可以通过以下方式运行您创建的文件:

./FileNameToWriteTo.out

详情请见http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html

相关问题