Using mkmf with Ruby ext Linking a Static Library with -L and -I and -l

Kevin Sylvestre

Given a simple gcc command that follows as:

gcc quickrb.c -o main -L /usr/local/lib/quickjs -I /usr/local/lib/quickjs -l quickjs

I'm attempting to wrap this inside of a ruby gem extension extconf.rb using mkmf. Currently I've got:

require 'mkmf'

dir_config('quickjs', '/usr/local/lib/quickjs', '/usr/local/include/quickjs')

abort('missing "quickjs.h"') unless find_header('quickjs/quickjs.h')
abort('missing JS_NewRuntime') unless find_library('quickjs', 'JS_NewRuntime', 'quickjs/quickjs.h')
abort('missing JS_NewContext') unless find_library('quickjs', 'JS_NewContext', 'quickjs/quickjs.h')

create_makefile('quickrb/quickrb')

This fails with:

checking for quickjs/quickjs.h... yes
checking for JS_NewRuntime() in -lquickjs... no
missing JS_NewRuntime

I'm unsure how to processed. Without the find_library calls the Makefile generates, however it fails when compiling with:

dyld: Symbol not found: _JS_NewRuntime

Note:

Here is my sample quickrb.c file:

#include <quickjs/quickjs.h>

#include <ruby.h>

#include <stdio.h>
#include <strings.h>

void Init_quickrb()
{
  const char *filename = "runtime";
  const char *script = "3 + 4";
  const size_t length = strlen(script);

  JSRuntime *runtime = JS_NewRuntime();
  JSContext *context = JS_NewContext(runtime);

  JSValue value = JS_Eval(context, script, length, filename, JS_EVAL_TYPE_GLOBAL);

  const char *result = JS_ToCString(context, value);
  printf("%s = %s\n", script, result);
  JS_FreeCString(context, result);

  JS_FreeContext(context);
  JS_FreeRuntime(runtime);
}
Casper

I think what you want is:

find_library('quickjs', 'JS_NewRuntime', '/usr/local/lib/quickjs')

Because the documentation says:

find_library(lib, func, *paths, &b) public

Returns whether or not the entry point func can be found within the library lib in one of the paths specified, where paths is an array of strings. If func is nil , then the main() function is used as the entry point.

If lib is found, then the path it was found on is added to the list of library paths searched and linked against.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related