Makefile wxWidgets

0

I'm trying to use wxWidgets to do a college project and I ended up trying to use the Makefile out of curiosity, below the makefile I'm using as an example for the project.

Makefile

CPP_FILES := $(wildcard src/*.cpp)
OBJ_FILES := $(addprefix obj/,$(notdir $(CPP_FILES:.cpp=.o)))
LD_FLAGS := -lm
CPP_FLAGS := -Wall -Wextra


Crypto: $(OBJ_FILES)
    g++ -o $@ $^ $(LD_FLAGS)

obj/%.o: src/%.cpp src/%.h
    g++ $(CPP_FLAGS) -c -o $@ $<

clean:
    rm -f $(OBJ_FILES) *.o

I tried to adapt it to use the flags and libs of wxWidgets but when I run the makefile it gives me some linker errors ...

Makefile wxWidgets

CPP_FILES := $(wildcard src/*.cpp)
OBJ_FILES := $(addprefix obj/,$(notdir $(CPP_FILES:.cpp=.o)))
# wx-config --libs
WX_LIBS = $(shell wx-config --libs)
# wx-config --cxxflags
WX_CXXFLAGS = $(shell wx-config --cxxflags) 
LD_FLAGS := -lm
CPP_FLAGS := -Wall -Wextra

Crypto: $(OBJ_FILES)
    g++ -o $@ $^ $(LD_FLAGS)

obj/%.o: src/%.cpp src/%.h
    g++ $(CPP_FLAGS) $(WX_CXXFLAGS) $(WX_LIBS) -o $@ $<

clean:
    rm -f $(OBJ_FILES) *.o

One of the linker errors that is generated

mainWindow.cpp:(.text._ZN20wxEventFunctorMethodI14wxEventTypeTagI14wxCommandEventE12wxEvtHandler7wxEventS3_EclEPS3_RS4_[_ZN20wxEventFunctorMethodI14wxEventTypeTagI14wxCommandEventE12wxEvtHandler7wxEventS3_EclEPS3_RS4_]+0x8c): undefined reference to 'wxTrap()'
collect2: error: ld returned 1 exit status

What can I modify in this makefile? I'm still studying how the makefile works and I'm trying to apply it using wxWidgets

    
asked by anonymous 02.12.2015 / 04:17

1 answer

1

Excerpt from your Makefile:

Crypto: $(OBJ_FILES)         # Faz a lincagem
    g++ -o $@ $^ $(LD_FLAGS)

obj/%.o: src/%.cpp src/%.h   # Compila arquivos individuais
    g++ $(CPP_FLAGS) $(WX_CXXFLAGS) $(WX_LIBS) -o $@ $<

In the variable WX_LIBS the flags are saved to link with WxWidgets, so you need to pass this when doing the linking, not the compilation.

Another point: to just compile and generate a .o file, as it is in the second block there, you need to pass the -c flag to gcc, otherwise it will attempt to generate an executable immediately, only with that file.

    
06.12.2015 / 13:52