Can I use PureBasic with a static c++ library?

Just starting out? Need help? Post your questions and find answers here.
karmacomposer
Enthusiast
Enthusiast
Posts: 113
Joined: Sun Jul 29, 2012 2:51 pm

Can I use PureBasic with a static c++ library?

Post by karmacomposer »

There is a 3D engine I am using that can be scripted with either c++, c#, BlitzMax or Lua. According to the creator of the engine, it can be used with ANY language that can open static c++ libraries. Can PureBasic do that?

I'd rather program in PureBasic than BlitzMax.

Mike
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Can I use PureBasic with a static c++ library?

Post by jassing »

you could use

Code: Select all

Import "MyStatic.lib"
  fnFunction()
endimport
Thade
Enthusiast
Enthusiast
Posts: 266
Joined: Sun Aug 03, 2003 12:06 am
Location: Austria

Re: Can I use PureBasic with a static c++ library?

Post by Thade »

karmacomposer wrote:There is a 3D engine I am using that can be scripted with either c++, c#, BlitzMax or Lua. According to the creator of the engine, it can be used with ANY language that can open static c++ libraries. Can PureBasic do that?

I'd rather program in PureBasic than BlitzMax.

Mike
Hi

May I ask which 3D Engine you want to use?

Btw.: Working with PureBasic is according to my own experience much better than with any other program.
It has by far the best editor for any solution. I have used several 3D Engines with PB.

To answer your question. Yes you can.
--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Can I use PureBasic with a static c++ library?

Post by luis »

Depends on the library, probably no or not easily if it's a C++ library (object oriented, with name mangling, etc.).
See what is "exported" and how and you will know.
"Have you tried turning it off and on again ?"
A little PureBasic review
karmacomposer
Enthusiast
Enthusiast
Posts: 113
Joined: Sun Jul 29, 2012 2:51 pm

Re: Can I use PureBasic with a static c++ library?

Post by karmacomposer »

How can one person adamantly say "Yes" and the other emphatically say "No"?

The engine is Leadwerks 2.5 (www.leadwerks.com).

Josh, the creator of the engine, says it works with c++, c#, Lua and BlitzMax. I've also been told it will work
with Nuclear Basic. I assume it will work with PureBasic, but i'd love to know if it can and how to do it.

Mike
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Re: Can I use PureBasic with a static c++ library?

Post by sec »

karmacomposer wrote:How can one person adamantly say "Yes" and the other emphatically say "No"?

The engine is Leadwerks 2.5 (http://www.leadwerks.com).

Josh, the creator of the engine, says it works with c++, c#, Lua and BlitzMax. I've also been told it will work
with Nuclear Basic. I assume it will work with PureBasic, but i'd love to know if it can and how to do it.

Mike
Yes, you can call function from static c++ library with Purebasic.

And i want to ask you:
How Josh say it works with C#, Lua .. you know? because he is tried with them. If you can't trying with purebasic by yourself, why you don't ask him to try with Purebasic? it is more nature way!!
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Can I use PureBasic with a static c++ library?

Post by luis »

karmacomposer wrote:How can one person adamantly say "Yes" and the other emphatically say "No"?
I really hate when someone misrepresent what another person said:
luis wrote:Depends on the library, probably no or not easily if it's a C++ library (object oriented, with name mangling, etc.).
See what is "exported" and how and you will know.
So I didn't say emphatically "No". To access a function inside a C++ library and to be able to use the library as intended are two different things.
Knowing the name of the engine would have helped in giving you an answer.
If it does make available a flat C api, like the engine you now mentioned seems to do, a PB programmer should be able to use it without the need of a wrapper.
"Have you tried turning it off and on again ?"
A little PureBasic review
karmacomposer
Enthusiast
Enthusiast
Posts: 113
Joined: Sun Jul 29, 2012 2:51 pm

Re: Can I use PureBasic with a static c++ library?

Post by karmacomposer »

luis wrote:
karmacomposer wrote:How can one person adamantly say "Yes" and the other emphatically say "No"?
I really hate when someone misrepresent what another person said:
luis wrote:Depends on the library, probably no or not easily if it's a C++ library (object oriented, with name mangling, etc.).
See what is "exported" and how and you will know.
So I didn't say emphatically "No". To access a function inside a C++ library and to be able to use the library as intended are two different things.
Knowing the name of the engine would have helped in giving you an answer.
If it does make available a flat C api, like the engine you now mentioned seems to do, a PB programmer should be able to use it without the need of a wrapper.
Fair enough. I apologize if I so misrepresented you.

I will try to do this myself, but I may be asking questions if I get stuck. Asking Josh will more than likely not happen since he does not code in PureBasic, but I can always ask.

Mike
karmacomposer
Enthusiast
Enthusiast
Posts: 113
Joined: Sun Jul 29, 2012 2:51 pm

Re: Can I use PureBasic with a static c++ library?

Post by karmacomposer »

Is there an example anywhere of another static c++ library being loaded into a PureBasic project? I learn by example and ANY example would help me here.

Thanks in advance.

Mike
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Can I use PureBasic with a static c++ library?

Post by luis »

Try to search for "wrapper" in the forum and look at those.
There are many, and most of them are not really "wrappers" but the same thing you need to do.
Basically you have to:

1) take the c include files, translate them to pb (constants, structures, etc)
2) make another pb file with a lot of imports, one for each c function needed from the library.

