Home > Software engineering >  Escaping spaces in LIBS path Makefile
Escaping spaces in LIBS path Makefile

Time:10-12

I'm trying to include Eclipse Mosquitto library sample mosquitto example from here

I'm trying to use a Makefile to build and compile the code.

I'm facing an issue where the compiler/linker/whatsoever cannot find the mosquitto library located at C:\Program Files\Mosquitto\devel. Here's the error:

mqtt-hostlink> make
gcc -Wall -o main main.c -LC:\\Program ,_,Files\\Mosquitto\\devel\mosquitto.lib
gcc: error: ,_,Files\Mosquitto\devel\mosquitto.lib: No such file or directory
make: *** [Makefile:11: make] Error 1

Here's my Makefile:

CC = gcc
null      :=
SPACE     := $(null) $(null)

LIBS = -LC:\\Program$(SPACE),_,Files\\Mosquitto\\devel\mosquitto.lib

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

make: main.c
    $(CC) -Wall -o main $^ $(LIBS)

.PHONY: clean

The "space" method I referred from : How to escape spaces inside a Makefile

CodePudding user response:

You can just use the short name for tar directory. List the directories with /X option as below

C:\>dir /X p*


 Directory of C:\

09/06/2021  02:24 PM    <DIR>          PROGRA~1     Program Files
09/06/2021  01:29 PM    <DIR>          PROGRA~2     Program Files (x86)
               0 File(s)              0 bytes

Then just use PROGRA~1 instead of Program Files

CodePudding user response:

There's some confusion here. That post is about how to escape spaces from make functions. You are not trying to invoke any make functions here, you are just trying to use a variable in a command line. There's no need to escape anything from make.

What you need to do is escape the spaces from the shell, not from make. You can do that easily, just using quotes. No need for fancy make operations. I recommend you also use forward-slashes, not backslashes. Almost all Windows programs accept both forward and backslashes. Only cmd.exe built-ins don't.

LIBS = "-LC:/Program Files/Mosquitto/devel/mosquitto.lib"
  • Related