Import and C++

Everything else that doesn't fall into one of the other PB categories.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Import and C++

Post by Polo »

Hi !

Can we import C++ functions with the "Import" feature of Purebasic (I use VC++ express) ?

What syntax should we use for exporting the functions ?

cheers,
Polo
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

You will have to put 'extern "C"' before the function you want to export and it should be ok.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

This is what I'm doing :)
When I compile the code with import, the linker hang :oops:

I'm pretty sure this is just me doing something wrong with visual C++ express, but I can't figure out what :cry:

Here's a quick example to show you what the problem is :

http://dl.free.fr/nopKQCTV1/test.rar

thanks :)
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

I created a new project with VS2008 and compiled this code to a static library:

Code: Select all

extern "C" {
	int get()
	{
		return 1;
	}
};
The Purebasic Linker doesn't find the function, even when I import it like this

Code: Select all

Import "Release/testlib.lib"
  get.l() As "get"
EndImport
it won't work :cry:
Windows 7 & PureBasic 4.4
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Yes this is exactly the problem I have :)
Is that a bug ?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Will you not need to use ImportC with that lib?
I may look like a mule, but I'm not a complete ass.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

srod wrote:Will you not need to use ImportC with that lib?
No I'm afraid it doesn't change anything, as I'm using _stdcall :cry:
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

srod wrote:Will you not need to use ImportC with that lib?
Doesn't change anything, I already tried that before :?
Windows 7 & PureBasic 4.4
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

What about :

Code: Select all

ImportC "Release/testlib.lib" 
  get.l() As "_get" 
EndImport
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

VS2008
Don't forget that VS2008 doesn't write code that will run on Win9x!
(I know that this isn't the cause of the problem, but its worth considering if your coding a lib and would like it to run on Win9x machines).
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

srod wrote:What about :

Code: Select all

ImportC "Release/testlib.lib" 
  get.l() As "_get" 
EndImport
It unfortunately doesn't change anything, as the linker just crash :(
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

@srod
Sorry, no change, it simply doesn't find the function and outputs this:
PureBasic - Linker error
POLINK: fatal error: Corrupt library: 'C:\Dokumente und Einstellungen\Milan\Eigene Dateien\testlib\Release\testlib.lib'; unable to find symbol '_get' in member '.\Release\testlib.obj'.
@DoubleDutch
I'm aware of this, thanks anyway... :P
Windows 7 & PureBasic 4.4
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

May be you can try with the lastest polink version (found in the pellesc package).
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Aye, my next suggestion was to perhaps look for a more up to date version of Polink. :)
I may look like a mule, but I'm not a complete ass.
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

OK, downloaded and replaced the new polink.exe, but the error persists :?
Windows 7 & PureBasic 4.4
Post Reply