#Trouble Linking

1 messages · Page 1 of 1 (latest)

eternal dock
#

Been having a bit of trouble linking two .o files.
First .o file is generated from compiling a .c file to a .ll file and then to a .o file
Second .o file is generated from a .zig file

When I attempt to link both together, I get the following error (using WSL btw)

LLD Link... ld.lld: error: duplicate symbol: _start
>>> defined at /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/crt1.o:(_start)
>>> defined at main
>>>            main.o:(.text+0x0)

Here are the commands I used in order (last one causes the error)

clang -O3 -S -emit-llvm helper.c -o helper.ll
llc -filetype=obj helper.ll -o helper.o      
zig cc -c helper.ll -o helper.o
zig build-obj main.zig -O ReleaseSmall       
zig cc -o main main.o helper.o -lc

I'm just trying to compile two simple files together, both don't contain complex code (I can share them if needed)

*Using the latest Zig version (master)

frosty elk
#

First .o file is generated from compiling a .c file to a .ll file and then to a .o file
why

#

why not just emit an object file from the .c file

#

you can provide multiple file inputs to build-exe, i.e zig build-exe helper.c main.zig -lc

eternal dock
frosty elk
#

could you explain a bit more on why it'll be from an .ll file?

#

this is sort of an XY question, there might just be a better way

eternal dock
#

I'm using clang just now because we've yet to get the textual ir generation working

#

just testing purposes really

frosty elk
#

i see

eternal dock
#

im testing linking with 2 simple files, if it works, we'll then test with the vm

frosty elk
#

if im remembering right, the flag is called something like -no-start-files for the last command you run

#

something like that

safe tree
frosty elk
#

yeah the flag is called -nostartfiles

#

do zig cc -o main main.o helper.o -lc -nostartfiles

eternal dock
eternal dock
frosty elk
#

to apply the fix in that issue, try doing zig build-obj main.zig -O ReleaseSmall -lc

eternal dock
#

It works now!

#

Thank you both very much

frosty elk
#

interesting, im confused why -nostartfiles doesn't work