Cannot load lua dll module - windows

I cannot load a lua module, which is a 32bit c++ dll.
The lua module and the lua code is in the same folder.
in c++ code:
extern "C" __declspec(dllexport) int luaopen_luartmidi(lua_State *L) {
...
}
lua first line:
local luartmidi = require 'luartmidi'
When i run the lua code with vs code lua 32bit debugger i get
error message:
Exception has occurred: [C]:-1: error loading module ... from file ...
The specified function could not be found
Dependency Walker says LUA.DLL is missing. When i copy lua.dll in the same folder i get error
c:Users/xyz/.vscode/extensions/actboy168.lua-debug-1.23.1/runtime/win32/lua53/lua.exe: multiple Lua VMs detected

This happens when you link with a lua interpreter statically and then try to load an external module that links against a Lua DLL (and expects a lua.dll or similarly named library to be present). You can't both have a statically compiled interpreter and one loaded from a DLL to be present in the same process (the "multiple Lua VMs detected" message is triggered by a check against this condition).
You have three options:
Compile everything statically (don't load any external modules)
Compile everything dynamically (don't link the Lua interpreter statically)
Use a proxy library that will forward API calls from external libraries to statically linked Lua interpreter (will require exporting Lua symbols and writing a proxy library). See http://lua-users.org/wiki/LuaProxyDllFour links for the code and details (it's for Lua 5.1, but you can tweak the script for Lua 5.3).

Related

Rust linker seeks a LIB, rather than a DLL

I'm experimenting with Rust on Windows. My code declares and calls a function in an external library.
The declaration is like this:
#[link(name = "Rvea0326nc-64")]
extern "C" {
fn WeibullSpeedProbability(wa: &f32, wk: &f32, qu: &f32, prob: &f32, theerr: &i32) -> ();
}
(It's all ByRef because the DLL is Fortran. It's built with the Intel compiler.)
Note that the file name has no extension. The DLL is in the \target\debug\deps folder of the Rust project.
According to the documentation here
https://doc.rust-lang.org/std/keyword.extern.html, this should import a DLL on Windows, but I get an error, thus:
error: linking with `link.exe` failed: exit code: 1181
<SNIP>
= note: LINK : fatal error LNK1181: cannot open input file 'Rvea0326nc-64.lib'
Sure enough, if I find and copy in the *.lib file from which the DLL was generated, everything works fine. The DLL is apparently irrelevant.
I have tried explicitly adding ".dll" to the link name, but Rust just complains that it cannot find Rvea0326nc-64.dll.lib.
Is the documentation wrong? Have I missed something? Is there a way to get Rust to work with the DLL?
Update: I found that when running the Rust-compiled executable directly, the DLL is required and the LIB is not.
Without having too much experience with FFI in Rust, I can imagine to compile your program, you will need the .lib installed on your machine, so that rustc can correctly check that the FFI function is correct. Then when the produced binary is run, it loads the .dll at runtime and uses it.
Try to see if after producing a binary with the .lib installed, that you can run that binary without the .lib installed.

How to export kernel functions which written in assembly?

I am working with a PowerPC processor and have to use dcache functions in my kernel module, like: "clean_dcache_range()", implemented in $KERNEL_SOURCE/arch/powerpc/kernel/misc_32.S. this assembly file is compiled during kernel compilation (version 4.1.8) and misc_32.o object file exists in kernel build directory.
However, i can't use this functions in my kernel module and the error "implicit declaration of function" appears when i compile the module using gcc.
Also, the Module.symvers file does not contain these functions.
Note that, the mentioned functions are declared as _GLOBAL.
So, what is the problem and how can i solve it?

dlopen - cannot open shared object file

I'm compiling a shared library with gcc and loading it using dlopen. I also pass the following to the compiler:
-fvisibility=hidden
When I compile the library WITHOUT the visibility flag, everything works perfectly. However, when I compile WITH the flag, I get the following error with dlopen:
libtest.so: cannot open shared object file: No such file or directory
The linbrary .so file exists! This seems weird to me, since if some symbols are hidden, I would expect dlsym to fail if something cannot be found. However, this already fails when loading the library (aka dlopen).
I also tried adding
__attribute__ ((visibility ("default")))
to the functions I later call (extern "C"), without any success. Does anyone know what I can do about this? Or alternatively, is there any way to debug this to figure out why dlopen fails? I do not want to remove the visibility flag, since his drastically reduces my executable size.
My lib was depended on another lib that could not be found.
You may use ldd to see the list of all dependencies, including missing.
ldd libtest.so

Importing external library to Veins

Morning,
I would like to import my own library to Veins (v4.4) project.
I followed this tutorial to compile a shared library.
I've also stripped the shared library with this command:
strip --strip-unneeded libfoo.so
since I've noticed that system libraries such as sqlite3 are compiled in stripped mode.
Then I imported the library from
1.Project->Properties->Paths and Symbols :
1.1 includes
1.2 Libraries
1.3 Library Paths
2.Makemake-> Src->Options->Link-> Additional Libraries
However, the problem is that when I use the imported library I still get an error of "undefined symbol "; so I suppose the library is not correctly imported or read by the simulator.
Any suggestion?
Thanks for helping
How to load additional libraries in your simulation is documented in the user manual's chapter on running simulations.
In brief, you will need to add -l foo to the command line parameters to make the simulation load libfoo.so when it starts.
If you use the IDE to start the simulation, you can edit your simulation's run configuration: Choose menu item Run > Run Configurations..., then on the Main tab click on More >>, append the name of your library (e.g. foo if your library is called libfoo.so, or foo bar if you want your simulation to load libfoo.so and libbar.so on startup) to the Dynamic libraries text field. After launching, you will see the aforementioned command line parameter -l foo being used by the IDE to run the simulation.
If you are unsure about where to put your library, a related question has a discussion on this: <!> Error during startup: Cannot load library in OMNET++ project while using sqlite3

Use 'dfwin' Fortran library with gfortran

I try to load dynamically DLL library in fortran, so I need to use loadlibrary and getprocaddress function from dfwin library.
But when I compile this:
program helloworld
use dfwin
end
I just got:
Fatal Error: Can't open module file 'dfwin.mod' for reading at (1): No such file or directory
Can I install or link in any way dfwin module to gfortran GCC compiler ?
No. The mod file generated by a compiler is specific to that compiler (in some cases, specific to a compiler version).
(Even if you had the source for the dfwin module, it uses extensions that are specific to the DEC/Compaq/Intel compiler lineage.)

Resources