Can I use PureBasic with a static c++ library?
-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Can I use PureBasic with a static c++ library?
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
I'd rather program in PureBasic than BlitzMax.
Mike
Re: Can I use PureBasic with a static c++ library?
you could use
Code: Select all
Import "MyStatic.lib"
fnFunction()
endimport
Re: Can I use PureBasic with a static c++ library?
Hikarmacomposer 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
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
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
Re: Can I use PureBasic with a static c++ library?
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.
See what is "exported" and how and you will know.
"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review
-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Re: Can I use PureBasic with a static c++ library?
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
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
-
- 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?
Yes, you can call function from static c++ library with Purebasic.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
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!!
Re: Can I use PureBasic with a static c++ library?
I really hate when someone misrepresent what another person said:karmacomposer wrote:How can one person adamantly say "Yes" and the other emphatically say "No"?
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.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.
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
A little PureBasic review
-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Re: Can I use PureBasic with a static c++ library?
Fair enough. I apologize if I so misrepresented you.luis wrote:I really hate when someone misrepresent what another person said:karmacomposer wrote:How can one person adamantly say "Yes" and the other emphatically say "No"?
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.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.
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.
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
-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Re: Can I use PureBasic with a static c++ library?
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
Thanks in advance.
Mike
Re: Can I use PureBasic with a static c++ library?
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.
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
A little PureBasic review
-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Re: Can I use PureBasic with a static c++ library?
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?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.
Mike
Re: Can I use PureBasic with a static c++ library?
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.
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
A little PureBasic review
-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Re: Can I use PureBasic with a static c++ library?
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
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
Re: Can I use PureBasic with a static c++ library?
written in a foreign language = not written in PB
"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review
-
- Enthusiast
- Posts: 113
- Joined: Sun Jul 29, 2012 2:51 pm
Re: Can I use PureBasic with a static c++ library?
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).luis wrote:written in a foreign language = not written in PB
Mike