如何创建C ++ Makefile并使用它

时间:2017-08-20 10:37:37

标签: c++ makefile mingw

我尝试用winw在win10上编写一个c ++程序,但是我无法运行我的Makefile,现在我尝试了几个我的并且我认为我最了解它但它仍然不起作用..

HashTabelleTest.o: main.o HashTabelle.o
    g++ -o HashTabelleTest main.o HashTabelle.o

main.o: main.cpp HashTabelle.cpp
    g++ -c main.o main.cpp

HashTabelle.o: HashTabelle.cpp HashTabelle.h
    g++ -c HashTabelle.o HashTabelle.cpp HashTabelle.h

clear:
    rm *.o *.exe

作为管理员,我使用mingw32-make,但它所说的只是Nothing to be Done for 'Makefile.mak'

我尝试将这些部分编辑为新的但仍然是同样的东西

2 个答案:

答案 0 :(得分:0)

我知道它在胜利方面有点不同,比如没有rm但是del.But你在两个系统中都更好地支持 all:。在linux中,我总是使用以下格式

public static final class Test {
        final int                      iterations     =     100;
        final int                      jiterations    = 1000000;
        final int                      count          = (int) (0.7 * iterations);
        final AtomicInteger            finishedSingle = new AtomicInteger(iterations);
        final AtomicInteger            finishedZynced = new AtomicInteger(iterations);
        final MovingAverage.Cumulative singleCum      = new MovingAverage.Cumulative();
        final MovingAverage.Cumulative zyncedCum      = new MovingAverage.Cumulative();
        final MovingAverage            singleConv     = new MovingAverage.Converging(0.5);
        final MovingAverage            zyncedConv     = new MovingAverage.Converging(0.5);

        // -----------------------------------------------------------
        // -----------------------------------------------------------
        public static void main(String[] args) {
                final Test test = new Test();

                for (int i = 0; i < test.iterations; i++) {
                        test.benchmark(i);
                }

                Threads.sleep(1000000);
        }
        // -----------------------------------------------------------
        // -----------------------------------------------------------

        void benchmark(int i) {

                Threads.async(()->{
                        long start = System.nanoTime();

                        for (int j = 0; j < jiterations; j++) {
                                a();
                        }

                        long elapsed = System.nanoTime() - start;
                        int v = this.finishedSingle.decrementAndGet();
                        if ( v <= count ) {
                                singleCum.add (elapsed);
                                singleConv.add(elapsed);
                        }

                        if ( v == 0 ) {
                                System.out.println(elapsed);
                                System.out.println("Single Cum:\t\t" + singleCum.val());
                                System.out.println("Single Conv:\t" + singleConv.val());
                                System.out.println();

                        }
                });

                Threads.async(()->{

                        long start = System.nanoTime();
                        for (int j = 0; j < jiterations; j++) {
                                az();
                        }

                        long elapsed = System.nanoTime() - start;

                        int v = this.finishedZynced.decrementAndGet();
                        if ( v <= count ) {
                                zyncedCum.add(elapsed);
                                zyncedConv.add(elapsed);
                        }

                        if ( v == 0 ) {
                                // Just to avoid the output not overlapping with the one above 
                                Threads.sleep(500);
                                System.out.println();
                                System.out.println("Zynced Cum: \t"  + zyncedCum.val());
                                System.out.println("Zynced Conv:\t" + zyncedConv.val());
                                System.out.println();
                        }
                });

        }                       

        synchronized void a() { b();  }
                     void b() { c();  }
                     void c() { d();  }
                     void d() { e();  }
                     void e() { f();  }
                     void f() { g();  }
                     void g() { h();  }
                     void h() { i();  }
                     void i() { }

        synchronized void az() { bz(); }
        synchronized void bz() { cz(); }
        synchronized void cz() { dz(); }
        synchronized void dz() { ez(); }
        synchronized void ez() { fz(); }
        synchronized void fz() { gz(); }
        synchronized void gz() { hz(); }
        synchronized void hz() { iz(); }
        synchronized void iz() {}
}

答案 1 :(得分:0)

我拥有它:

Hashtabelletest: main.o Hashtabelle.o
    g++ -Wall -o Hashtabelletest main.o Hashtabelle.o

main.o: main.cpp Hashtabelle.h
    g++ -Wall -c main.cpp

Hashtabelle.o: Hashtabelle.cpp
    g++ -Wall -c Hashtabelle.cpp

1.问题是我必须将libstdc ++ - 6.dll从Mingw \ bin复制到我的工作文件夹

2.Thing是我必须输入mingw32-make -f Makefile.mak,而不是为我工作,@ all感谢您的支持