~sircmpwn/hare-users

11 6

ld: undefined reference to rt.abort_fixed

Details
Message ID
<D6UE2A8NL9SS.29EIUDNAW1PL5@mxsr.de>
DKIM signature
pass
Download raw message
I'm mixing Hare and C objects again.

`layout.ha` contains this function:

export @symbol("layout_row_render") fn layout_row_render(
	row: nullable *LayoutRow,
) void = {
	match (row) {
	case null => void;
	case let row: *LayoutRow =>
		let x: f32 = row.x;
		let widget: nullable *Widget = row.widgets;
		for (widget is *Widget) {
			let r: Rectangle = render_texture(
					(widget as *Widget).texture,
					x,
					row.y,
					(widget as *Widget).width,
					(widget as *Widget).height,
					ALIGN_TOP_LEFT);
			x += r.w + row.spacing;
			widget = (widget as *Widget).next;
		};
	};
};

`hare compile -t o` works fine.

The linker complains:

/usr/bin/ld: layout.o: in function `layout_row_render':
/media/home/max/repos/TinyTicTacToe-Hare/app/src/main/jni/layout.ha:135:(.text.layout_row_render+0x36): undefined reference to `rt.abort_fixed'

(Line 135 is the first line in the function: `match (row) {`)

Can anyone tell me what's wrong?
Details
Message ID
<D6UEJERR0SDZ.Z513K54CZSIU@turminal.net>
In-Reply-To
<D6UE2A8NL9SS.29EIUDNAW1PL5@mxsr.de> (view parent)
DKIM signature
pass
Download raw message
> The linker complains:
>
> /usr/bin/ld: layout.o: in function `layout_row_render':
> /media/home/max/repos/TinyTicTacToe-Hare/app/src/main/jni/layout.ha:135:(.text.layout_row_render+0x36): undefined reference to `rt.abort_fixed'
>
> (Line 135 is the first line in the function: `match (row) {`)
>
> Can anyone tell me what's wrong?

Hare expects some functions to be present in the final binary and
rt.abort_fixed is one of them. You can get a good enough approximation of what
is needed by building the rt/ folder from the stdlib or the compiler repo with 
`hare build -t o -o rt.o rt/`, and then you can try linking that into your
executable.
Details
Message ID
<D6UE8WTXNFSQ.30LNSZBEANS6@d2evs.net>
In-Reply-To
<D6UE2A8NL9SS.29EIUDNAW1PL5@mxsr.de> (view parent)
DKIM signature
pass
Download raw message
you'll need to manually link rt:: (and any other stdlib modules you end 
up using) in

we haven't put a ton of work into integrating hare code into external 
build systems; as of now, you'll likely have more success using hare as 
the linker - `hare build` will treat any object files you stick in a 
hare module's directory as inputs to be linked in, just make sure you 
pass at least one -l flag in to it (-lc works if you're not using any c 
libraries), to make sure that libc is linked in as well
Details
Message ID
<D6UEDMSPVTJO.143CERTRMHJBB@mxsr.de>
In-Reply-To
<D6UEJERR0SDZ.Z513K54CZSIU@turminal.net> (view parent)
DKIM signature
pass
Download raw message
On Sun Jan 5, 2025 at 8:55 PM CET, Bor Grošelj Simić wrote:
> > The linker complains:
> >
> > /usr/bin/ld: layout.o: in function `layout_row_render':
> > /media/home/max/repos/TinyTicTacToe-Hare/app/src/main/jni/layout.ha:135:(.text.layout_row_render+0x36): undefined reference to `rt.abort_fixed'
> >
> > (Line 135 is the first line in the function: `match (row) {`)
> >
> > Can anyone tell me what's wrong?
>
> Hare expects some functions to be present in the final binary and
> rt.abort_fixed is one of them. You can get a good enough approximation of what
> is needed by building the rt/ folder from the stdlib or the compiler repo with 
> `hare build -t o -o rt.o rt/`, and then you can try linking that into your
> executable.

Thank you. I have tried this but now I get a different error:

/usr/bin/ld: rt.o: in function `_start':
(.text+0x0): multiple definition of `_start'; /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../lib/Scrt1.o:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
Details
Message ID
<D6UER3UPW95O.1AWUZ3GQ33GZ7@mxsr.de>
In-Reply-To
<D6UE8WTXNFSQ.30LNSZBEANS6@d2evs.net> (view parent)
DKIM signature
pass
Download raw message
On Sun Jan 5, 2025 at 8:41 PM CET, Ember Sawady wrote:
> you'll need to manually link rt:: (and any other stdlib modules you end 
> up using) in
>
> we haven't put a ton of work into integrating hare code into external 
> build systems; as of now, you'll likely have more success using hare as 
> the linker - `hare build` will treat any object files you stick in a 
> hare module's directory as inputs to be linked in, just make sure you 
> pass at least one -l flag in to it (-lc works if you're not using any c 
> libraries), to make sure that libc is linked in as well

Thank you for the hint! When I try this, I get a new error:

layout.ha:38:7: error: Duplicate global ident '::Alignment'

38 |    export type Alignment = uint;
   |          ^


This `Alignment` part was missing in my original snippet. These lines 
are also contained in `layout.ha`:

export type Alignment = uint;
def ALIGN_TOP_LEFT: uint = 0;
def ALIGN_TOP_RIGHT: uint = 2;

(In C, this was a `typedef enum {...} Alignment`.)
Details
Message ID
<D76BTQ6FWI6A.28N0XOTIAC9IR@d2evs.net>
In-Reply-To
<D6UER3UPW95O.1AWUZ3GQ33GZ7@mxsr.de> (view parent)
Sender timestamp
1737317980
DKIM signature
pass
Download raw message
On Sun Jan 5, 2025 at 8:05 PM UTC, Max Schillinger wrote:
> layout.ha:38:7: error: Duplicate global ident '::Alignment'

