Find the answer to your Linux question:
Results 1 to 4 of 4
I am trying to create a simple Makefile for a collection of code-files I have, but I get this error every time I compile: /bin/sh: syntax error at line 1: ...
  1. #1
    Just Joined!
    Join Date
    Aug 2009
    Posts
    2

    Unhappy Need some help with a simple Makefile...

    I am trying to create a simple Makefile for a collection of code-files I have, but I get this error every time I compile:

    /bin/sh: syntax error at line 1: "-c" unexpected
    gmake: *** [gentext.o] Error 2

    Of course, getting rid of all the -c's in my Makefile doesn't fix anything. Without them, I get:

    /bin/sh: syntax error at line 1: `gentext.cpp' unexpected

    I'm thinking there must be something really simple I'm missing here. Thanks for any help! Here's all the important bits of my Makefile code:

    Code:
    gmake gentext
    
    #------------------------------------------------
    # Variables
    
    CXX = g++
    
    CXXFLAGS = -Wall -ggdb $(M_DEBUG)
    
    RANDOBJS = RandomNumGen.o testRandom.o
    
    #-------------------------------------------------
    # Rules to compile
    
    PREFOBJS = gentext.o Prefix2.o RandomNumGen.o
    
    gentext: $(PREFOBJS) 
    	$(CXX) $(CXXFLAGS) $(PREFOBJS) -o gentext
    
    gentext.o: 
    	$(CXX) &(CXXFLAGS) -c gentext.cpp
    
    Prefix2.o: Prefix2.cpp Prefix2.h
    	$(CXX) &(CXXFLAGS) -c Prefix2.cpp
    
    RandomNumGen.o:
    	$(CXX) &(CXXFLAGS) -c RandomNumGen.cpp
    
    #-------------------------------------------------
    
    Prefix2.o: Prefix2.h
    
    testRandom: $(RANDOBJS)
    	$(CXX) $(CXXFLAGS) $(RANDOBJS) -o testRandom
    $(RANDOBJS): RandomNumGen.h

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    You appear to have used "&" instead of "$" in several places. That will probably fire off the preceding text as a background process, and the subsequent text as another command ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Exclamation

    yes,as drl said seems like you have used & instead of $ in following lines
    gentext.o:
    $(CXX) &(CXXFLAGS) -c gentext.cpp

    Prefix2.o: Prefix2.cpp Prefix2.h
    $(CXX) &(CXXFLAGS) -c Prefix2.cpp

    RandomNumGen.o:
    $(CXX) &(CXXFLAGS) -c RandomNumGen.cpp
    Replace all your & into $.
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  4. #4
    Just Joined!
    Join Date
    Aug 2009
    Posts
    2
    oh dear. i feel sufficiently dumb for not realizing such a small but significant error in my code. Thanks for the help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...