Home > Software engineering >  Circular main in makefile
Circular main in makefile

Time:05-08

when i run "make" with the Makefile I wrote, it says "Circular main <- main dependency dropped." how to solve it?

main: main main.cpp pair.cpp
    g   -o main main.cpp pair.cpp
generate:
    g   -shared -fPIC -o libpair.so pair.cpp
clean:
    rm main.exe

CodePudding user response:

main: main main.cpp pair.cpp
    g   -o main main.cpp pair.cpp

There are too many mains in your makefile, make sure that you know the first main is the target name, and the second one is an executable that generated by "something else".

tar_main: main_exec main.cpp pair.cpp
    g   -o main_exec main.cpp pair.cpp

Assume we modify your makefile as this to identify the two mains. Here, to generate the target tar_main, make requires main.cpp, pair.cpp and main_exec. But we have no main_exec yet and it can only generated by target tar_main...

So tar_main is waiting for someone to generate main_exec and provides to it, and tar_main can only be generated by tar_main itself, in your makefile. That's a dead-lock, and the cycle can be detected, make will refuse to run this.

  • Related