~emersion/mrsh-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH mrsh] Move $(LIBS) to end of compile command

Details
Message ID
<20220914162346.19848-1-andrew@paon.wtf>
DKIM signature
missing
Download raw message
Patch: +2 -2
Without this change, when I run `make` it fails with this error (edited
for clarity):

```
ld: frontend/readline.o: in function `sigint_handler':
mrsh/frontend/readline.c:33: undefined reference to `rl_on_new_line'
ld: mrsh/frontend/readline.c:34: undefined reference to `rl_replace_line'
ld: mrsh/frontend/readline.c:35: undefined reference to `rl_redisplay'
ld: frontend/readline.o: in function `interactive_init':
ld: mrsh/frontend/readline.c:53: undefined reference to `read_history'
ld: frontend/readline.o: in function `interactive_next':
ld: mrsh/frontend/readline.c:74: undefined reference to `add_history'
ld: mrsh/frontend/readline.c:76: undefined reference to `write_history'
collect2: error: ld returned 1 exit status
make: *** [Makefile:61: mrsh] Error 1
```

It turns out that the placement of `-l` in the command is significant
[1]; it should come after the object files that depend on the library.

> It makes a difference where in the command you write this option; the
> linker searches and processes libraries and object files in the order
> they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after
> file foo.o but before bar.o. If bar.o refers to functions in ‘z’,
> those  functions may not be loaded.

Moving $(LIBS) to the end of the command (right next to -lmrsh) fixes
the error.

Tested using gcc 12.2.0 and clang 15.0.0

[1] https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index ad9ada2..1730c5a 100644
--- a/Makefile
+++ b/Makefile
@@ -58,11 +58,11 @@ $(OUTDIR)/mrsh.pc:

mrsh: $(OUTDIR)/libmrsh.a $(mrsh_objects)
	@printf 'CCLD\t$@\n'
	@$(CC) -o $@ $(LDFLAGS) $(LIBS) $(mrsh_objects) -L$(OUTDIR) -lmrsh
	@$(CC) -o $@ $(LDFLAGS) $(mrsh_objects) -L$(OUTDIR) -lmrsh $(LIBS)

highlight: $(OUTDIR)/libmrsh.a $(highlight_objects)
	@printf 'CCLD\t$@\n'
	@$(CC) -o $@ $(LDFLAGS) $(LIBS) $(highlight_objects) -L$(OUTDIR) -lmrsh
	@$(CC) -o $@ $(LDFLAGS) $(highlight_objects) -L$(OUTDIR) -lmrsh $(LIBS)

check: mrsh $(tests)
	@for t in $(tests); do \
--
2.37.3

[mrsh/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CMW9JVQI3RYD.3CR54N6G8RVWJ@cirno2>
In-Reply-To
<20220914162346.19848-1-andrew@paon.wtf> (view parent)
DKIM signature
missing
Download raw message
mrsh/patches: SUCCESS in 1m8s

[Move $(LIBS) to end of compile command][0] from [Andrew Paon][1]

[0]: https://lists.sr.ht/~emersion/mrsh-dev/patches/35307
[1]: andrew@paon.wtf

✓ #844623 SUCCESS mrsh/patches/freebsd.yml   https://builds.sr.ht/~emersion/job/844623
✓ #844622 SUCCESS mrsh/patches/archlinux.yml https://builds.sr.ht/~emersion/job/844622
✓ #844621 SUCCESS mrsh/patches/alpine.yml    https://builds.sr.ht/~emersion/job/844621
Details
Message ID
<TmdgjrZ7GKuFiPGRtYUBeI3pf5w61gtV18nxyeE_c50PD71D7hmIDbeXBobQcurjVHDgAVVEzFEFoApPNCn0_Ef3-yhfl-0WS36ZYV-Bij4=@emersion.fr>
In-Reply-To
<20220914162346.19848-1-andrew@paon.wtf> (view parent)
DKIM signature
missing
Download raw message
Pushed, thanks!
Reply to thread Export thread (mbox)