Page 1 of 1
Is it possible to use a .lib written with C++ in pb?
Posted: Sat Oct 12, 2013 9:57 am
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.
Re: Is it possible to use a .lib written with C++ in pb?
Posted: Sat Oct 12, 2013 4:13 pm
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
Re: Is it possible to use a .lib written with C++ in pb?
Posted: Sat Oct 12, 2013 5:13 pm
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&
Re: Is it possible to use a .lib written with C++ in pb?
Posted: Sat Oct 12, 2013 5:53 pm
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.
Re: Is it possible to use a .lib written with C++ in pb?
Posted: Sun Oct 13, 2013 2:14 pm
by jassing
is the lib a static lib or simply an import lib?
Re: Is it possible to use a .lib written with C++ in pb?
Posted: Sun Oct 13, 2013 2:17 pm
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.
Re: Is it possible to use a .lib written with C++ in pb?
Posted: Fri Oct 18, 2013 4:59 am
by USCode
So PB can only import libraries written in C?
Re: Is it possible to use a .lib written with C++ in pb?
Posted: Fri Oct 18, 2013 5:10 am
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.
Re: Is it possible to use a .lib written with C++ in pb?
Posted: Fri Oct 18, 2013 10:13 pm
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
Re: Is it possible to use a .lib written with C++ in pb?
Posted: Sat Oct 19, 2013 1:54 am
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.