0

I'm trying to write a Makefile which will copy its target and objects to bin/ and obj/ directories, respectively.

Yet, when I try to run it I get the following error:

nasm -f elf64 -g -F stabs main.asm -l spacelander.lst
ld -o spacelander obj/main.o
ld: cannot find obj/main.o: No such file or directory
make: *** [spacelander] Error 1
Why is this happening?

Update

I noticed when I posted the error that it was due to white spacing errors. After taking care of those, I still get the new error I replaced with the old one I mentioned prior.

What is this??

Update 2

Posted -d flag output below Makefile source.


Source

ASM  := nasm
ARGS := -f
FMT  := elf64
OPT  := -g -F stabs

SRC    := main.asm

OBJDIR := obj 
TARGETDIR := bin

OBJ    := $(addprefix $(OBJDIR)/,$(patsubst %.asm, %.o, $(wildcard *.asm)))
TARGET := spacelander

.PHONY: all clean

all: $(OBJDIR) $(TARGET)

$(OBJDIR): 
    mkdir $(OBJDIR)

$(OBJDIR)/%.o: $(SRC)
    $(ASM) $(ARGS) $(FMT) $(OPT) $(SRC) -l $(TARGET).lst

$(TARGET): $(OBJ)
    ld -o $(TARGET) $(OBJ)

clean:
    @rm -f $(TARGET) $(wildcard *.o)
    @rm -rf $(OBJDIR)

make -d Output - NOTE: output is too many characters for body, thus is pastebinned

http://pastebin.com/3bctGJxs

zeboidlund
  • 9,731
  • 31
  • 118
  • 180
  • Which lines are 29 and 32? Does make with the -d give anything notable? – Scooter Sep 29 '12 at 02:13
  • 1
    You probably need to specify the output file from `nasm`, maybe using `-o $@` as an additional option (but you'll have to read the manual to be sure). This is analogous to the `-o output.o` used with compilers such as `gcc`. – Jonathan Leffler Sep 29 '12 at 03:01
  • In the `$(TARGET): $(OBJ)` instruction you mean? – zeboidlund Sep 29 '12 at 03:03

1 Answers1

1

What Jonathan Leffler said in comments is correct. Your $(OBJDIR)/%.o: $(SRC) rule compiles your source into an object file, but you're not telling nasm where to save that object file. This explains exactly why you get the linking error regarding obj/main.o not being found by your linker - because nasm didn't know it should save it in obj/main.o. Try adding -o <output>, e.g:

$(OBJDIR)/%.o: $(SRC)
    $(ASM) $(ARGS) $(FMT) -o $@ $(OPT) $(SRC) -l $(TARGET).lst

This answer is marked as community wiki. Any gratitudes should go to Jonathan Leffler.

Community
  • 1
  • 1
jweyrich
  • 31,198
  • 5
  • 66
  • 97