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

后端 未结 3 1343
被撕碎了的回忆
被撕碎了的回忆 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:29

    The technical term for 'multiple files' would be translation units:

    g++ file1.cpp file2.cpp -o program
    

    Or you separate compilation and linking

    g++ -c file1.cpp -o file1.o
    g++ -c file2.cpp -o file2.o
    
    # linking
    g++ file1.o file2.o -o program   
    

    But that usually doesn't make sense unless you have a larger project (e.g. with make) and want to reduce build times.

提交回复
热议问题