I think I have to refer to the directory every time I re-link the static library in the Makefile below.
If I have more than one static library, is there a way to specify a directory and then omit it?
Once you type L~/Library/lib
, you want to know if there is a way to link it by simply typing L~/Library/lib
and so on.
#$(CXX)$^-o$@-L~/Library/lib-lglfw3
gets the following error
$make
g++obj/Main.o-olibFrameWork.a-L to/Library/lib-lglfw3
/usr/bin/ld: -lglfw3 not found
collect2:error:ld returned1 exit status
make:*** [Makefile:11:libFrameWork.a] Error 1
PRG:=libFrameWork.a
SRC_DIR: =src
OBJ_DIR: = obj
DEP_DIR: =obj
DEP: =$(wildcard$(DEP_DIR)/*.d)
SRC: =$(wildcard$(SRC_DIR)/*.cpp)
OBJ: =$(addprefix$(OBJ_DIR)/,$(patsubst%.cpp, %.o, $(notdir$(SRC)))))
####################################################################
$(PRG): $(OBJ)
# $(CXX)$^-o$@-L~/Library/lib-lglfw3
$(CXX)$^-o$@-L~/Library/lib/glfw3
# arcs$@$(OBJ)
####################################################################
$(OBJ_DIR)/%.o:src/%.cpp
$(CXX)-c-MMD-MP$<-o$@-I~/Library
-include$(DEP)
US>clean:
rm-f./$(OBJ_DIR)/*.o*.out./$(OBJ_DIR)/*.d$(PRG)
If multiple libraries are in the same directory, you only need to specify them once with -L
.If you have more than one library in a different directory, you need as many directories as -L
.
Since you only need to write once in Makefile
, you don't have to worry about the number of times you write -L
.
Also, libraries created by others are usually installed in packages and flagged with the pkg-config --libs name
.
© 2024 OneMinuteCode. All rights reserved.