Linking object files

Linking foreign object files to GHDL

You may add additional files or options during the link of GHDL using -Wl, as described in Passing options to other programs. For example:

ghdl -e -Wl,-lm math_tb

will create the math_tb executable with the lm (mathematical) library.

Note the c library is always linked with an executable.

Hint

The process for personal code is the same, provided the code is provided as a C source or compiled to an object file. Analysis must be made of the HDL files, then elaboration with -e -Wl,personal.c [options...] primary_unit [secondary_unit] as arguments. Additional C or object files are flagged as separate -Wl,* arguments. The elaboration step will compile the executable with the custom resources. Further reading (particularly about the backend particularities) is at Elaboration [-e] and Run [-r].

Linking GHDL object files to Ada/C

As explained previously in Wrapping a simulation, you can start a simulation from an Ada or C program. However the build process is not trivial: you have to elaborate your program and your VHDL design.

Hint

If the foreign language is C, this procedure is equivalent to the one described in Linking foreign object files to GHDL, which is easier. Thus, this procedure is explained for didactic purposes. When suitable, we suggest to use -e, instead of --bind and --list-link.

First, you have to analyze all your design files. In this example, we suppose there is only one design file, design.vhdl.

$ ghdl -a design.vhdl

Then, bind your design. In this example, we suppose the entity at the design apex is design.

$ ghdl --bind design

Finally, compile/bind your program and link it with your VHDL design:

in C:

gcc my_prog.c -Wl,`ghdl --list-link design`

in Ada:

$ gnatmake my_prog -largs `ghdl --list-link design`

See GCC/LLVM only commands for further details about --bind and --list-link.