Using Linux Static Library with JS-Ctypes - jsctypes

I have created a Static Library in Ubuntu 12.04 and want to use the Library using JS-Ctypes.
My JS code is :
try {
var libc = ctypes.open("/lib/i386-linux-gnu/libtestfn.a");
alert("JSCtype - after open1");
}
Unfortunately the open fails and exception is thrown. Same code works for other System libraries like libc.so.6.
Any pointer to solve this issue.
Thanks in advance

jsctypes internally uses dlopen() to load the library (on Unix), so only dynamic libraries can be loaded. Simply re-compile your code as a dynamic shared library and it will load just fine.

Related

The procedure entry point_gxx_personality_sj0 could not be located in the dynamic link library c:\sfm\sfml\sfm-graphics-d-2.dll

I am trying to install SFML(2.5.1) in CODEBLOCK(20.03) with and currently using windows 8.1. I have downloaded sfml-tdm-sjlj-32 bit as per the tutorials that I saw in the web. I did all the set-ups and declared all the linkers properly but unfortunately it gave me error asking for libgcc_s_sjlj-1.dll not found so I downloaded it and added to my CODEBLOCK environment. After doing so I build and debugged a code that I got from SFML::CODEBLOCK tutorial just to test it but it gives me the following error -
The procedure entry point_gxx_personality_sj0 could not be located in the dynamic link library c:\sfm\sfml\sfm-graphics-d-2.dll
thank you in advance :)
Don't mix gcc exception models. Your environment probably uses Dwarf and now you want to use a library compiled with a GCC that uses SJLJ. Even if you get it to link it's likely to crash if there is any C++ code in there. Best is to use SFML compiled with the same compiler the rest of your environment uses, or even build it from source.

Qt - linking an external static lib that uses WinBase

I'm trying to build a GUI using Qt 5.3.1 and having that link to a static lib (built with VisualStudio 2010 using /MD and /MDd). When linking in QtCreator IDE, I get 2 unresolved external linker errors generated from these two function calls from within the static lib.
Both of these (unresolved) functions are declared in WinBase.h.
::InitializeSecurityDescriptor
::SetSecurityDescriptorDacl
What is the easiest solution to get QtCreator to compile this lib? Ideally if possible, I'd like to also link whatever dependency in the static lib itself.
As the documentation of both functions specifies, you have to link against advapi32.lib. In general, all functions of the Windows SDK specify in a box at the end of the documentation the header where they are declared, the header that you should actually include and their import library.
As for the other dependencies, AFAIK there's no way to know - static libraries are just collections of object modules, that specify their dependencies only in terms of imported functions.

Load Statically Linked GStreamer Plugin

I'm working on software for an embedded system that uses GStreamer 0.10.36. My goal is to keep the software as small as possible in terms of Flash memory space, so I'd like to statically linking the GStreamer plugins I need. According to the Core Reference Manual:
"There are options to statically link plugins to an app or even use
GStreamer without a plugin repository in which case gst_plugin_load()
can be needed to bring the plugin into memory. "
Unfortunately, it's not clear to me exactly what I need to do to bring the plugin into memory such that a subsequent call to gst_element_factory_make() completes successfully.
I'm doing the following:
Building GStreamer with --enable-static and --disable-registry set.
Linking the static library into my application
Call gst_element_factory_make() to create an element
Right now I'm only doing this for one plugin (tcpclientsink) out of several as an experiment. I had to edit the Makefile for that plugin to remove a --disable-static statement to get the libgsttcp.a file to build. I assume the library is good, but I'm not sure if there is a good way to verify that. gst-inspect does not appear to work on static libraries.
Note: If I call load_gst_plugin(/path/to/libgsttcp.a), GStreamer fails to load the plugin because of an invalid ELF header.
How does one load a statically linked GStreamer library?
I made an app in which all plugins are compiled inside the app (so it is self-containing)... Maybe this is another option for you, or do you really need to link to the library?
I got my usual code (plugin.c and plugin.h) that I used to compile the plugins in a shared library. I add an extra wrapper header that containts static registration code
static gboolean myplugin_init(GstPlugin * plugin)
{
gboolean ret;
gst_controller_init(NULL, NULL);
GST_DEBUG_CATEGORY_STATIC (gst_myplugin_debug);
GST_DEBUG_CATEGORY_INIT(gst_myplugin_debug, "myplugin", 0, "description");
ret = gst_element_register(plugin, "myplugin", GST_RANK_NONE, GST_TYPE_MECIMOTION);
return ret;
}
void gstmyplugins_register_static()
{
gst_plugin_register_static(
GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"myplugin",
"description",
myplugin_init,
"0.0.1",
"LGPL",
"myplugins",
"GStreamer",
"http://gstreamer.net/");
gst_plugin_register_static(
...
}
then inside the code for my app i call this registration:
gstmyplugins_register_static();
then continue with
gst_element_factory_make("myplugin", NULL);
hope this helps.
With some help from the GStreamer developers I found the answer.... don't use version 0.10.36. :)
Basically the ability to build static plugin libraries was added/fixed in later versions. To get it to work in 0.10.36, I've had to back port changes from the GStreamer SDK and GStreamer 1.x into 0.10.36. Things are still a work in progress, but I am able to build libgstcoreelements.a and statically link with it. If I wasn't already building a modified version of 0.10.36, I probably would have just used the SDK.
Update
I created static versions of all of the libraries I'm using. My GStreamer library is now a bit of a hybrid between 0.10.36, the SDK, and 1.2.2, but it works. I wouldn't recommend this solution for anyone though. Use the SDK or version 1.x.

Linking against WinNLS

What static library should I use to link against to use the NormalizeString() function?
In contrast with most functions documented on MSDN, the static library required to use the function is not declared. I tried using the name derived from the DLL: normaliz.lib and it successfully linked, but then I get a pop-up at runtime saying Normalization.dll could not be found on my computer and the process is shut down.
As pointer out by Hans Passant, the correct import library is normaliz.lib. It seems there was some problem in my setup.
I was using Windows SDK v6.0A. After switching to Windows SDK v7.0A, my problems stopped.
The link at the bottom-ish of the page you linked states that the download contains implib and dll resources. You probably have to manifest the dll, or at least put it into PATH.

Compile dynamicaly linkable libraries

I'm currently trying to compile dynamicaly linkable libraries, which would link during run-time with an application I'm writing.
I'm not sure how these libraries are called, so just to be sure : they're those libraries you load not during compilation, but during runtime using :
- dlopen / dlsync using libdl
- LoadLibrary / (another one with a complicated name) using Windows.
The thing is I can't find a CMake-way to compile those librairies under Windows : using Linux, this works perfectly :
set(libName myLib)
set(srcFiles myLib.cpp)
add_library(${libName} MODULE ${srcFiles})
Still, running Windows, it doesn't work at all : the Makefile is trying to link some pieces of code the myLib.cpp is referencing to (but it shouldn't... those symbols should be resolved at runtime).
I'm using the CodeBlocks MinGW generator if it may helps.
I think this would help:
add_library(${libname} SHARED ${srcfiles})
As CMake documentation says, MODULE should be used for building libraries that should be dynamically loaded using dlopen-like functionality. On Windows use SHARED instead of MODULE.

Resources