So this is more an import and structure/constants conversion job than a wrapper. A wrapper generally means you need to write a thin layer of code to bridge from pb to the target library. This is needed for example if the library is a c++ lib using objects and so on. You need to write a wrapper in c++ calling the target library and exposing flat c functions to you. I suppose this is what fred originally did with the ogre library, for example. But it seems in your case this is not needed (from what I read on wikipedia, I never downloaded the library).

In all of this the most difficult thing to do is to pay attention to the correct conversion of data types, the most boring is the conversion of constants/structures.

My suggestion is to try initially only with the initialization function, if any, and to convert from the .h file only what's needed for that one. One that one works, you know the approach is correct and you can continue.
"Have you tried turning it off and on again ?"
A little PureBasic review
karmacomposer
Enthusiast
Enthusiast
Posts: 113
Joined: Sun Jul 29, 2012 2:51 pm

Re: Can I use PureBasic with a static c++ library?

Post by karmacomposer »

luis wrote:Try to search for "wrapper" in the forum and look at those.
There are many, and most of them are not really "wrappers" but the same thing you need to do.
Basically you have to:

1) take the c include files, translate them to pb (constants, structures, etc)
2) make another pb file with a lot of imports, one for each c function needed from the library.

So this is more an import and structure/constants conversion job than a wrapper. A wrapper generally means you need to write a thin layer of code to bridge from pb to the target library. This is needed for example if the library is a c++ lib using objects and so on. You need to write a wrapper in c++ calling the target library and exposing flat c functions to you. I suppose this is what fred originally did with the ogre library, for example. But it seems in your case this is not needed (from what I read on wikipedia, I never downloaded the library).

In all of this the most difficult thing to do is to pay attention to the correct conversion of data types, the most boring is the conversion of constants/structures.

My suggestion is to try initially only with the initialization function, if any, and to convert from the .h file only what's needed for that one. One that one works, you know the approach is correct and you can continue.
This can already be programmed in Lua and BlitzMax, and according to Josh, it's creator, it can be easily ported to any programming language - so, is the wrapper/conversion really necessary?

Mike
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Can I use PureBasic with a static c++ library?

Post by luis »

I don't know. You are already using the lib, you said, so you should know.

Are we talking about a library in a foreign language here ?

Yes, right ?

So at the bare minimum (C flat API) you need to import the functions using the correct calling convention (ImportC probably, I don't know).

If there is a .h with supporting structures / constants you need to convert them.

If the library only expose C++ functions you need a real wrapper.
"Have you tried turning it off and on again ?"
A little PureBasic review
karmacomposer
Enthusiast
Enthusiast
Posts: 113
Joined: Sun Jul 29, 2012 2:51 pm

Re: Can I use PureBasic with a static c++ library?

Post by karmacomposer »

Actually, no. Josh is American (not a foreign language to me - I live in Florida, he lives in California).

The only thing that needs to be imported is 'engine.dll'.

The rest is declaring functions.

It has c++ header files which contains all the functions - would I be able to just load that in, like an include?

Mike
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Can I use PureBasic with a static c++ library?

Post by luis »

written in a foreign language = not written in PB
"Have you tried turning it off and on again ?"
A little PureBasic review
karmacomposer
Enthusiast
Enthusiast
Posts: 113
Joined: Sun Jul 29, 2012 2:51 pm

Re: Can I use PureBasic with a static c++ library?

Post by karmacomposer »

luis wrote:written in a foreign language = not written in PB
LOL. Yeah, it was written in c++ I believe. It was also originally written in BlitzMax and I know they are using Lua for scripting (because they ported it to both BlitzMax and Lua).

Mike
Post Reply