Creating purelibraries in MinGW C++ possible?

Everything else that doesn't fall into one of the other PB categories.
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Creating purelibraries in MinGW C++ possible?

Post by olejr »

The reason I ask this is that MinGW on Windows & gcc Linux are great for crossplatform development..
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post by FloHimself »

I think this is possible for sure!

You can even code PureLibraries in HLA, FPC or OCaml if you want to.
KarLKoX
Enthusiast
Enthusiast
Posts: 681
Joined: Mon Oct 06, 2003 7:13 pm
Location: France
Contact:

Post by KarLKoX »

If you mean creating userlibraries from C++ code with MingW, the answer is no, however, you can use almost all C compiler to create userlibraries.
"Qui baise trop bouffe un poil." P. Desproges

http://karlkox.blogspot.com/
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

Yes I'm talking about userlibraries in C++ code.. And Why not C++, Why just C??
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

olejr,

It is possible to create userlibraries using GCC/MingW. I've compiled the provided example using Bloodsheds Dev-Cpp.

However, the userlibraries can only be bound on simple functions. You cannot use C++ classes.

If you know what you are doing it is possible to return C++ classes from simple functions using interfaces.
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

Ok.. I think some more investigation is required on my side..
BTW. It would be great to see some kind of example...

I was trying to do a simple "hello world" Function in C++,
but ended up with a POLINK unresolved external symbol.. _PB_MyFunction..

*EDIT: In MingW there's a switch -fno-leading-underscore..
But I get the same error no matter what, in C++ that is. Standard C works..
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

olejr wrote: But I get the same error no matter what, in C++ that is. Standard C works..
Did you use extern "C" ?
Good programmers don't comment their code. It was hard to write, should be hard to read.
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

Well, yes and no.. Tried both. :)

If I use extern "C", I get 4 POLINK errors..
__ZNKSs4sizeEv
__ZNKSsixEj
__ZNKSst8ios_base4InitC1Ev
__ZNKSst8ios_base4InitD1Ev
All is unresolved external...

And without I get one.... (unresolved external symbol.. _PB_MyFunction..)
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

If I use extern "C", I get 4 POLINK errors..
__ZNKSs4sizeEv
__ZNKSsixEj
__ZNKSst8ios_base4InitC1Ev
__ZNKSst8ios_base4InitD1Ev
All is unresolved external...
I don't know these __ZNKS* but it looks like there's some kind of c-runtime
missing. I never used MingW so can't help but extern "C" is the way to go,
otherwise your exported function will be unkown (as POLINK told you)

(If __ZNKS* are no real or used functions you could also try to simply define
them, like char _ZNKSsixEj; but because I don't know __ZNKS* I personally
can't recommend this ;))
Good programmers don't comment their code. It was hard to write, should be hard to read.
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

Well.. Maybe I also should add that I'm trying to use polib to do the job.. :oops:
But it doesn't matter :cry: Only difference is that when using the objectfile
directly, instead of a LIB file I end up with just the one error..

The Linux gcc has the -fno-gnu-linker switch, but it seems that it is missing in MingW..
I think maybe that's the one I need...
From the gcc manual.
-fno-gnu-linker
Do not output global initializations (such as C++ constructors and destructors) in the form used by the GNU linker (on systems where the GNU linker is the standard method of handling them). Use this option when you want to use a non-GNU linker.....
So it seems I'm back to just C then.. Oh well.. :roll:
(Don't know my way around C++ that well anyway)
KarLKoX
Enthusiast
Enthusiast
Posts: 681
Joined: Mon Oct 06, 2003 7:13 pm
Location: France
Contact:

Post by KarLKoX »

It is not possible to use C++ code ! I played a lot with compilers to say this but this is not a purebasic limitation but as PureBasic use Pelles'C (wich is a C compiler/linker), we can't use C++.
"Qui baise trop bouffe un poil." P. Desproges

http://karlkox.blogspot.com/
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

I get the point..
And I know what Pelles'C is.
It's installed on my machine.. :wink:
MingW can also be used in "C mode"...
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

KarLKoX wrote:It is not possible to use C++ code ! I played a lot with compilers to say this but this is not a purebasic limitation but as PureBasic use Pelles'C (wich is a C compiler/linker), we can't use C++.
I fully understand what you're saying but have to disagree to a certain extent. :)

It's of course not possible to simply write a C++ class and use this directly as a
PureLibrary but using a C++ Compiler can still have some advantages.
Try/catch, new/delete, d3d->Clear(...) instead of IDirect3DDevice_Clear(d3d,...) etc.

There're also ways to use C++ from within C - writing the required wrappers can
be a quite painful job, though.

So seeing it that way you can actually use C++ code (at least elements of it).

But as I initially said, I got your point.

(BTW: Is it OK to start an english sentence with 'but' ? ;))
Good programmers don't comment their code. It was hard to write, should be hard to read.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Let me get this straight (I'm new to pb userlibraries), lets say I have a DLL which has an exposed function i want PB to be able to call:

void Initialize()
{
Device* device=new Device();
device->createWindow();
}


Device is a C++ class provided in a header.

Can I use Initialize() in PB? Probably not, correct?

How would I go about making an Initialize() function that could be called from PB, that calls C++ object functions.
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

@dracflamloc: That's a completly different thing.. :wink:
When you're talking about DLL, you have to go for the Library Functions
in PB.. Ie LoadLibrary() and so on.. Take a look under Library in the Refrence Manual..
What this thread is/was about is creating new "internal commands" to PB..
Post Reply