Article View: comp.unix.programmer
Article #3542g++: Shared library, mapfiles, execution speed
From: Fred Ma
Date: Thu, 13 Mar 2003 21:00
Date: Thu, 13 Mar 2003 21:00
47 lines
3288 bytes
3288 bytes
Hello,
I'm converting a C++ program into a function that can be
called by an external application. Specifically, I will be
invoking it from a scientific computation package called
Matlab. It needs my program (main converted into an
actual function) to be compiled with the "gcc -shared"
option, which creates position-indepedent code.
My question is: is execution speed or optimizability
(gcc -O) affected by -shared? I'm not too sure how to
compare shared vs. nonshared. My experience in the
past has been just to compile without shared. In that
case, calling the program is straightforward. Just type
the name of the executable. With matlab, however, I
compile it using their compiler (which does alot of other
things beside just invoking gcc). In particular, they add
extra switches:
-shared
-Wl,-M,${MATLAB}/extern/lib/sol2/mexFunction.map
The -shared is obvious, and the -Wl is for the linker.
I never used the linker explicitly before, relying on gcc to
pull it all together. Now, I'm looking at "man ld", which
is the sunOS5.8 man page, and I'm not sure if it is the same
one that gcc uses. Is there any reason to think otherwise?
In the end, I'm still left with the question of how to
invoke a shared library function outside of matlab.
This is for the sake of speed comparison with the
nonshared version, as the nonshared version is run
from outside of matlab.
To get a grip on shared functions, I looked at the ld man
page for the above -Wl switch. It talks about mapfiles, and
refers to "Linker and Libraries Guide" for an explanation,
which I found on the web. It's one hefty document. All I
want to know is whether execution speed and optimizability
is affected. I don't intend to actually dabble with the linker.
Could a kindly programmer provide some expert commentary
on this? I'm using g++ 3.2.1 on solaris 8. Matlab r13 (though
I doubt that matters).
Thanks.
Fred
Technical Details
Message-ID:
<3E70F170.B4EE8B07@doe.carleton.ca>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!snoopy.risq.qc.ca!torn!webster!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,e2dd6c17ce56ca38,start X-Google-Attributes: gid11318c,public X-Google-Thread: 106e3f,e2dd6c17ce56ca38,start X-Google-Attributes: gid106e3f,public X-Google-Thread: fc89c,e2dd6c17ce56ca38,start X-Google-Attributes: gidfc89c,public X-Google-Thread: 11035d,e2dd6c17ce56ca38,start X-Google-Attributes: gid11035d,public X-Google-ArrivalTime: 2003-03-13 13:10:20 PST Message-ID: <3E70F170.B4EE8B07@doe.carleton.ca> From: Fred Ma <fma@doe.carleton.ca> X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.unix.programmer,gnu.gcc.help,comp.soft-sys.matlab,comp.unix.solaris Subject: g++: Shared library, mapfiles, execution speed Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 48 Date: Thu, 13 Mar 2003 16:00:32 -0500 NNTP-Posting-Host: 64.230.67.212 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1047589454 64.230.67.212 (Thu, 13 Mar 2003 16:04:14 EST) NNTP-Posting-Date: Thu, 13 Mar 2003 16:04:14 EST Organization: Bell Sympatico Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!snoopy.risq.qc.ca!torn!webster!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail