Search code examples
linkerexecutablevala

Can valac link object files to executable


I have 2 object files from which I want to create an executable. I see that I can do it with gcc as follows:

gcc main.vala.o statlib.o -lm -lglib-2.0

main.vala.o is created with valac using command valac -c main.vala while statlib.o is created with gcc using command gcc -c statlib.c.

I tried to create executable with valac but I got error with following command:

$ valac main.vala.o statlib.o --library=m --library=glib-2.0
error: main.vala.o is not a supported source file type. Only .vala, .vapi, .gs, and .c files are supported.
error: statlib.o is not a supported source file type. Only .vala, .vapi, .gs, and .c files are supported.
Compilation failed: 2 error(s), 0 warning(s)

How can I link object files to create executable with valac compiler?


Solution

  • Use gcc instead:

    $ gcc -o main main.vala.o statlib.o -lm `pkg-config --libs glib-2.0`
    

    See also the meson.build file I posted in your previous question:

    https://stackoverflow.com/a/73972038/426242

    Edit: Sorry I didn't completely read you question, you already know how to use gcc, but still: That is the way to go.