Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Executable as DLL
Executable as DLL [message #31384] Sun, 27 February 2011 06:23 Go to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Executable can be used as DLL. No changes to UPP is required. A proof of this is attached.

Explanation of how this can be done on Windows.

1) Create an application, which uses UPP. Let's name it exe_dll.
#include <Core/Core.h>

using namespace Upp;

extern String test_function(int i);

CONSOLE_APP_MAIN
{
	Cout() << test_function(1) << EOL;
}


2) Export required symbols via def file
EXPORTS
        ?FormatInt@Upp@@YA?AVString@1@H@Z
        ?MemoryAlloc@Upp@@YAPAXI@Z
        ?MemoryFree@Upp@@YAXPAX@Z
        ?LFree@String0@Upp@@AAEXXZ


3) Compile application. This will create an exe_dll.lib export library.

4) Create a DLL, which is not using UPP. Let's name this DLL test_dll.
#include <Core/Core.h>

using namespace Upp;

__declspec(dllexport) String test_function(int i)
{
	return FormatInt(++i);
}

Although Core.h is included, DLL itself is not linked against UPP.

5) Link test_dll against exe_dll.lib. As a result you will get a test_dll.lib library.

6) Link exe_dll application against test_dll.lib.

7) run exe_dll.

This is a long way. But I believe this work-flow can be automated.

I hope this approach will be useful for the UPP community.
  • Attachment: exe_dll.zip
    (Size: 166.21KB, Downloaded 346 times)


Regards,
Novo
Re: Executable as DLL [message #31391 is a reply to message #31384] Sun, 27 February 2011 13:05 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

This is very interesting idea with a lot of potential...

I tried to get some more info about how to achive similar thing in Linux and I came to this article on gcc wiki. It suggests a way how to (platform independently) separate public API from internal stuff, which I think could help a lot with making this automated.

Honza
Re: Executable as DLL [message #31393 is a reply to message #31391] Sun, 27 February 2011 19:45 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
dolik.rce wrote on Sun, 27 February 2011 07:05

This is very interesting idea with a lot of potential...

I tried to get some more info about how to achive similar thing in Linux and I came to this article on gcc wiki. It suggests a way how to (platform independently) separate public API from internal stuff, which I think could help a lot with making this automated.

Honza


This should be even easier on Unix because we do not need export libraries. The only problem is how to export required symbols. GCC linker doesn't export anything by default. This situation can be reversed by using -Wl,-E option. In this case all symbols will be exported. But we do not need all of them because this can affect performance and loading time as mentioned in the article.
I checked this linker option with a simple console application and got 374088 versus 587080 bytes of executable size. -fvisibility=hidden option doesn't seem to affect size of executable. This is strange.


Regards,
Novo
Re: Executable as DLL [message #31394 is a reply to message #31393] Mon, 28 February 2011 01:16 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
I figured out how to export limited set of names in Unix (ELF format).

We just need to use export maps. For example, one can create an export map file foo.map
{
global: name1; name2;
local: *;
};

and pass this file to linker via -Wl,--version-script=foo.map option.

Problem solved.


Regards,
Novo
Re: Executable as DLL [message #31449 is a reply to message #31394] Thu, 03 March 2011 16:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
How is this different from linking with DLL flag?
Re: Executable as DLL [message #31451 is a reply to message #31449] Fri, 04 March 2011 06:36 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
mirek wrote on Thu, 03 March 2011 10:55

How is this different from linking with DLL flag?


If you are linking a package with DLL flag you will get a DLL.
If you want to call functions from UPP in your DLL you need to link your DLL against UPP packages.
If you want to use UPP code in both application and DLL you need to link both application and DLL against UPP packages. In this case you will get duplicated code, two different memory allocators, e.t.c.
If you want to share UPP code between app and DLL, you will need to compile UPP itself as DLL and link against this DLL, what you do not want to do.

What I'm proposing is to use app as DLL because UPP code is already in there. You just need to export it.

Am I wrong?


Regards,
Novo
Re: Executable as DLL [message #31454 is a reply to message #31451] Fri, 04 March 2011 08:59 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Ah, I see. That is nice indeed Smile

Could be easily automated using coff package.

Mirek
Re: Executable as DLL [message #31470 is a reply to message #31454] Fri, 04 March 2011 20:16 Go to previous message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
mirek wrote on Fri, 04 March 2011 02:59

Ah, I see. That is nice indeed Smile

Could be easily automated using coff package.

Mirek


IMHO, coff package deals with internals of COFF format. Automation of "Executable as DLL" process requires filtering out mangled names of missed symbols, creating/updating of def or linker script file and relinking of application and DLL. Unless exporting of symbols can be done by using coff package, there is no need to use it. And, of course, we are missing an elf package.

On Linux we will just need to relink app with updated linker script.


Regards,
Novo

[Updated on: Fri, 04 March 2011 20:19]

Report message to a moderator

Previous Topic: TheIde SVN problem in windows 7
Next Topic: About Painter vs OpenGL
Goto Forum:
  


Current Time: Fri Mar 29 03:35:55 CET 2024

Total time taken to generate the page: 0.01445 seconds