how to tell the run-time loader not to run the constructor function when dlopen a shared library - constructor

From the manual of dlopen, I see
" Instead, libraries should export routines using the attribute((constructor)) and attribute((destructor)) function attributes.
See the gcc info pages for information on these. Constructor routines are executed before dlopen() returns, and destructor routines are
executed before dlclose() returns.
"
I do not want the constructor in a specific shared library to run automatically, while the ones in other shared libraries are not affected. Is there any way to achieve that?
Actually, I'm using dlopen, dlsym, dladdr to find the exact path of some shared library.

I do not want the constructor in a specific shared library to run automatically
Too bad: the library author decided that his library can't be used safely unless the constructors are run, and he has more say than you do.
Actually, I'm using dlopen, dlsym, dladdr to find the exact path of some shared library.
Are you saying that the only reason you dlopen that library is just so that you can find the absolute path to it?
If so, why do you care about the absolute path in the first place?

Related

Why does call to an undefined function does not give a compiler error and gives linker error in C?

If in a C program I call a function that is not defined or declared anywhere in the scope then I will get an error at the linking time but not at the compile time. I wonder why does this not generate an error at the compile time?
In C, like in other programming languages, the compilation process is made of two main steps:
Compiling
Linking
In the first step all the functions, with respective signatures (that are enough for the moment), must be declared and visibile in the scope of the caller. This step produces an object file, that is a file which contains a machine code, relocatable and not yet executable.
In the second and final step the object file is linked to the system and/or user libraries. Each declared function is now resolved to its implemented counterpart (now if it does not exist the linker generates the error) and made executable.
This is the reason.

Evaluate chaiscript file within a chaiscript file

I'm starting to learn chaiscript and couldn't find this in the documentation.
I know there is API to evaluate a chaiscript file from C++ by calling ChaiScript::eval_file
But is it possible to do the same from a chaiscript file?
From within ChaiScript the use function is available, but the eval_file is not. use only loads a file if it has not already been loaded. eval_file loads the file regardless.
use("use.inc")
assert_equal("hello", greet())
// Include it a second time and see if there are any errors
use("use.inc")
assert_equal("hello", greet())
From here: https://github.com/ChaiScript/ChaiScript/blob/master/unittests/use.chai
Documentation of the C++ implementation of this function is here: http://chaiscript.com/docs/5/classchaiscript_1_1_chai_script.html#a9fc2eaf37274d09d1ee90ffd411e665c
I don't see any documentation specifying that it's also exposed to the ChaiScript runtime, but you can see many of the functions that are exposed here: https://github.com/ChaiScript/ChaiScript/blob/master/include/chaiscript/language/chaiscript_engine.hpp#L318

Manifest for dependencies on items other than the main executable?

