Giter Club home page Giter Club logo

Comments (10)

bjorn3 avatar bjorn3 commented on June 8, 2024

Try setting LD_LIBRARY_PATH to the absolute path to the directory that contains your dylib.

from evcxr.

baiguoname avatar baiguoname commented on June 8, 2024

Try setting LD_LIBRARY_PATH to the absolute path to the directory that contains your dylib.

Thanks for your help, I just tried what you said and got the same error.
When I use the function adding_from_Library in another program with command cargo run, the function works fine. But it doesn't work in notebook. I think it might be related to the method cargo_command from eval_context.rs. The generated command may lose something so the compiler cannot find the library.

from evcxr.

bjorn3 avatar bjorn3 commented on June 8, 2024

Does it work if you use

:env LD_LIBRARY_PATH=/path/to/dynlink/library
:restart

?

from evcxr.

baiguoname avatar baiguoname commented on June 8, 2024

Does it work if you use

:env LD_LIBRARY_PATH=/path/to/dynlink/library
:restart

?

I just tried what you said, and still got the same error.
Then I copied the libawesome_math.so file to the directory path_to_tmpdir\target\x86_64-unknown-linux-gnu\debug\deps, and still got the same error. I'm curious why this error happen, doesn't the compiler find the shared object in this directory. If it does, why the compiler cannot find the shared object?

from evcxr.

bjorn3 avatar bjorn3 commented on June 8, 2024

The error happens after compilation. It happens when evcxr attempts to dlopen the dylib is compiled for the user code. It finds the dylib, but then the dynamic linker doesn't find where libawesome_math.so is. Setting LD_LIBRARY_PATH should tell the dynamic linker in which directory it can find it, but for some reason that doesn't help for you.

from evcxr.

baiguoname avatar baiguoname commented on June 8, 2024

The error happens after compilation. It happens when evcxr attempts to dlopen the dylib is compiled for the user code. It finds the dylib, but then the dynamic linker doesn't find where libawesome_math.so is. Setting LD_LIBRARY_PATH should tell the dynamic linker in which directory it can find it, but for some reason that doesn't help for you.

Is there way that I copy the libawesome_math.so file to a specific location, so that the compiler can find it?

from evcxr.

bjorn3 avatar bjorn3 commented on June 8, 2024

The dynamic linker should look in /lib, /usr/lib, /usr/local/lib (only writable as root and I strongly recommend not to add any files here, but if you do anyway prefer /usr/local/lib. that one is not under the control of your distro's package manager) and all the directories mentioned by LD_LIBRARY_PATH. Can you check if println!("{:?}", std::env::var("LD_LIBRARY_PATH")); does mention the LD_LIBRARY_PATH you tried to set?

from evcxr.

baiguoname avatar baiguoname commented on June 8, 2024

The dynamic linker should look in /lib, /usr/lib, /usr/local/lib (only writable as root and I strongly recommend not to add any files here, but if you do anyway prefer /usr/local/lib. that one is not under the control of your distro's package manager) and all the directories mentioned by LD_LIBRARY_PATH. Can you check if println!("{:?}", std::env::var("LD_LIBRARY_PATH")); does mention the LD_LIBRARY_PATH you tried to set?

When I run this cell in notebook:

std::env::var("LD_LIBRARY_PATH")
//output: Ok("/root/dynlink/library")

I put the libawesome_math.so in /usr/lib, and deleted the build.rs file. Then I cd into directory dynlink/executable and ran cargo run, and got this error:

/root/dynlink/executable/src/lib.rs:7: undefined reference to `from_the_library'

It seems the putting the .so file in /usr/lib doesn't work on my computer.

from evcxr.

davidlattimore avatar davidlattimore commented on June 8, 2024

I tried creating a directory structure like you said and I got a different error. For me the error wasn't that it couldn't find the .so file, it was that it couldn't find the symbol. I'm not sure what you were doing to get it to try to load the .so file. I got it to load it by adding #[link(name = "awesome_math")] before extern in lib.rs.

I've attached a .tar.gz of the directory structure that worked for me. I didn't use LD_LIBRARY_PATH, but instead set rpath like you were doing in one of your earlier attempts.

358.tar.gz

from evcxr.

davidlattimore avatar davidlattimore commented on June 8, 2024
❯ ~/work/evcxr/target/debug/evcxr
Welcome to evcxr. For help, type :help
>> :dep executable = { path = "executable" }
   Compiling libc v0.2.151
   Compiling cc v1.0.83
   Compiling executable v0.1.0 (/home/david/tmp/358/executable)
>> executable::adding_from_library()
()
Adding: 3

from evcxr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.