ld:无法打开输出文件进行写入:bin/s,对于架构x86_64,errno = 2 [英] ld: can't open output file for writing: bin/s, errno=2 for architecture x86_64

查看:94
本文介绍了ld:无法打开输出文件进行写入:bin/s,对于架构x86_64,errno = 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在OSX El Capitan上编译我的代码.这是我的Makefile

I'm 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!"

在El Capitan上编译时,我不断收到以下错误消息

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

我知道这是一个链接器问题,但是如果有人可以帮助我修改Makefile,那真的会有所帮助.

I understand that its a linker issue, but if someone could help me amending the Makefile, it would really help.

推荐答案

Errno 2意味着(谷歌搜索类似errno的列表):

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

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

bin/proj 是相对路径.

看一下Makefile,最可能的原因似乎是 bin 目录根本不存在.如果 ld 不存在,则不会尝试创建.要修复,请添加

Looking at the Makefile, the most likely cause seems to be, bin directory simply does not exist. ld will not try create it if it is not there. To fix, add

mkdir -p $(BINDIR)

$(LINKER)行之前( -p 开关允许创建一个不存在的路径,在这种情况下,如果 bin 已经存在).

before $(LINKER) line (-p switch allows creating a path if it does not exist, which in this case prevents error if bin already exists).

旁注:相对路径的另一个常见原因是,当运行 ld 时,工作目录不是您认为的那样.在 $(LINKER)命令之前添加 pwd 之类的命令将有助于解决此问题.但是查看Makefile,这可能不是这里的原因.

A side note: Another common cause with relative paths is, that working directory is not what you think it is, when ld is run. Adding command like pwd to before $(LINKER) command would help troubleshooting this. But looking at Makefile, this probably is not the reason here.

这篇关于ld:无法打开输出文件进行写入:bin/s,对于架构x86_64,errno = 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