mighty-gerbils / gerbil

Gerbil Scheme
https://cons.io
GNU Lesser General Public License v2.1
1.14k stars 112 forks source link

Building executable with same basename as input source fails #1048

Closed leahneukirchen closed 8 months ago

leahneukirchen commented 8 months ago
% gerbil version
Gerbil v0.18 on Gambit v4.9.5-40-g24201248

We try to compile hello.ss into hello:

% cat hello.ss
(export main)
(def (main . args)
  (displayln "hello, world"))
% gxc -exe -o hello hello.ss
/tmp/gxc.1700324049.6964028/hello.scm:
/tmp/empty/hello.scmx:
/tmp/gxc.1700324049.6964028/hello.c:
/tmp/empty/hello.c:
/tmp/empty/hello_.c:
/usr/bin/ld: /tmp/empty/hello.o: in function `___LNK_hello':
hello.c:(.text+0x3d2): multiple definition of `___LNK_hello'; /tmp/gxc.1700324049.6964028/hello.o:hello.c:(.text+0x1da): first defined here
collect2: error: ld returned 1 exit status
*** ERROR IN gxc#compile-executable-module/separate -- 
*** ERROR IN ?
--- Syntax Error at compile: Compilation error; process exit with nonzero status
... form:   "gcc"

However, naming the output binary differently makes it work:

% gxc -exe -o myhello hello.ss 
/tmp/gxc.1700324120.77565/hello.scm:
/tmp/empty/myhello.scmx:
/tmp/gxc.1700324120.77565/hello.c:
/tmp/empty/myhello.c:
/tmp/empty/myhello_.c:
% ./myhello 
hello, world

(Personally, I think the name of the output file should not change the binary content at all.)

fare commented 8 months ago

Note that the problem magically disappears (or moves around) if you use a gerbil.pkg with a non-trivial package.

Nevertheless, I have a fix using an __exe suffix where appropriate.