NO

Author Topic: Import MingW DLL  (Read 5632 times)

Tino

  • Guest
Import MingW DLL
« on: March 22, 2013, 04:36:34 AM »
Hello Forum :)

I m trying to import a DLL from MingW wich export s a class using a C interface and virtual function pointers.
( based on this http://www.codeproject.com/Articles/28969/HowTo-Export-C-classes-from-a-DLL )

I added some Linux switches and changed the header so that it works with Pelles C,
but the problem is i fail to import the import-lib in Pelles C.

I tried the original .a and used polib to generate a .lib
but the linker completely refuse.


Any help would be appreciated :)

/Project attached

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Import MingW DLL
« Reply #1 on: March 23, 2013, 10:54:10 AM »
You can try create that xstd.dll with ld option --kill-at
After that create DEF-file like this
Code: [Select]
LIBRARY xstd.dll
EXPORTS
_GetXyz@0
_XyzFoo@8
_XyzRelease@4
__ZN4CXyz3FooEi
and then create import-library with polib
Code: [Select]
polib.exe  /MACHINE:x86 /DEF:xstd.def /OUT:xstd.libHere are something to read: http://wyw.dcweb.cn/stdcall.htm

EDIT: x64 test
Code: [Select]
g++ XyzLibrary1.cpp -shared -I%gccdir%\include\w32api -DXYZLIBRARY_EXPORTS -o XyzLibrary64.dll -Wl,--output-def,XyzLibrary64.def,--out-implib,libXyzLibrary64.a -s
Code: [Select]
LIBRARY XyzLibrary64
EXPORTS
    GetXyz @1
    XyzFoo @2
    XyzRelease @3
    _ZN4CXyz3FooEi @4
« Last Edit: March 27, 2013, 09:53:09 AM by timovjl »
May the source be with you

Tino

  • Guest
Re: Import MingW DLL
« Reply #2 on: March 23, 2013, 11:05:04 AM »
Thanks a lot Timo :)

I will try and post result here.

Thank you very much again :)


Tino

  • Guest
Re: Import MingW DLL
« Reply #3 on: March 27, 2013, 03:03:30 AM »
Hello Forum :)

This is more complicated it seems ><

When i changed the DLL - C worked but C++ was limited :\
Considering i wanted to embedd an option for 64bit too i ran into some more troubles..

I checked some projects like Scintilla and Squlite but they go their own ways too
( This "Amalgamation" seemed the most interesting way but didnt solve my attempt to make universal DLL Template )

Maybe anyone knows a good project wich creates a DLL and supports:
- Exporting classes the C++ and C way for Linux and Windows wich works for 32 and 64 bit ?

Any help appreciated this is really getting hard for me ><
When i change 1 setting for 1 plattform it seems to produce more problems with other ><

CLR

  • Guest
Re: Import MingW DLL
« Reply #4 on: March 27, 2013, 03:29:51 AM »
Hi Tino.

I don't have a codeproject.com account and I can't download the source code.

I believe you'll get more help if you post your code, the command line and your goal. It's hard to guess what you're doing when you say When i change 1 setting for 1 plattform it seems to produce more problems with other'.

Tino

  • Guest
Re: Import MingW DLL
« Reply #5 on: March 27, 2013, 04:17:12 PM »
Hello CLR :)

I attached my current project wich contains a Codeblocks DLL, a Codeblocks Demo and a PellesC Demo.
I dont know if its really helpfull because i didnt get it to run yet.

I changed the --kill-at switch wich success (for C) but then the common C++ access for the class was broken.
Without that switch the C++ access works but C doesnt.

The fastcall for 64 bit isnt implemented yet.

I was searching for something like a template wich solves all 3 needs.


Its hard to belive that something like a DLL project doesnt exist wich support:
C and C++ interface for C++ classes for 32 and 64 bit targetting linux and windows.

Well maybe i should give up on universal template and just create multiple makefiles or so this is really getting a bit hard.

Thank you :)



Edit:
Just saw timo added more files,
i will try them and post results tyvm =)

CLR

  • Guest
Re: Import MingW DLL
« Reply #6 on: March 28, 2013, 05:29:16 AM »
Hi Tino.

The attachment contains scripts for building the DLL & demo programs on windows & linux.
I can't help with CodeBlocks templates.  :(

Tino

  • Guest
Re: Import MingW DLL
« Reply #7 on: March 31, 2013, 12:22:31 PM »
Thanks you very much CLR ! :)

I m still trying to find out why it looks "so easy" but that really helped much.

If anyone is interested i will post the CodeBlocks project once i tried the 64 bit version,
cause atm i fight a bit to setup 64 bit guest vm on 32 bit host.

Thank you so much that really helped me :)