V: Is is possible to include prebuilt library in v package?

Created on 22 Nov 2019  路  12Comments  路  Source: vlang/v

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!

Question

Most helpful comment

@donnisnoni95 Thanks!

All 12 comments

@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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

radare picture radare  路  3Comments

markgraydev picture markgraydev  路  3Comments

PavelVozenilek picture PavelVozenilek  路  3Comments

vtereshkov picture vtereshkov  路  3Comments

radare picture radare  路  3Comments