flat assembler
Message board for the users of flat assembler.

Index > Windows > Export routine problem

Author
Thread Post new topic Reply to topic
emil



Joined: 16 Dec 2003
Posts: 76
Location: egypt
emil 08 Dec 2007, 17:46
Hi All

I am working in creating a DLL with MinGW C++ , and have some asm routines that I want to merge them with my DLL.

The problem is how to export the asm routines to produce obj file that I can link with ?

Any help please.
Post 08 Dec 2007, 17:46
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 08 Dec 2007, 18:01
Code:
format MS COFF

public ret5 as '_ret5'

section '.code' code executable readable

ret5:
mov eax,5
retn    
Post 08 Dec 2007, 18:01
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
emil



Joined: 16 Dec 2003
Posts: 76
Location: egypt
emil 08 Dec 2007, 18:10
Thanks vid for fast reply.

But the routine ret5 did not appear in my DLL file.

I have put this in my header file of my DLL

__declspec(dllexport) int ret5 ( void );

And link with yor code but as I said it did not appear.

So what could be the problem?
Post 08 Dec 2007, 18:10
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 08 Dec 2007, 18:38
You could use some kind of command line argument or module definition file to export function, instead of __declspec(). But I don't know how to do this with MinGW.

If you linked with that file, and exported "ret5", then it should appear. Linker may silently ignore it, if you didn't export "ret5" properly.
Post 08 Dec 2007, 18:38
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
emil



Joined: 16 Dec 2003
Posts: 76
Location: egypt
emil 08 Dec 2007, 19:46
Vid I am afraid, I did not think so.

ok look.

I have made a tow functions in C++ , exported one of them and the other did not. Then compiled them to produce the Obj file by Mingw, then opened them with HexEditor program and found that the exported function was marked as export function with a prefix word “ –export:’ i.e “–export:functionName” . the other one was not .

So I think you have to supply some extra information in the Obj file to tell the linker that there are some export functions those must be in the final DLL.

Any help please?
Post 08 Dec 2007, 19:46
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4205
Location: vpcmpistri
bitRAKE 08 Dec 2007, 21:24
The OBJ file can have commands for the linker embedded in it, but FASM does not do this - the "-export:" is a command for the linker, IIRC. You will need to supply the linker with the "-export:" commands.
Post 08 Dec 2007, 21:24
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8376
Location: Kraków, Poland
Tomasz Grysztar 09 Dec 2007, 00:01
bitRAKE wrote:
The OBJ file can have commands for the linker embedded in it, but FASM does not do this

fasm does not do only when it's not told to. Try this with MS COFF output:
Code:
section '.drectve' linkinfo linkremove
 db '–export:functionName '     
Post 09 Dec 2007, 00:01
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4205
Location: vpcmpistri
bitRAKE 09 Dec 2007, 00:45
That is very helpful! I was unaware of the ".drectve" section. It is good to include all the requirements within the source file. Thank you.
Post 09 Dec 2007, 00:45
View user's profile Send private message Visit poster's website Reply with quote
emil



Joined: 16 Dec 2003
Posts: 76
Location: egypt
emil 09 Dec 2007, 06:30
Thanks Tomasz Grysztar

I think it needs more information or something else because I got this warning from the linker

Warning: .drectve '–export:functionName ' unrecognized

Any help please ?
Post 09 Dec 2007, 06:30
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4205
Location: vpcmpistri
bitRAKE 09 Dec 2007, 08:55
functionName needs to be the name of your label (i.e. ret5).
Post 09 Dec 2007, 08:55
View user's profile Send private message Visit poster's website Reply with quote
emil



Joined: 16 Dec 2003
Posts: 76
Location: egypt
emil 09 Dec 2007, 15:20
Of course it is the real name of the function , I am do aware of that.

I have changed it only in the post.
Post 09 Dec 2007, 15:20
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 09 Dec 2007, 16:03
emil: post that object file here, so we can look at it
Post 09 Dec 2007, 16:03
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
emil



Joined: 16 Dec 2003
Posts: 76
Location: egypt
emil 09 Dec 2007, 16:41
Ok vid

Here is the asm file and the obj , it is your first example.

http://bcxdx.spoilerspace.com/Ogre/ExportProblem.zip

still has the linker error.
Post 09 Dec 2007, 16:41
View user's profile Send private message Reply with quote
emil



Joined: 16 Dec 2003
Posts: 76
Location: egypt
emil 09 Dec 2007, 17:10
Ok , I am thinking in make the main DLL in asm and merge the OBJ files from Mingw C++ and export there functions in asm file just like the DLL example that comes with fasm.

The question is , does fasm accept obj file from Mingw C++ , and if so how to do that with fasm?
Post 09 Dec 2007, 17:10
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.