c++ class why need main?

后端 未结 5 2109
难免孤独
难免孤独 2021-01-27 01:28

Hello I\'m writing a little project in c++ where I would like to have some classes that does some work, I wrote the interfaces and the implementation of the classes.

The

5条回答
  •  日久生厌
    2021-01-27 01:38

    You should either compile them together (in a single g++ command) or compile both of them to object files (g++ -c) and then use ld to link the object files together.

    Sample Makefile:

    all: app.exe
    
    app.exe: app.o animal.o
        g++ -o app.exe app.o animal.o
    
    app.o: app.cpp
        g++ -c -o app.o app.cpp
    
    animal.o: animal.cpp animal.h
        g++ -c -o animal.o animal.cpp
    

提交回复
热议问题