Page 1 of 2
C++ static libs
Posted: Mon Nov 07, 2005 8:14 pm
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
Posted: Mon Nov 07, 2005 10:09 pm
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).
Posted: Mon Nov 07, 2005 10:37 pm
by pg
Ok, thanks

Posted: Thu Nov 10, 2005 8:56 pm
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
Posted: Thu Nov 10, 2005 10:01 pm
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.
Posted: Fri Nov 11, 2005 8:57 pm
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

Posted: Sat Nov 12, 2005 12:43 am
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.
Posted: Sat Nov 12, 2005 9:48 am
by Polo
yep, I know, unfortunately it doesn't work, I've got plainty of errors starting with __imp...
Posted: Sat Nov 12, 2005 11:18 am
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

Posted: Sat Nov 12, 2005 11:32 am
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

Posted: Sat Nov 12, 2005 12:24 pm
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?
Posted: Sat Nov 12, 2005 12:28 pm
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).

Posted: Sat Nov 12, 2005 12:41 pm
by pg
Maybe your lib needs other libs to be linked, like
this: #pragma comment(lib, "mylib.lib"), if you use such comments?
Posted: Sat Nov 12, 2005 12:41 pm
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 ?
Posted: Sat Nov 12, 2005 12:54 pm
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 ?