Is it possible to use a .lib written with C++ in pb?

Everything else that doesn't fall into one of the other PB categories.
User avatar
N_Gnom
User
User
Posts: 76
Joined: Fri Sep 13, 2013 3:20 pm
Location: Germany

Is it possible to use a .lib written with C++ in pb?

Post by N_Gnom »

Topic says all.
I only have the .lib and the c++ header.

Is there any way?

The best way is to convert the .lib to a .dll or write a dll with both like a wrapper.
But i´m no c++ prof.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Is it possible to use a .lib written with C++ in pb?

Post by jassing »

N_Gnom wrote:Topic says all.
I only have the .lib and the c++ header.

Is there any way?

The best way is to convert the .lib to a .dll or write a dll with both like a wrapper.
But i´m no c++ prof.
yes, use Import
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Is it possible to use a .lib written with C++ in pb?

Post by luis »

You can do it using a wrapper or sometimes directly.
With the wrapper is easier and foolprof, you just need some time to write a thin layer of C functions to be called by PB.
Directly is a lot more difficult.

http://www.purebasic.fr/english/viewtop ... 13&t=46203
http://www.purebasic.fr/english/viewtop ... 13&t=52522
http://www.purebasic.fr/english/viewtop ... 12&t=54604

Some pointers about demangling

http://www.purebasic.fr/english/viewtop ... 12&t=53808&
"Have you tried turning it off and on again ?"
User avatar
N_Gnom
User
User
Posts: 76
Joined: Fri Sep 13, 2013 3:20 pm
Location: Germany

Re: Is it possible to use a .lib written with C++ in pb?

Post by N_Gnom »

Directly doesn´t work for me.
A friend and i have tested the .lib to import the exported functions...no result.
With a seperate tool(the name of it i forget) we could only see one main function wich is exported...
So the only way is the write a wrap with the .lib and the header.
But i don´t write in c++ and so i don´t nothing about doing that.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Is it possible to use a .lib written with C++ in pb?

Post by jassing »

is the lib a static lib or simply an import lib?
Fred
Administrator
Administrator
Posts: 18264
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Is it possible to use a .lib written with C++ in pb?

Post by Fred »

The usual answer for this question is: no. You have to create small wrapper in C to expose the C++ functions you need, PB doesn't handle direct import.
USCode
Addict
Addict
Posts: 924
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: Is it possible to use a .lib written with C++ in pb?

Post by USCode »

So PB can only import libraries written in C?
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Is it possible to use a .lib written with C++ in pb?

Post by Shield »

PB can only (easily) import plain functions. If a library is written in C++
but provides an external plain C interface, that's fine.

Of course also other languages can be used as long as they follow the same conventions.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
idle
Always Here
Always Here
Posts: 5928
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Is it possible to use a .lib written with C++ in pb?

Post by idle »

If a c++ lib exports functions as extern c or stdcall then you can import them
If a c++ lib exports classes with pure virtual functions you can import them via interfaces, except on windows x86
unless you use a thiscall patch/hack. x64 and x86 on linux and osx will all work with pb interfaces
If the c++ lib is a com library you can import it via interfaces or use srods comate tool
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Is it possible to use a .lib written with C++ in pb?

Post by Shield »

You can import them on x86 too if you declare methods as virtual and with __stdcall. I did it before but it's quite a pain in the rear since you also need to worry about the correct order of definition. Definitely not recommendable.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Post Reply