when trying to make my own extension for guile I have run into a problem with scm_new_smob.
I use the standard packages for guile in ubuntu. The code should compile on ubuntu 13.10 if you have guile installed. The problem is that the extension could not be loaded in guile REPL using (load-extension "/path/to/libbuilder.so" "init_builder"), the error I am getting is "File not found" but the path is correct. if I comment out line 12 in functions.cpp that calls scm_new_smob and then tries to load the extension, it will load. I am using: Ubuntu 13.10 guile (GNU Guile) 2.0.9 g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 GNU ld (GNU Binutils for Ubuntu) 2.23.52.20130913 GNU Make 3.81 I tried at first making a smaller example but that would for some reason work instead, without me really understanding what the difference was. -- // Jim Hansson // Tel: 0722019664 // http://se.linkedin.com/in/jimhansson // ===== GPG ===== // key: 9AA942ED // Fingerprint: 6947 5F70 7D4E D55D FCE2 // 3A1E 0C21 D543 9AA9 42ED // ===============
#include <libguile.h>
#include "functions.h"
#include "types.h"
// remember to use scm_assert_smob_type(tag, object) to verify that arguments are of the
// right type.
SCM define_package_wrapper(SCM name, SCM version, SCM require) {
SCM smob;
struct builder_package* package;
package = (builder_package*) scm_gc_malloc(sizeof (struct builder_package), "package");
package->name = name;
smob = scm_new_smob(builder_package_tag, (scm_t_bits) package);
return smob;
}
extern "C" {
void init_builder() {
init_builder_package_type();
scm_c_define_gsubr("C/define-package", 3, 0, 0, (void*) define_package_wrapper);
}
}
extern scm_t_bits builder_package_tag; extern "C" void init_builder();
Makefile
Description: Binary data
#include <libguile.h>
#include "types.h"
extern "C" {
static scm_t_bits builder_package_tag;
SCM mark_package(SCM package_smob) {
struct builder_package* pack = (struct builder_package*) SCM_SMOB_DATA(package_smob);
scm_gc_mark(pack->name);
return pack->update_function;
}
size_t free_package(SCM package_smob) {
struct builder_package* pack = (struct builder_package*) SCM_SMOB_DATA(package_smob);
scm_gc_free(pack, sizeof(struct builder_package),"package");
return 0;
}
static int print_package(SCM package_smob, SCM port, scm_print_state* state) {
struct builder_package* pack = (struct builder_package*) SCM_SMOB_DATA(package_smob);
scm_puts("#<package ", port);
scm_display(pack->name, port);
scm_puts(">", port);
return 1;
}
void init_builder_package_type() {
builder_package_tag = scm_make_smob_type("package", sizeof(struct builder_package));
scm_set_smob_mark(builder_package_tag, mark_package);
scm_set_smob_free(builder_package_tag, free_package);
scm_set_smob_print(builder_package_tag, print_package);
}
}
#include <libguile.h>
extern "C" {
struct builder_package {
SCM name;
SCM update_function;
};
void init_builder_package_type();
}
