janet-lang / jpm

Janet Project Manager
MIT License
68 stars 22 forks source link

jpm build + jaylib => functions are nil #2

Closed saikyun closed 3 years ago

saikyun commented 3 years ago

When running jpm build && ./build/lul in this minimal project: https://github.com/saikyun/jaylib-and-new-jpm-test

Source (UPDATED to use jaylib instead):

(use jaylib)

(defn main [& args]
  (init-window 800 600 "wat")
  (pp args)
  (print "hej :)"))

I get:

error: nil called with 3 arguments, possibly expected 1
  in main [lul/main.janet] on line 4, column 3

It works when doing janet lul/main.janet.

Am on Ubuntu, janet 1.17.0-dev-61769c8f linux/x64.

bakpakin commented 3 years ago

Looks like the init-window function call is somehow not being loaded or linked, and is instead replaced with nil.

saikyun commented 3 years ago

It happened to all functions I tried. Any clue where to start checking?

saikyun commented 3 years ago

I had accidentally written (use freja-jaylib) when I made the repro repo. I've now updated it, and I still get the same error.

saikyun commented 3 years ago

Another error, with the following source:

(defn main [& args]
  (require "jaylib"))

I get:

error: could not load native /usr/local/lib/janet/jaylib.so: /usr/local/lib/janet/jaylib.so: undefined symbol: janet_getkeyword
  in native [src/core/corelib.c] on line 314
  in native-loader [boot.janet] on line 2622, column 40
  in require-1 [boot.janet] (tailcall) on line 2645, column 18

When running a binary built by jpm build.

saikyun commented 3 years ago

sogaiu figured out that you can reproduce by just running dlopen:

// assuming this content is in the file repro.c:
//
//   gcc repro.c -ldl
//
// then:
//
//   ./a.out put-the-full-path-to-the-so-file-here

#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char *argv[])
{
  if (argc > 1) {
    void* lib = dlopen(argv[1], RTLD_NOW);
    if (!lib) {
      printf("oops: %s\n", dlerror());
      return -1;
    }
  }
  return 0;
}

Following the instructions leads to:

$ gcc repro.c -ldl && ./a.out /usr/local/lib/janet/jaylib.so
oops: /usr/local/lib/janet/jaylib.so: undefined symbol: janet_getkeyword

Added repro.c to the repro repo.

sogaiu commented 3 years ago

Sorry for the confusion.

IIUC, this sort of thing:

(defn main [& args]
  (require "jaylib"))

not working is not an error (for a declare-executable situation) and is unrelated to the original issue.

That won't work with the latest release of janet and the older jpm either.

sogaiu commented 3 years ago

It may be that https://github.com/janet-lang/janet/issues/753 will take care of this issue.

saikyun commented 3 years ago

I tried sogaiu's fix, and it works for me. :)

sogaiu commented 3 years ago

It looks like https://github.com/janet-lang/janet/commit/a78cbd91dad1066ec82c31cb74b6c4bf2ea44d1b addressed https://github.com/janet-lang/janet/issues/753.

Perhaps this issue can be closed?

saikyun commented 3 years ago

Yup, works now. :) Thanks for the fix sogaiu and bakpakin. ^^