Makefile找不到库。

huangapple go评论52阅读模式
英文:

Makefile cant find libraries

问题

我试图为树莓派4上的paho.mqtt项目编写自己的makefile

我已经下载并测试了paho.mqtt的安装,一切都按预期运行。

所以我现在正在测试一些C代码,但我只是无法弄清楚makefile(我是新手),我的文件到目前为止如下:

NAME = mqtt_test
OBJ = $(NAME).o
LIBS = -lpaho-mqtt3c -lpaho-mqtt3cs
CFLAGS = -Wall -I/usr/local/include -L/usr/local/lib
CC = gcc
EXTENSION = .c

all: $(NAME)

%.o: %$(EXTENSION)
	$(CC) -c -o $@ $< $(CFLAGS)

$(NAME): $(OBJ)
	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)

.PHONY: clean

clean:
	@rm -f *.o *~ core $(NAME)

这返回:

gcc -o mqtt_test mqtt_test.o -Wall -I/usr/local/include  -L/usr/local/lib -lpaho-mqtt3c -lpaho-mqtt3cs
/usr/bin/ld: 无法找到 -lpaho-mqtt3c
/usr/bin/ld: 无法找到 -lpaho-mqtt3cs
collect2: 错误: ld 返回 1
make: *** [makefile:14: mqtt_test] 错误 1

我已经检查了-I-L标志后面的目录中包含头文件和库文件。

当我查看/usr/bin时,没有ld,但有以paho_为前缀的paho文件,但没有库文件。

我漏掉了什么?

英文:

I'm trying to write my own makefile for a paho.mqtt project on a Raspberry Pi 4.

I've downloaded & tested the paho.mqtt install and its all working as expected.

So I'm now testing some C code but I just cant figure out the makefile (I'm new to this), my file so far,

NAME = mqtt_test
OBJ = $(NAME).o
LIBS = -libpaho-mqtt3c -libpaho-mqtt3cs
CFLAGS = -Wall -I/usr/local/include -L/usr/local/lib
CC = gcc
EXTENSION = .c

all: $(NAME)

%.o: %$(EXTENSION) $(DEPS)
	$(CC) -c -o $@ $&lt; $(CFLAGS)

$(NAME): $(OBJ)
	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)

.PHONY: clean

clean:
	@rm -f *.o *~ core $(NAME)

This returns,

gcc -o mqtt_test mqtt_test.o -Wall -I/usr/local/include  -L/usr/local/lib -libpaho-mqtt3c -libpaho-mqtt3cs
/usr/bin/ld: cannot find -libpaho-mqtt3c
/usr/bin/ld: cannot find -libpaho-mqtt3cs
collect2: error: ld returned 1 exit status
make: *** [makefile:14: mqtt_test] Error 1

I've checked & the includes and libraries are in the directories I put after the-I and -L flags.

When I look in /usr/bin there is no ld but there are paho files prefixed with paho_ but no library files.

What am I missing?

答案1

得分: 2

You don't use -libpaho-mqtt3c (etc.)

The option is -l, so when you write -libpaho-mqtt3c, the linker is looking for libraries named ibpaho-mqtt3c, which of course do not exist. That would be either libibpaho-mqtt3c.a or libibpaho-mqtt3c.so.

You want to use -lpaho-mqtt3c, remove the lib at the front and the extension .a or .so, and add in the option -l.

英文:

You don't use -libpaho-mqtt3c (etc.)

The option is -l so when you write -libpaho-mqtt3c the linker is looking for libraries named ibpaho-mqtt3c which of course do not exist: that would be either libibpaho-mqtt3c.a or libibpaho-mqtt3c.so.

You want to use -lpaho-mqtt3c: remove the lib at the front and the extension .a or .so, and add in the option -l.

huangapple
  • 本文由 发表于 2023年2月14日 22:10:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75449036.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定