Makefile wxWidgets

Asked

Viewed 73 times

0

I’m trying to use wxWidgets to do a college project and I ended up trying to use 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 wxWidgets flags and libs but when I run 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 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 the workings of Makefile and am trying to apply it using wxWidgets

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 are saved the flags to do the lynching with Wxwidgets, so you need to pass this at the time of doing the lynching, not in the compilation.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.