Page 1 of 2
Creating purelibraries in MinGW C++ possible?
Posted: Tue Jan 04, 2005 1:12 am
by olejr
The reason I ask this is that MinGW on Windows & gcc Linux are great for crossplatform development..
Posted: Tue Jan 04, 2005 1:45 am
by FloHimself
I think this is possible for sure!
You can even code PureLibraries in
HLA,
FPC or
OCaml if you want to.
Posted: Tue Jan 04, 2005 2:55 am
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.
Posted: Tue Jan 04, 2005 8:19 am
by olejr
Yes I'm talking about userlibraries in C++ code.. And Why not C++, Why just C??
Posted: Tue Jan 04, 2005 11:41 am
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.
Posted: Tue Jan 04, 2005 12:36 pm
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..
Posted: Tue Jan 04, 2005 1:01 pm
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" ?
Posted: Tue Jan 04, 2005 1:35 pm
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..)
Posted: Tue Jan 04, 2005 1:48 pm
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

)
Posted: Tue Jan 04, 2005 2:11 pm
by olejr
Well.. Maybe I also should add that I'm trying to use
polib to do the job..

But it doesn't matter

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)
Posted: Tue Jan 04, 2005 4:17 pm
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++.
Posted: Tue Jan 04, 2005 5:26 pm
by olejr
I get the point..
And I know what Pelles'C is.
It's installed on my machine..
MingW can also be used in "C mode"...
Posted: Tue Jan 04, 2005 6:23 pm
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' ?
)
Posted: Tue Jan 04, 2005 8:31 pm
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.
Posted: Tue Jan 04, 2005 8:42 pm
by olejr
@dracflamloc: That's a completly different thing..
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..