使用Makefile编译一些代码后,当我尝试运行它时得到了这个:

$ ./libbookgui.a
./libbookgui.a: line 1: syntax error near unexpected token `newline'
./libbookgui.a: line 1: `!<arch>'


Makefile具有以下内容。

INCLUDES = -I"$(FLTK)"
LIBS     = -lstdc++
CXXFLAGS = $(INCLUDES) -Wall -time -O3 -DNDEBUG -Wno-deprecated
LIBFLAGS =
AR       = ar

.SUFFIXES: .cpp .o

# Create a list of source files.
SOURCES  = $(shell ls *.cpp)
# Create a list of object files from the source file lists.
OBJECTS = ${SOURCES:.cpp=.o}
# Create a list of targets.
TARGETS = libbookgui.a

# Build all targets by default
all:    $(TARGETS)

%.a: $(OBJECTS)
    $(AR) rcs $@ $(OBJECTS)

# A rule to build .o file out of a .cpp file
%.o: %.cpp
    $(CXX) $(CXXFLAGS) -o $@ -c $<

# A rule to clean all the intermediates and targets
clean:
    rm -rf $(TARGETS) $(OBJECTS) *.out *.stackdump


我看到它的行是TARGETS = libbookgui.a,编译器不会返回任何错误,它只会创建.a文件。

有任何想法吗?

最佳答案

libbookgui.a是静态库(在其中汇总了多个目标文件)。

您应该运行可执行文件,而不是库。将此库链接到一些可执行文件中并运行它。

我建议您阅读this article

10-08 17:23