The docs do not mention LIBS . The option is called LIBS .
use Inline C => config => libs => '-L/usr/local/lib/ -llibcmark.so'; use Inline C => <<'__EOC__'; char* commonmark_to_html(char* thetext) { char* result = cmark_markdown_to_html(thetext, strlen(thetext)); return result; } __EOC__
Note that using char* thetext as an argument to an XS function is a sure sign of an error. This gives you a pointer to a string buffer without telling you the format of the buffer.
Assuming the library accepts and returns text encoded using UTF-8,
SV* commonmark_to_html(SV* text_sv) { STRLEN text_len; const char* text = SvPVutf8(text_sv, text_len); const char* html = cmark_markdown_to_html(text, text_len); SV* html_sv = newSVpvn_flags(html, strlen(html), SVf_UTF8); free(html); return html_sv; }
Optimized a little (since newSVpvn_flags less scalar more efficient because it has a code-code with the code sv_2mortal ):
void commonmark_to_html(SV* text_sv) { STRLEN text_len; const char* text = SvPVutf8(text_sv, text_len); const char* html = cmark_markdown_to_html(text, text_len); SV* html_sv = newSVpvn_flags(html, strlen(html), SVf_UTF8|SVs_TEMP); free(html); ST(0) = html_sv; XSRETURN(1); }
source share