Error loading wrapper for shared library in lua plugin

asked 2023-08-17 20:09:39 +0000

jerome gravatar image

I’m attempting to write a C wrapper for a shared library that would expose it to lua so that it can be called by a lua plugin.

I recreated the error with minimal code, using the following four files:

/usr/lib/x86_64-linux-gnu/wireshark/plugins/lua_test.lua: this is just one line, "require(c_wrapper)"

/usr/lib/x86_64-linux-gnu/wireshark/plugins/c_wrapper.c: this has the shared library's header file in its includes and exposes shared_lib's functionality (one function) to lua

/home/user/Desktop/shared_lib/shared_lib.c and shared_lib.h: these contain the shared_function (a void function that takes no parameters)

I compile shared_lib.c to shared_lib.so with the following command:

gcc -shared -o shared_lib.so -fPIC shared_lib.c

And compile c_wrapper.c to c_wrapper.so with:

gcc -O2 -fPIC -I/usr/include/lua5.2 -I/usr/Desktop/shared_lib -c c_wrapper.c -o c_wrapper.o

gcc -shared -o c_wrapper.so c_wrapper.o

And then I copied c_wrapper.so to /usr/lib/x86_64-linux-gnu/lua/5.2 so that Wireshark could find it (I also tried copying shared_lib.so to this directory but it didn't make any difference.)

When I run wireshark, I get the following error:

Lua: Error during loading:
error loading module 'c_wrapper' from file '/usr/lib/x86_64-linux-gnu/lua/5.2/c_wrapper.so':
    /usr/lib/x86_64-linux-gnu/lua/5.2/c_wrapper.so: undefined symbol: shared_function
stack traceback:
    [C]: in ?
    [C]: in function 'require'
    /usr/lib/x86_64-linux-gnu/wireshark/plugins/lua_test.lua:1: in main chunk

It looks like including the header for shared_lib wasn’t sufficient, as shared_function is the function from shared_lib that c_wrapper attempts to expose to lua. I’m not sure if doing this via a wrapper is even possible, or if I need to go in and modify the original code of the shared lib and expose it to lua directly.

I'm running Wireshark 3.6.2 on Ubuntu 22.04.1 VM with Windows host, gcc is version 11.4.0 and lua is version 5.2. Please let me know if there's any more information that would be useful. I tried to attach my files to this post but I'm a new user so I don't have permission to do so, but they're very short so if needed I could copy and paste the code into the question.

Any help is appreciated! Thank you for reading.

edit retag flag offensive close merge delete