are you defining Alignment in any other .ha files in that directory?
Details
Message ID
<D76T4XBT9Y2Y.1NJS5GYRVXRTA@mxsr.de>
In-Reply-To
<D76BTQ6FWI6A.28N0XOTIAC9IR@d2evs.net> (view parent)
Sender timestamp
1737370416
DKIM signature
pass
Download raw message
On Sun Jan 19, 2025 at 9:19 PM CET, Ember Sawady wrote:
> On Sun Jan 5, 2025 at 8:05 PM UTC, Max Schillinger wrote:
> > layout.ha:38:7: error: Duplicate global ident '::Alignment'
>
> are you defining Alignment in any other .ha files in that directory?

Thank you for the hint! Indeed, I was defining Alignment in two .ha 
files because both files need this type. I have tried defining this type 
in a single (third) file (analogous to a C header file), but then `hare 
build -t o layout.ha` fails because it can't see this type. Then I 
realized that I shouldn't create object files with `hare build -t o` 
when I use `hare build` for linking everything together.

But this approach still fails because `main` is defined both in my 
`main_x11.c` and Hare's `rt` module:

$ hare build -v -o tinytictactoe-hare -lX11 -lGLESv2 -lEGL -lm -lvorbisfile -lasound
/usr/bin/ld: /media/home/max/repos/TinyTicTacToe-Hare/app/src/main/jni/main_x11.o: in function `main':
/media/home/max/repos/TinyTicTacToe-Hare/app/src/main/jni/main_x11.c:125: multiple definition of `main'; /home/max/.cache/hare/usr/local/src/hare/stdlib/rt/7c8b86d6d6deb76da23401e676ed227df137ace9d8c003a9e4f9af9e1a1140e5.o:(.text.main+0x0): first defined here
/usr/bin/ld: /home/max/.cache/hare/usr/local/src/hare/stdlib/rt/7c8b86d6d6deb76da23401e676ed227df137ace9d8c003a9e4f9af9e1a1140e5.o: in function `main':
/media/home/max/repos/TinyTicTacToe-Hare/app/src/main/jni/rt/+linux/start+libc.ha:20:(.text.main+0x2d): undefined reference to `.main'

Can I tell Hare to ignore rt's main function?
Details
Message ID
<D76XYEFVBNRS.1W79TNYM8WCAC@d2evs.net>
In-Reply-To
<D76T4XBT9Y2Y.1NJS5GYRVXRTA@mxsr.de> (view parent)
Sender timestamp
1737380411
DKIM signature
pass
Download raw message
On Mon Jan 20, 2025 at 9:53 AM UTC, Max Schillinger wrote:
> But this approach still fails because `main` is defined both in my 
> `main_x11.c` and Hare's `rt` module:

ah, yeah, that kinda sucks. it's a bit hacky, but try sticking an

	export fn main() void = main2();

in the hare code, then renaming your c main function to main2

hare needs to intercept main(), in order to be able to eg. run @init 
functions; we configure the hare toolchain to put the user's main() in 
the `.main` symbol, but that doesn't work with c
Details
Message ID
<D76XZEEKILYY.2BSOYK9ZFIC1D@cmpwn.com>
In-Reply-To
<D76XYEFVBNRS.1W79TNYM8WCAC@d2evs.net> (view parent)
Sender timestamp
1737384089
DKIM signature
pass
Download raw message
Could also build it freestanding (-F) and add -T+libc -lc
Details
Message ID
<D76XZRVB0Z6R.3QKFC98DWOTVL@cmpwn.com>
In-Reply-To
<D76XZEEKILYY.2BSOYK9ZFIC1D@cmpwn.com> (view parent)
Sender timestamp
1737384118
DKIM signature
pass
Download raw message
On Mon Jan 20, 2025 at 2:41 PM CET, Drew DeVault wrote:
> Could also build it freestanding (-F) and add -T+libc -lc

I take that back after thinking about it for more than 5 seconds
Details
Message ID
<D76YVWBXI695.1EPMNY74G16P7@mxsr.de>
In-Reply-To
<D76XYEFVBNRS.1W79TNYM8WCAC@d2evs.net> (view parent)
Sender timestamp
1737386636
DKIM signature
pass
Download raw message
On Mon Jan 20, 2025 at 2:40 PM CET, Ember Sawady wrote:
> On Mon Jan 20, 2025 at 9:53 AM UTC, Max Schillinger wrote:
>> But this approach still fails because `main` is defined both in my 
>> `main_x11.c` and Hare's `rt` module:
>
> ah, yeah, that kinda sucks. it's a bit hacky, but try sticking an
>
> 	export fn main() void = main2();
>
> in the hare code, then renaming your c main function to main2
>
> hare needs to intercept main(), in order to be able to eg. run @init 
> functions; we configure the hare toolchain to put the user's main() in 
> the `.main` symbol, but that doesn't work with c

Thank you, it works!

For future readers with the same problem:

I had to add these _two_ lines to a .ha file:

export @symbol("main2") fn main2() void;
export fn main() void = main2();
Details
Message ID
<D76Z9P38ZXLU.2UUQI6F8P5ZZA@mxsr.de>
In-Reply-To
<D76XYEFVBNRS.1W79TNYM8WCAC@d2evs.net> (view parent)
Sender timestamp
1737387717
DKIM signature
pass
Download raw message
OK, the first `export` isn't necessary. This works as well:

@symbol("main2") fn main2() void;
export fn main() void = main2();
Reply to thread Export thread (mbox)