run a program with more than one source files in GNU c++ compiler

后端 未结 3 1341
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 12:45

I am using DEV GNU c++ compiler on windows 7 OS. I need to know how a program with more than one source file can be compiled. here is example,

#FILE1
void f         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 13:34

    To preprocess and compile as such:

    gcc -c FILE1.c
    gcc -c FILE2.c
    

    Then, to link:

    gcc -o EXECUTABLE FILE1.obj FILE2.obj
    

    Alternately, you can do both in one step:

    gcc -o EXECUTABLE FILE1.c FILE2.c
    

    If it's a C++ program, then replace the gcc by g++ and the .c by .cpp.

    It does not interest you, but for the benefit of similar readers who find your question later, FILE1.cpp may be named FILE1.cc or the like, and FILE1.obj may be named FILE1.o, depending on the reader's platform.

    It may interest you that, depending on the shell you are using, you might have to write options like -o as /o.

提交回复
热议问题