即使我用-L

时间:2019-11-23 23:30:58

标签: c++ c gcc makefile linker

这是我的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)*

这里

#Libraries
LIBS = -lmingw32 -lSDL2main -lSDL2 -LD:/Development/GLFW/lib-mingw/libglfw3.a -lglfw3 -lglew32s                 -lgdi32 -lopengl32

我用libglfw3.a指定了-L的位置,但是链接器仍然抱怨并且找不到-lglfw3。它给出了以下错误:

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

我正在使用Mingw32,如果我将libglfw3.a放在它的lib文件夹中,它将找到它(没有-LD:/Development/GLFW/lib-mingw/libglfw3.a)。

为什么当我用-L指定库的位置时,链接器找不到库?

2 个答案:

答案 0 :(得分:3)

super.super.x指定库的搜索目录,因此选项应为func takeScreenshot() -> UIImage { // Begin context print(UIScreen.main.scale) print(self.bounds.size) UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, UIScreen.main.scale) // Draw view in that context draw(self.bounds) //drawHierarchy(in: self.bounds, afterScreenUpdates: true) // And finally, get image let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() print(image) if (image != nil) { return image! } return UIImage() }

答案 1 :(得分:1)

位置表示位置,而不是什么

您提供了库的完整路径,而不是库所在的目录的路径。

-L用于指定包含库的目录的路径。

要么只提供到-L的目录(您已经有一个-lglfw3),要么删除-L,然后将此路径作为要链接的对象传递,就像使用所有.o文件(并删除-lglfw3)。