简体   繁体   中英

The linker can't find a library even when i have specified it's location with -L

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 ?

-L指定库的搜索目录,因此该选项应为-LD:/Development/GLFW/lib-mingw/

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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM