ignacio
ignacio

Reputation: 5

syntax error near unexpected token `newline'

After compiling some code using a Makefile I get this when I try to run it:

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

The Makefile has the following contents.

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

I see that it has the line TARGETS = libbookgui.a and the compiler doesn't return any errors it just creates the .a file.

Any ideas?

Upvotes: 0

Views: 15908

Answers (2)

MadScientist
MadScientist

Reputation: 100781

You need to update your post to show the changes you made to the makefile to get the link line added. Without that we can't really help you with that part of the problem.

Based on the errors my suspicion is that you're not using the right tool for linking: you're either using "gcc" (C compiler front-end) or trying to invoke the linker directly. When you link your application you should use the C++ compiler (in your case, $(CXX)). You also don't need to specify -lstdc++, since the C++ front-end will automatically add that to the link line.

Upvotes: 0

Eli Bendersky
Eli Bendersky

Reputation: 273366

libbookgui.a is a static library (that aggregates several object files in it).

You are supposed to run executables, not libraries. Link this library into some executable and run that.

I suggest you read this article.

Upvotes: 1

Related Questions