C++ 意外标记“newline'”附近出现语法错误;

C++ 意外标记“newline'”附近出现语法错误;,c++,makefile,C++,Makefile,在使用Makefile编译一些代码之后,当我尝试运行它时,会得到以下结果: $ ./libbookgui.a ./libbookgui.a: line 1: syntax error near unexpected token `newline' ./libbookgui.a: line 1: `!<arch>' 我看到它有一行TARGETS=libbookgui.a,编译器没有返回任何错误,只是创建了.a文件 有什么想法吗?libbookgui.a是一个静态库(在其中聚合多个对象

在使用
Makefile
编译一些代码之后,当我尝试运行它时,会得到以下结果:

$ ./libbookgui.a
./libbookgui.a: line 1: syntax error near unexpected token `newline'
./libbookgui.a: line 1: `!<arch>'
我看到它有一行
TARGETS=libbookgui.a
,编译器没有返回任何错误,只是创建了
.a
文件


有什么想法吗?

libbookgui.a
是一个静态库(在其中聚合多个对象文件)

您应该运行可执行文件,而不是库。将此库链接到某个可执行文件并运行该文件


我建议您阅读。

您需要更新您的帖子,以显示您对makefile所做的更改,从而添加链接行。没有这一点,我们就无法真正帮助你解决这部分问题


基于这些错误,我怀疑您没有使用正确的工具进行链接:您要么使用“gcc”(C编译器前端),要么试图直接调用链接器。当你链接你的应用程序时,你应该使用C++编译器(在你的例子中, $(CXX))。你也不需要指定<代码> -LSTDC++<代码>,因为C++前端会自动添加到链接行。

<代码>。一个库/文件>是一个库存档,它不是一个可执行文件。我看,在链接过程中(<代码> cc-O可执行名称LIbCest.a/代码>),编译器返回错误:<代码> LBBooGui.A(StureSmith.Mo):Store_main.cpp:(.text+0x4b):对Fl_菜单的未定义引用(int,int,int,int,char const*),或
libbookgui.a(Store_main.o):Store_main.cpp:(.text+0x461):对std::basic_ostream&std:u ostream\u insert(std::basic_ostream&,char const*,int)的未定义引用“
@ignacio:现在这是一个不同的问题-某些符号
libctest.a
正在查找,应该在其他库中找到,因此您也应该链接这些符号。”。此外,您还需要从某处获得一个
main
。我真的认为你应该从一些非常小和简单的东西开始,首先让它工作-你在这里采取的步骤对一个start来说太大了,似乎我忘了链接我的源文件。(.cpp),但现在编译器返回
/tmp/ccLGb4Ui.o:Chrono.cpp:(.text+0x306):对'std::basic_ostream::operator'的未定义引用
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