我正在尝试将自己的静态库链接到我的主程序中。我的include头文件和库是在同一个路径中。 g ++能够很好地链接主标题,但它无法找到我的库(ipc.a)。请让我知道我做错了什么。
我在运行make时遇到的错误是:
# make
g++ -o esim esim.o -L /home/vint/HobbyProjects/esim/src/LIB/PLAT -lipc -Wall -g
/usr/bin/ld: cannot find -lipc
collect2: ld returned 1 exit status
Makefile在下面给出
INC_DIR = /home/vint/HobbyProjects/esim/src/LIB/PLAT
LIB_DIR = /home/vint/HobbyProjects/esim/src/LIB/PLAT
INCLUDES = -I $(INC_DIR)/
LIBS = -L$(LIB_DIR)/
LIBA = -lipc
CC = g++
DEBUG = -g
LFLAGS = -Wall $(DEBUG)
CFLAGS = -Wall -c
SOURCES = esim.cpp \
HEADERS = esim.h
OBJ = $(SOURCES:.cpp=.o)
EXE = esim
all: esim
$(EXE): $(OBJ)
$(CC) $(OBJ) $(INCLUDES) $(LIBA) -o $(EXE)
.cpp.o:
$(CC) $(CFLAGS) $(INCLUDES) $< -o $@
tar:
tar -czf $(EXE).tar.gz $(SOURCES) $(HEADERS) Makefile
clean:
rm -f $(OBJ)
rm -f $(EXE)
答案 0 :(得分:1)
问题是在makefile编译时没有添加-L/home/vint/HobbyProjects/esim/src/LIB/PLAT
选项。
变化:
$(EXE): $(OBJ)
$(CC) $(OBJ) $(INCLUDES) $(LIBA) -o $(EXE)
分为:
$(EXE): $(OBJ)
$(CC) $(OBJ) $(INCLUDES) $(LIBA) $(LIBS) -o $(EXE)