I want to know how to omit directory references in g++ static libraries.

Asked 1 years ago, Updated 1 years ago, 338 views

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)

c++

2022-12-18 09:55

1 Answers

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.


2022-12-19 07:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.