flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > How to use asmlib with mingw? (c++ and asm linking)

Author
Thread Post new topic Reply to topic
vivik



Joined: 29 Oct 2016
Posts: 671
vivik 02 Aug 2017, 14:23
I tried this library http://www.agner.org/optimize/#asmlib

mingw doesn't support .lib files, so I converted it to .a using "Object file converter" from the same page. I used command "objconv -felf32 -nu libacof32o.lib libacof32o.a".

I moved resulting .a file in the directory with all other .a files, and added -lacof32o linker flag.

mingw showed error "undefined reference to MersRandomInit" in asmlibran.h. Probably issue is in name mangling.

If somebody knows where I can copypaste random number generator from, please share.


Last edited by vivik on 03 Aug 2017, 12:48; edited 1 time in total
Post 02 Aug 2017, 14:23
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 671
vivik 03 Aug 2017, 12:48
Removed header, c file now looks like

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

extern "C" {
int MersenneBRandom();
}

int WINAPI
main(void)
{
return MersenneBRandom();
}

still says undefined reference.

If I remove libacof32o.a, it clearly complains "ld.exe cannot find -lacof32o". So it sees file itself, but not sure what it sees inside.


If i unpack libacof32o.a and disassemble mersenne32.o from there using "objconv -fnasm mersenne32.o mersenne32.o.asm" command, it shows this among other things:

MersenneBRandom: ; dword
db 0B9H ; 056B _ .
dd MersenneInstance ; 056C _ 00000000 (d)
dd 0FFFC6FE9H ; 0570 _ -233495
db 0FFH ; 0574 _ .


I'm going to google every exe in my C:\msys64\mingw32\bin untill I find which one is related to linking and object files.
Post 03 Aug 2017, 12:48
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 671
vivik 03 Aug 2017, 13:07
Tried compiling with command "g++ main.o mersenne32.o", resulted in "undefined reference to `InstructionSet'"

Tried compiling with command "g++ main.o libacof32o.a", ended as usual.
Post 03 Aug 2017, 13:07
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 671
vivik 03 Aug 2017, 13:13
"objdump -t mersenne32.o" shows this, among others

0000056b g O .CODE 00000004 MersenneBRandom
Post 03 Aug 2017, 13:13
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 671
vivik 05 Aug 2017, 17:52
My mainCRTStartup function looks like _mainCRTStartup@0 in object files. Thought I used C compiler, why is there still name mangling in it. I thought it was a C++ thing.
Post 05 Aug 2017, 17:52
View user's profile Send private message Reply with quote
pber



Joined: 23 Jul 2017
Posts: 24
pber 11 Aug 2017, 22:39
strcmp is surprisigly faster than gcc 4.8
thanks for the hint vivik.

but... why you dont simply recompile?
Post 11 Aug 2017, 22:39
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2559
Furs 14 Aug 2017, 11:27
Do you even export the function? Either a .def file or __declspec(dllexport) would work with MinGW. When importing it, of course you need __declspec(dllimport). So if it's an asm function then use __declspec(dllimport) in the C header so it imports it.

There is name mangling because of the Win32 API using stdcall -- and mainCRTStartup being stdcall as well.
Post 14 Aug 2017, 11:27
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.