链接库时的“undefined reference to”

    通常的“undefined reference to”都是找不到头文件和库文件,一般需要指定-I${header_path},-L${lib_path} -l${lib_name} ,都能解决问题,不过最近遇到一个特别奇怪的问题,加上以上的信息仍然报此错误,我的Makefile如下:

CROSS = mipsel-linux-
CFLAGS += -I./include
LDLIBS += -L./lib -lmtd


all: hello.c
	$(CROSS)gcc ${CFLAGS} ${LDLIBS} -o hello hello.c

出现以下的错误:

hello.c:(.text+0xa74): undefined reference to `libmtd_open'
hello.c:(.text+0xae0): undefined reference to `mtd_get_dev_info'
hello.c:(.text+0x13f0): undefined reference to `mtd_is_bad'
hello.c:(.text+0x1cc0): undefined reference to `mtd_write_oob'
hello.c:(.text+0x1df8): undefined reference to `mtd_write'
hello.c:(.text+0x1f68): undefined reference to `mtd_erase'
hello.c:(.text+0x2158): undefined reference to `mtd_mark_bad'
hello.c:(.text+0x2328): undefined reference to `libmtd_close'
collect2: ld returned 1 exit status
make: *** [all] Error 1


后来发现调换下-L的路径就能编译通过了,修改Makefile如下:

CROSS = mipsel-linux-
CFLAGS += -I./include
LDLIBS += -L./lib -lmtd


all: hello.c
	$(CROSS)gcc -o hello hello.c ${CFLAGS} ${LDLIBS}


真是编程世界无奇不有,究竟是什么原因呢?

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值