The mechanism for compiling C code for use with the SystemVerilog DPI is going to be tool specific. But any tool should be able to provide the necessary switches to include your object on the command line, or use gcc independently to build a shared object that can be loaded into your simulator.
Regardless of how the DPI is built, SystemVerilog requires that any C code calling a SystemVerilog function must be from the same thread where SystemVerilog code called the C code first.
Basically, a SystemVerilog simulation appears as a single thread to the C code, and any interaction between the languages has to be within the same thread.