e.g. If I want to create a package that binds to lz4 c library, is it possible to ship prebuilt (dynamically linked) .dll / .so / .dylib files along with the package? Or is there way to include c source code and cross compile? Thanks!
@hanabi1224 V combines all the C headers and other files that are included and used in a project so there's no need for .o or .dll etc. The output is a single binary which can be run anywhere.
@thecodrr Thanks! Is there any example on how to reference c source file? The document shows examples of referencing .h file which I thought was to link to system library
You'd include it like you include it in any C project.
#include "file.c"
@thecodrr How does V search for the file? I tried to place .c file next to .v one but it complains .c file not found
It is relative to the main.v file. What's your directory structure?
@thecodrr Just flat directory (created via v create), everything is in the same folder
@hanabi1224 add v #flag to your module
#flag -I $PWD/path_to_c_folder
path_to_c_folder is the relative path to the folder where you put your c files
$PWD is ENV variable, its a path to the current working directory. so it will be your root folder
@donnisnoni95 Thanks!
@hanabi1224 But it's not the best option. user must build it before they using it
@donnisnoni95 Since vlang uses C as backend, it works as a glue language by nature, it will be great to have detailed documentation on how to build a V lib with existing C source code and how to expose C APIs from vlang for other VM based languages to invoke
In rust, it's very easy to build a lib from existing C code / make extensions with safe rust code / expose C api to other VM based launguages. And I don't see a reason that prevents vlang from achieving that as well
e.g. https://github.com/bozaro/lz4-rs which builds a rust lz4 library from official C code
Try to look at this https://github.com/nsauzede/vsdl2
Most helpful comment
@donnisnoni95 Thanks!