C++ static libs

Everything else that doesn't fall into one of the other PB categories.
pg
User
User
Posts: 75
Joined: Wed Jun 18, 2003 3:31 pm
Location: Swiss
Contact:

C++ static libs

Post by pg »

Hi

Is there a way to use a C++ static Lib in PureBasic? I know how to create Userlibs with C static libs, but with C++ I have no success.

Thanks
KarLKoX
Enthusiast
Enthusiast
Posts: 681
Joined: Mon Oct 06, 2003 7:13 pm
Location: France
Contact:

Post by KarLKoX »

This is simple : just compile it as a Multithreaded DLL and link with MSVCPRT.LIB (you can add it in your project to resolve hypotetical unresolved symbols).
"Qui baise trop bouffe un poil." P. Desproges

http://karlkox.blogspot.com/
pg
User
User
Posts: 75
Joined: Wed Jun 18, 2003 3:31 pm
Location: Swiss
Contact:

Post by pg »

Ok, thanks :wink:
User avatar
the.weavster
Addict
Addict
Posts: 1576
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Post by the.weavster »

KarLKoX wrote:This is simple
Please can you explain it to me like I'm a two-year-old, if I have a *.lib file can I make it usable with PureBasic?

If so, how?

Thanks
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

the.weavster wrote:if I have a *.lib file can I make it usable with PureBasic?
Coding's nothing for two year olds... :)

If it's a C++ library, you'll have to write a wrapper, if it's a C library, you can
either write a simple wrapper (functionnames have to start with "PB_"), use
the method mentioned here or wait for this feature to be implemented in
PureBasic.

Another solution can be to use the DLL-Importer (PB's Library SDK) but you'll
possibly run into problems if the library depends on other libraries.
Good programmers don't comment their code. It was hard to write, should be hard to read.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

I don't know why, but everytime I'm trying to do a PBlib of a C++ code (wrapped by a C code), I always get unresolved externals errors :?
And that for every lib I'm trying to wrap :(
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

try adding windows libs to your desc file.

Code: Select all

;
; Langage used to code th library: ASM or C
C
;
; Number of windows DLL than the library need
1
crtmt2.lib
; Library type (Can be OBJ or LIB)
;
OBJ
;
.....................
.....................
you could use any number of libs, includind msvcrt.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

yep, I know, unfortunately it doesn't work, I've got plainty of errors starting with __imp...
pg
User
User
Posts: 75
Joined: Wed Jun 18, 2003 3:31 pm
Location: Swiss
Contact:

Post by pg »

I did not find the solution until now. Just to repeat again. I'm trying to link a c++ static lib, not dll. To use DLL is not a problem :-)
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

pg wrote:I did not find the solution until now. Just to repeat again. I'm trying to link a c++ static lib, not dll. To use DLL is not a problem :-)
I think he told you about the DLL Importer because it also works with .lib files, not sure though...
I'm still trying to work out my C++ lib, without success for the moment :(
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Polo wrote:I think he told you about the DLL Importer because it also works with .lib files, not sure though...
Exactly
Polo wrote: I'm still trying to work out my C++ lib, without success for the moment :(
Can you give some specific error messages (unresolved external symbols)?
What's missing?
Good programmers don't comment their code. It was hard to write, should be hard to read.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Here it is :
POLINK: warning: Multiple '.data' sections found with different flags (0xc0000040 and 0x60000040).
POLINK: error: Unresolved external symbol '__imp_??0_Lockit@std@@QAE'.
POLINK: error: Unresolved external symbol '__imp_??1_Lockit@std@@QAE'.
POLINK: error: Unresolved external symbol '__imp__fstat'.
POLINK: error: Unresolved external symbol '__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDIABV?$allocator@D@1@'.
POLINK: error: Unresolved external symbol '__imp_??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE'.
POLINK: error: Unresolved external symbol '__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV?$allocator@D@1@'.
POLINK: error: Unresolved external symbol '__imp_??Y?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@D'.
POLINK: error: Unresolved external symbol '__imp_?length@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@'.
POLINK: error: Unresolved external symbol '__imp_?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@'.
POLINK: error: Unresolved external symbol '__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDABV?$allocator@D@1@'.
POLINK: error: Unresolved external symbol '__imp_??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@ABV01@'.
POLINK: error: Unresolved external symbol '__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@'.
POLINK: error: Unresolved external symbol '__imp_??Mstd@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@0'.
POLINK: error: Unresolved external symbol '__imp_??_F?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@'.
POLINK: error: Unresolved external symbol '??Hstd@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@ABV10@D@Z'.
POLINK: error: Unresolved external symbol '__imp_??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@D'.
POLINK: error: Unresolved external symbol '__imp_??A?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAADI'.
POLINK: error: Unresolved external symbol '__imp_?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@'.
POLINK: error: Unresolved external symbol '__imp_?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@'.
POLINK: error: Unresolved external symbol '__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@IDABV?$allocator@D@1@'.
POLINK: error: Unresolved external symbol '__imp_?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@'.
POLINK: error: Unresolved external symbol '__imp_?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II'.
POLINK: error: Unresolved external symbol '__imp_?resize@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXI'.
POLINK: error: Unresolved external symbol '__imp_?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBDI'.
POLINK: error: Unresolved external symbol '__imp_?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ID'.
POLINK: error: Unresolved external symbol '__imp_?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBD'.
POLINK: fatal error: 26 unresolved external(s).
:lol: :?
pg
User
User
Posts: 75
Joined: Wed Jun 18, 2003 3:31 pm
Location: Swiss
Contact:

Post by pg »

Maybe your lib needs other libs to be linked, like

this: #pragma comment(lib, "mylib.lib"), if you use such comments?
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Polo, did you do what jack described? Did you link msvcrt.lib?

Beside the common c-runtimes (msvcrt, crtmt, crtmt2 (mt=multithreaded))
"_fstat" is defined in fstat.obj. You could add this directly to your VC project.

I can only guess about the rest. Are you using VC >= 7.0 ?
Good programmers don't comment their code. It was hard to write, should be hard to read.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Yeah, exactly, I've included these 3 : msvcrt, crtmt, crtmt2
I'm using VC 6.0.
I'm gonna try for the fstat, but for the rest ?
Post Reply