Ld: cannot open output file for writing: bin / s, errno = 2 for x86_64 architecture

I am trying to compile my code on OSX El Capitan. This is my Makefile

TARGET   = proj_name

CC       = gcc
# compiling flags 
CFLAGS   = -std=c99 -Wall -I.

LINKER   = gcc -o
# linking flags 
LFLAGS   = -Wall -I. -lm

SRCDIR   = src
OBJDIR   = obj
BINDIR   = bin

SOURCES  := $(wildcard $(SRCDIR)/*.c)
INCLUDES := $(wildcard $(SRCDIR)/*.h)
OBJECTS  := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
rm       = rm -f


$(BINDIR)/$(TARGET): $(OBJECTS)
    @$(LINKER) $@ $(LFLAGS) $(OBJECTS)
    @echo "Linking complete!"

$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
    @$(CC) $(CFLAGS) -c $< -o $@
    @echo "Compiled "$<" successfully!"

.PHONEY: clean
clean:
    @$(rm) $(OBJECTS)
    @echo "Cleanup complete!"

.PHONEY: remove
remove: clean
    @$(rm) $(BINDIR)/$(TARGET)
    @echo "Executable removed!"

I keep getting the following error while compiling on El Capitan

ld: can't open output file for writing: bin/proj, errno=2 for architecture x86_64

I understand that the problem is with the linker, but if someone can help me modify the Makefile, it really will help.

+4
source share
1 answer

Errno 2 means (google for something like errno list):

#define ENOENT       2  /* No such file or directory */

bin/proj - relative path.

Looking at the Makefile, the most likely reason seems to be that the directory binsimply does not exist. ldwill not try to create it if it is not there. To fix, add

mkdir -p $(BINDIR)

$(LINKER) line (-p switch , , , bin ).

: - , , , ld. , pwd, $(LINKER), . , Makefile, , , .

+5

Source: https://habr.com/ru/post/1610523/


All Articles