Reputation: 795
This is my makefile
# Output
OUTDIR = out/
#Source files
SRC = src/main
#Objects
OBJS = $(addprefix $(OUTDIR), $(addsuffix .o, $(SRC)))
#Dependencies
DEPS = $(addprefix $(OUTDIR), $(addsuffix .d, $(SRC)))
#Compiler
GCC = gcc
#Includes
INCS = -Iinc -ID:/Development/SDL2/Bins/include/SDL2 -ID:/Development/GLFW/include/GLFW\
-ID:/Development/GLEW/glew-2.1.0/include/GL
#Compiler flags
CFLAGS = $(INCS) -Wall
#Libraries
LIBS = -lmingw32 -lSDL2main -lSDL2 -LD:/Development/GLFW/lib-mingw/libglfw3.a -lglfw3 -lglew32s -lgdi32 -lopengl32
#Linker flags
LFLAGS = $(LIBS)
all: $(OUTDIR)asd.exe
$(OUTDIR)asd.exe: $(OBJS)
@echo LINKING...$(OBJS) $(LFLAGS)
@gcc -o $@ $(OBJS) $(LFLAGS)
$(OUTDIR)%.o: %.c
@mkdir -p $(subst /,\,$(dir $@))
# @echo PREPROCESSING...$<
# @gcc -Iinc -E $< -o $(patsubst %.o,%.i,$@)
# @echo COMPILLING...$(patsubst %.o,%.i,$@)
# @gcc -Iinc -S $(patsubst %.o,%.i,$@) -o $(patsubst %.o,%.s,$@)
# @echo ASSEMBLING...$(patsubst %.o,%.s,$@)
# @as $(patsubst %.o,%.s,$@) -o $@
@echo COMPILLING...$<
@$(GCC) $(CFLAGS) -MM -MT $@ -o $(patsubst %.o, %.d, $@) $<
@$(GCC) $(CFLAGS) -c $< -o $@
#$(OUTDIR)%.d: %.c
# @mkdir -p $(subst /,\,$(dir $@))
# @$(GCC) $(CFLAGS) -MM -MT $(patsubst %.d, %.o, $@) -o $@ $<
-include $(DEPS)
clean:
@echo CLEANING...
@rm -rf $(OUTDIR)*
Here
#Libraries
LIBS = -lmingw32 -lSDL2main -lSDL2 -LD:/Development/GLFW/lib-mingw/libglfw3.a -lglfw3 -lglew32s -lgdi32 -lopengl32
i have specified the location of libglfw3.a
with -L
, but the linker still complains and can't find -lglfw3
.It gives the following error:
LINKING...out/src/main.o -lmingw32 -lSDL2main -lSDL2 -LD:/Development/GLFW/lib-mingw/libglfw3.a -lglfw3 -lglew32s -lgdi32 -lopengl32
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lglfw3
collect2.exe: error: ld returned 1 exit status
I am using Mingw32 and if i put libglfw3.a
in it's lib
folder it finds it(without -LD:/Development/GLFW/lib-mingw/libglfw3.a
).
Why the linker can't find the library when i have specified it's location with -L
?
Upvotes: 1
Views: 797
Reputation: 385325
Location means where it is, not what it is.
You provided the full path for the library, not the path of the directory where the library is located.
-L
is used to specify a path to a directory which contains libraries.
Either provide just the directory to -L
(you already have a -lglfw3
), or remove the -L
and just pass this path as an object to link, just like you do with all the .o
files (and remove the -lglfw3
).
Upvotes: 2
Reputation: 451
-L
specifies the search directory for libraries, so the option should be -LD:/Development/GLFW/lib-mingw/
.
Upvotes: 4