Search code examples
makefilewxwidgets

WxWidgets || Creating makefile


I'm trying to compile my program using makefile.

My code:

zad2_1Main: zad2_1Main.o zad2_1App.o
    g++ -o zad2_1Main zad2_1Main.o zad2_1App.o wx-config.exe --cxxflags

zad2_1Main.o: zad2_1Main.cpp
    g++ -c zad2_1Main.cpp wx-config.exe wx-config.exe --cxxflags

zad2_1App.o: zad2_1App.cpp
    g++ -c zad2_1App.cpp wx-config.exe wx-config.exe --cxxflags

But i have error:

unrecognized command line option '--cxxflags'

wx-config.exe is in the same folder as the files

My files:

Zad2_1App.cpp
Zad2_1App.h
Zad2_1Main.cpp
Zad2_1Main.h

Solution

  • You want to pass the output of wx-config to the compiler, not the literal string itself. Moreover, it's pretty wasteful to run the shell script again and again for each and every source file. So instead you should do the following:

    WX_CXXFLAGS := $(shell wx-config --cxxflags)
    WX_LIBS := $(shell wx-config --libs)
    
    zad2_1Main: zad2_1Main.o zad2_1App.o
        g++ -o zad2_1Main zad2_1Main.o zad2_1App.o $(WX_LIBS)
    
    zad2_1Main.o: zad2_1Main.cpp
        g++ -c zad2_1Main.cpp $(WX_CXXFLAGS)
    
    zad2_1App.o: zad2_1App.cpp
        g++ -c zad2_1App.cpp $(WX_CXXFLAGS)
    

    Your makefile could be improved in several other ways, but this should at least work.