c++dl.readme
来自「《Linux程序设计权威指南》源代码」· README 代码 · 共 70 行
README
70 行
Content-Type: text/plain; charset=us-asciiContent-Transfer-Encoding: 8bitMIME-Version: 1.0Date: Thu, 11 Jun 1998 13:57:15 +0100 (IST)Organization: Interactive Design CenterXFMstatus: 0001From: Caolan McNamara <Caolan.McNamara@ul.ie>To: ilug-l@ul.ieSubject: re: librarieson the topic of shared libraries, i thought idjust mention an idea close to my heart.there are linux and solaris calls dlopen and friendsthat allow you to at runtime from inside yourown code open explictly a shared library andexecute the code found there, theres anexample in the dlopen manpage. so forinstance you could have a widget library thatconsists of a scrollbar shared library, a buttonshared library etc, and the program rather thanbeing linked to these libraries actually explicltyopens the button shared lib and runs the buttonstuff, so from a menu you could selectwhich of multiple button libs, each with a utterlydifferent look and feel that you want your program touse. pretty snazzy eh ? the point of this mail though is that its bitch difficultto do this with c++, when you open the lib withdlopen in c you basically search for a function named for instance foo and then run it, with c++ if you had a functionnamed foo, then compiled to a lib foo becomes dueto name mangling foo_int23qwe_ug_addh or some othernonsense, so you cant just find the function youwant with dlsym when c++ does its bizz to it, and ifyou want to get a handle to an object etc you mightas well piss against the breeze, but there is a wayout of the problem if you have *one* c call protectedwith extern C in the shared lib that returns a pointerthe the object. now the name doesnt get mangled soyou can find it with dlsym, and you get a handle to thepointer so you're off. of course as the program youcall dysym from isnt actually linked to the programit wont actually have any knowledge of the object beingpassed to it, so you cant use the object unless you havea common parent class that the shared lib inherits from and thatis visible to the dlopen code. so what you have now is a parent class definition that the code using dlopen has included, and that the object that the extern C protected call in the shared lib will return is basedon so you can use the baby. from the dlopen calling code theonly methods you can call directly on the returned objects are onesthat had definitions in the base class, this is a big limitation, butit still allow a mechanism where a program can at run time with c++, swap inand out widget modules, change the style of buttons its using at thedrop of a hat, any program using such a lib would be fully configurable. Imnot too sure whether something like this is of *any* use, but its a damn coolidea. it all works pretty well in theory, and a sample chunk code thatdemonstrates the basic code for the concept is athttp://www.csn.ul.ie/~caolan/docs/dynamic.htmlive also gotten it to work with cygnus's windows library as well, so the samething is possible under windows.C.Real Life: Caolan McNamara * Doing: MSc in HCIWork: Caolan.McNamara@ul.ie * Phone: +353-61-202699URL: http://skynet.csn.ul.ie/~caolan * Sig: an oblique strategyGet your neck massaged
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?