Makefile Lib链接问题

时间:2015-09-23 10:16:01

标签: c++ makefile static-libraries

在我的项目中,我有3个文件夹:

  • 包含lib头文件的包含
  • 包含lib文件的Libs
  • 包含我的项目源文件的来源

但是当我尝试编译时,我收到了这些错误:

g++ -W -Wall -Werror -ansi -pedantic -L ./Libs/ -langelscript -I./Includes/ -o Pretorian Sources/math.o Sources/main.o Sources/functions.o 
Sources/main.o: In function `main':
main.cpp:(.text+0x10): undefined reference to `asCreateScriptEngine'
Sources/main.o: In function `ConfigureEngine(asIScriptEngine*)':
main.cpp:(.text+0x7c): undefined reference to `asGetLibraryOptions'
collect2: ld returned 1 exit status

这是我的Makefile:

NAME = Pretorian

SRCDIR = ./Sources/
HDDIR = ./Includes/
LIBDIR = ./Libs/

SRCS = $(wildcard $(SRCDIR)*.cpp)
OBJS = $(SRCS:.cpp=.o)

CC = g++

RM = rm -f
ECHO = echo -e

CFLAGS += -W -Wall -Werror -ansi -pedantic
HFLAGS = -I$(HDDIR)
LDFLAGS = -L $(LIBDIR) -langelscript

all: $(NAME)

%.o: %.cpp
                $(CC) $(CFLAGS) $(HFLAGS) -o $@ -c $<

$(NAME): $(OBJS)
                        $(CC) $(CFLAGS) $(LDFLAGS) $(HFLAGS) -o $(NAME) $^
                @$(ECHO) '\033[0;32m> Compiled Without error\033[0m'

clean:
                $(RM) $(OBJS)
                @$(ECHO) '\033[0;33m> Directory cleaned\033[0m'

fclean: clean
                $(RM) $(NAME)
                @$(ECHO) '\033[0;33m> Remove executable\033[0m'

re: fclean all

SRCList:
        @$(ECHO) $(SRCS)

OBJList:
        @$(ECHO) $(OBJS)

我在Includes文件夹中有正确的include,我在Libs文件夹中有libangelscript.a

1 个答案:

答案 0 :(得分:0)

这是一个订单问题

我把LDFLAG放在文件前面: 我替换了这个:$(CC) $(CFLAGS) $(LDFLAGS) $(HFLAGS) -o $(NAME) $^ 由此:$(CC) $(CFLAGS) $(HFLAGS) -o $(NAME) $^ $(LDFLAGS)