Linux's way to run a function inside a dynamic library (.so) via command line - linux

Just wondering if there is a way to invoke a method inside a dynamic library without creating a process in Linux. In windows you can call from the command line something like rundll32.exe my_dynamic_library.dll,my_method and that will run the rundll32.exe process and it will load my_dynamic_library.dll and providing there is an exported method named my_method it will execute it. What I'm looking is to avoid having to create a separate project to wrap my .so into an executable when testing code that depends on a dummy process running my_dynamic_library.dll in the background (distributed system).

Related

Call function in OpenModelica

Is it possible to execute Modelica functions in OpenModelica without performing a simulation?
In Dymola I can call them from:
the package browser, using Call Function...
the command line, using the full class path
the script editor, again with the full class path
Is there anything comparable in OpenModelica?
Yes. In OMEdit,
the Libraries Browser, using Call function
the OpenModelica Compiler CLI under the Tools menu, using the full class path
Note that option 1 is only available in the latest version.

Is it possible to start a program with a missing shared library

I'm running Linux and have a situation like this:
A binary file 'bin1' loads via dlopen 'shared1.so' which is linked with 'shared2.so' and 'shared3.so'.
if 'shared2.so' or 'shared3.so' is missing the program 'bin1' won't run.
There are runs that I know that I won't touch any code from 'shared2.so' and I want 'bin1' to be able to run even when this library is missing, can this be done ?
You could ship program with dummy shared2.so library. You might need to add dummy functions which shared1 expects to find there. This can be done manually or via automatic tool like Implib.so.

CMake preload each test with a library

In our Linux application we use a library that is preloaded with LD_PRELOAD.
I'd like to have the same library preloaded for each test. We are using CMake as build tool.
Can I tell CMake that it should add LD_PRELOAD to the environment for each test that is executed.
Test are executed with make test.
Assuming you use add_test to register the individual tests, the most robust way to achieve this is to use test properties. The ENVIRONMENT property allows you to specify arbitrary environment variables that are being set for running the test:
add_test(NAME some_test COMMAND some_test_target)
add_test(NAME some_other_test COMMAND other_test_target)
set_property(TEST some_test some_other_test
PROPERTY
ENVIRONMENT LD_PRELOAD=/path/to/preload.so)
You also might want to escape the property with a generator expression to keep the tests portable to platforms that do not support LD_PRELOAD.

C++ Creating a standalone library in linux and using it in another program

I'm trying to create a shared library for Linux such that:
other programs can use its functions and its objects
the code is not visible to final user
What i did is create a shared library with Eclipse. This library uses pthreads.
I generated .so and .lib. The .lib is in LIBRARY/Lib while the .so is in LIBRARY/Release.
Then i created another project which should use this library and i gave the path of the .lib file and the path of the .h file which only contains the inclusions of all the necessary .h of the library.
All seems working but when i run the program it crashes. When debugging it I receive the following message:
Can't find a source file at "pthread_mutex_lock.c"
Locate the file or edit the source lookup path to include its location.
What's wrong? Can someone help me please?
EDIT: I changed nothing and now I have a different error, some lines before the previous:
Can't find a source file at "random.c"
Locate the file or edit the source lookup path to include its location.
other programs can use its functions and its objects
the code is not visible to final user
These two goals directly contradict each other, and achieving both at the same time is impossible on Linux.
If some program can use your library, then I can write a new program that can do so as well.

How do I ignore a system file picked up by `configure' generated from AC_CHECK_HEADERS

We using an automated build system which downloads and compiles source. The only interface I have to control the behaviour of the compilation is by setting ENV VARs and the arguments given to `./configure'.
The issue is that the 'configure' script (of the particular source I'm compiling) checks for a system header file, which if found, adversely affects the compilation process. (the compilation process will avoid compiling libraries which it believes are already installed on the local system when the above mentioned system header file is found.)
Since this is an automated process, I cannot modify the 'configure' script in anyway, and as mentioned can only specify the environment variables and arguments passed to `configure'. The configure script uses the AC_CHECK_HEADERS macro to generate the code to do the check for the system file. Is there anyway to avoid a check of a specific system file from the configure arguments?
The troublesome header file is in the path /usr/include/pcap/.
Thanks
Well there's a few things you could try:
remove foo.h from AC_CHECK_HEADERS and always build the library
use AC_CHECK_HEADER for foo.h and check for /usr/include/pcap/foo.h and don't AC_DEFINE(HAVE_FOO_H) if /usr/include/pcap/foo.h is there.
you could use AC_ARG_ENABLE or AC_ARG_WITH to turn off the offending test on a host-by-host basis via arguments to configure. So the answer to that question is yes.
All of these assume you can modify configure.ac and regenerate configure. If you can't do that you might have to modify configure (in an automated fashion, of course).

Resources