I'll explain what i'm trying to do (and why) first and then get more into the details.
I'm trying to get Registration Free COM activation working in the context of a language that is compiled JIT. I use Reg-Fre COM because i would like to avoid having to register my COM component and would like this application to be installable without administrative rights.
The JIT compiler is the main executable is signed and contains an embeded manifest. Latest versions of Windows prefer the embeded manifest over an external one, by default (it was the opposite on Windows XP).
Since the JIT is signed, i cannot extract/modify/update it's manifest without breaking the signing. Also, this would introduce complexity in the maintenance of our application (always making sure we embed a new manifest). And there's are also the legal implications of modifying a program for which i don't own the rights.
So, my idea was to try to get the WinSxS activation going thru a Win32 wrapper library for which i would provide a manifest that lists the dependencies. As a proof of concept, i decided to make a simple VB6 app, a C++ Wrapper Library and two COM library (1 in .NET and 1 in VB6).
The wrapper contains 3 methods, one that calls the VB6 COM, one that calls the .NET COM and one that returns a simple string.
As long as everything as my COM are registered, it works, of course.
If i unregister them, provide manifests for the COMs and add them as dependencies to the main executable's manifest, it works.
If i unregister them, provide manifests for the COMs and the C++ Wrapper and add the com as dependencies for the C++ Wrapper and then add the C++ Wrapper as the only dependency in the main executable's manifest, it works.
If i delete my main executable's manifest, the COM calls stop working but the simple string method still works.
Please note that for all my tests, i run a Powershell script that changes the Modified Date of all my files, making sure to trip the activation context cache (manifest).
From there, i started debugging using SXSTrace.exe and setting the COMPlus_LoadLogDir variable. I found out that if my manifest is external, it never gets taken into consideration. I also found out that if i embed it in the .DLL, sxstrace shows it is found, parsed and that the dependencies are found, their manifest found and i get the usual successful context activation lines in the log.
INFO: Parsing Manifest File C:\RegFreeComWrapper\bin\vbCom.MANIFEST.
INFO: Manifest Definition Identity is vbCom,type="win32",version="1.0.0.0".
INFO: Parsing Manifest File C:\RegFreeComWrapper\bin\netCom.MANIFEST.
INFO: Manifest Definition Identity is netCom,processorArchitecture="msil",version="1.0.0.0".
INFO: Activation Context generation succeeded.
End Activation Context Generation.
However, even tho the log says that, my COM calls still dont go thru.
When the call goes thru for the .NET COM call, i get some output in the COMPlus_CLRLoadLogDir configured path.
In this case, i don't get any output.
As soon as i add the manifest that only lists my C++ Wrapper as a dependency to my main executable, everything starts working again. I get a similar output from SXSTrace, but now the COM call works. As mentioned, in all cases, the C++ Wrapper's simple string method works. Meaning that even tho i have no manifest from my main executable, it can still find my .dll and call it.
Seems like the COMs don't work if i dont have the full manifest chain:
Application.Manifest > Wrapper.Manifest > COMs manifests
So, two things here...
1. Is the thing i'm trying to do even possible? (Having dependencies listed only in the manifest of a DLL that belongs to me, without touching the main executable's manifest)
2. If it is possible, i'm probably only missing a small thing to get everything going... what is it ? :)
I can provide all my code/executable as examples, should someone be interested in trying stuff with em.
Got it working!
I modified my C++ Wrapper to use the Activation Context API and force a context activation using 'ActivateActCtx'
http://msdn.microsoft.com/en-us/library/aa374151(v=vs.85).aspx
I wrapped my code with their example's code and made sure to reference my manifests and now all is working fine. No manifest on my main executable!

Failed to create shared library with wx and STL, "multiple definition" error?

I tried to build a shared library using wx and STL, and failed in an error of "multiple definition of". Please refer to:
https://code.google.com/p/gppanel/issues/detail?id=7
The declaration of wxPointListNode is not found in the sources. The suspicious lines are like these:
include/mathplot.h:85:WX_DECLARE_LIST(wxPoint, PointList);
include/mathplot.h:87:WX_DEFINE_LIST(PointList);
include/gpLineLayer.h:16:typedef std::deque<mpPointLayer*> mpPointList_t;
What the problem is?
Without the actual code this is just a guess, but I suspect that
include/mathplot.h:87:WX_DEFINE_LIST(PointList);
generates the full definition of PointList, including a non-templated method wxPointListNode::DeleteData. mathplot.h is included by all of the .cpp files (gpPanel.cpp, gpSeries.cpp, and baseData.cpp). Each cpp file is compiled into a .o file, so each has its own definition of DeleteData, and when you try to link the .o files together into lib/libgpPanel.so the linker issues the errors you're reporting.
The definition of the method needs to be in its own cpp file that's compiled and linked in.
All wxWidgets methods with DEFINE in their name expand into a definition of something and a definition can only be used once in a module, so it typically can't appear in a header file (unless you can guarantee that it's included by only a single source file). So just don't put it there.
Moreover, if this is your code, you should avoid using the legacy WX_DECLARE_LIST macro at all and just use std::list<> or std::vector<> instead. Or, if you really want to use only wx (which can only be important if you are targeting some embedded platform without good STL implementation), then use wxVector<>.

Actionscript : 1087: Syntax error: extra characters found after end of program

I tried importing a .as referring to my variable name/value
import "net.chars."+adc;
You can't dynamically import a path via a string, because AS3 imports occur as compile-time. They're simply directives to tell the compiler what classes/packages you're using, nothing more.
You might be able to use the getDefinitionByName function if you really need this functionality, as described in this answer. However, you should note that you still have to reference the class somewhere in your code, otherwise it won't get compiled into the SWF. Flash has no way of loading classes externally at runtime, so you have to ensure that the compiler knows to include it.
For more information, see this article.