Sublime Text not compiling multi-file projects in C++

后端 未结 1 857
谎友^
谎友^ 2021-01-24 09:53

I am to compile a multi-file C++ program, and have the following error;

Undefined symbols for architecture i386:
  \"included::printMSG()\", referenced from:
            


        
相关标签:
1条回答
  • 2021-01-24 10:03

    You can't just compile a single file and hope all other files are automatically linked to it to create the final program.

    One way to make that happen is to use a program called make, which reads a Makefile that has rules that make follows`.

    A simple Makefile can look like this:

    CXXFLAGS = -Wall -g
    
    my_pogram: main.o other_file.o third_file.o
        g++ main.o other_file.o third_file.o -o my_program
    
    main.o: main.cpp
        g++ $(CXXFLAGS) -c -o main.o main.cpp
    
    other_file.o: other_file.cpp
        g++ $(CXXFLAGS) -c -o other_file.o other_file.cpp
    
    third_file.o: third_file.cpp
        g++ $(CXXFLAGS) -c -o third_file.o third_file.cpp
    

    There are other similar programs to handle this. One that is popular is CMake.

    0 讨论(0)
提交回复
热议问题