Static Linking of Library (no DLL dist.)
Static Linking of Library (no DLL dist.)
Is it possible to static-link a library with a PureBasic exe?
I am compiling C DLLs with VS2013 and it generates both .lib and .dll files. Can I link my PureBasic exe with any of the outputs so that I do not have to distribute the DLL?
I am compiling C DLLs with VS2013 and it generates both .lib and .dll files. Can I link my PureBasic exe with any of the outputs so that I do not have to distribute the DLL?
Re: Static Linking of Library (no DLL dist.)
you can static-link a lib!
but if you use a lib that only included the functionprototypes for a dll, for early-binding, you have to use the dll with your programm.
but if you use a lib that only included the functionprototypes for a dll, for early-binding, you have to use the dll with your programm.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: Static Linking of Library (no DLL dist.)
Hello ts-soft. Thank you. How can I know if the .lib contains only functionprototypes or full functions? Is there a setting in VS2013 do you know?ts-soft wrote:you can static-link a lib!
but if you use a lib that only included the functionprototypes for a dll, you have to use the dll with your programm.
If it does I just have to import the functions to static-link ?
Re: Static Linking of Library (no DLL dist.)
Normal, if the lib bigger as the dll, you can statically link. This is not the default behavior. The settings for static-linking in VS2013 (and others) is more difficult.coder14 wrote: Hello ts-soft. Thank you. How can I know if the .lib contains only functionprototypes or full functions? Is there a setting in VS2013 do you know?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: Static Linking of Library (no DLL dist.)
OK. Thanks!ts-soft wrote:Normal, if the lib bigger as the dll, you can statically link. This is not the default behavior. The settings for static-linking in VS2013 (and others) is more difficult.coder14 wrote: Hello ts-soft. Thank you. How can I know if the .lib contains only functionprototypes or full functions? Is there a setting in VS2013 do you know?
Re: Static Linking of Library (no DLL dist.)
Or you can use a trick:
add the dll in a DataSection and call the dll from memory.
Look here:
http://www.purebasic.fr/english/viewtop ... 13&t=42118
Bernd
add the dll in a DataSection and call the dll from memory.
Look here:
http://www.purebasic.fr/english/viewtop ... 13&t=42118
Bernd
Re: Static Linking of Library (no DLL dist.)
I think, this is a old lib. Better use: http://www.purebasic.fr/english/viewtop ... 91&start=0
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: Static Linking of Library (no DLL dist.)
@ts-soft & @infratec: Thank you for the suggestions and links.
I am now able to do it. From VS2013 I create a static library project which generates an object .lib file. Then I import the function from the library. After compiling it in PureBasic the exe runs standalone and is able to read the string by using PeekS and display it in PureBasic's message requester.
But why is the library not able to display its own message box after compiling to exe? This works in the debugger:
EDIT: Another issue is that regardless of the Unicode setting (one set and the other not or vice-versa or both the same) PeekS is always able to read and display the string correctly. But if the library uses Unicode its message box displays the string as Chinese characters. I have to leave it to NOT SET for it to display properly.
Whats the reason for this?
I am now able to do it. From VS2013 I create a static library project which generates an object .lib file. Then I import the function from the library. After compiling it in PureBasic the exe runs standalone and is able to read the string by using PeekS and display it in PureBasic's message requester.

But why is the library not able to display its own message box after compiling to exe? This works in the debugger:
Code: Select all
extern "C" {
char* go()
{
char* returnStr = "Hello PureBasic!";
//MessageBox(NULL, LPTSTR(returnStr), TEXT("fromDLL"), MB_OK);
MessageBox(HWND_DESKTOP, LPTSTR(returnStr), TEXT("fromDLL"), MB_OK);
return returnStr;
}
}
Whats the reason for this?
Re: Static Linking of Library (no DLL dist.)
make sure you specify #PB_Ascii as the flag for PeekS?
Re: Static Linking of Library (no DLL dist.)
Thanks for the tip, but there is no issue with PeekS.Keya wrote:make sure you specify #PB_Ascii as the flag for PeekS?
But when I try the linking with my bigger library I get this:

The functions are not even in the library.
Can some please help.

Re: Static Linking of Library (no DLL dist.)
Go to Project\Properties\Configuration Properties\C/C++\All Options
Security Check -> Disable Security Check (/GS-)
Whole Program Optimization -> No
Security Check -> Disable Security Check (/GS-)
Whole Program Optimization -> No
Et cetera is my worst enemy
Re: Static Linking of Library (no DLL dist.)
YES! Thanks a whole bunch chi! You have cleared up 4 of the 6 errors leaving only 2:chi wrote:Go to Project\Properties\Configuration Properties\C/C++\All Options
Security Check -> Disable Security Check (/GS-)
Whole Program Optimization -> No
Code: Select all
unresolved external symbol '__imp__findfirst64i32'
unresolved external symbol '__imp__findnext64i32'
Almost there!

Re: Static Linking of Library (no DLL dist.)
Hard to tell without the complete project 
might be useful
http://www.microsofttranslator.com/bv.a ... 752627.htm

might be useful
http://www.microsofttranslator.com/bv.a ... 752627.htm
Et cetera is my worst enemy
Re: Static Linking of Library (no DLL dist.)
Thanks again chi. I cannot overcome that issue.chi wrote:Hard to tell without the complete project
might be useful
http://www.microsofttranslator.com/bv.a ... 752627.htm
After searching older posts on the forum I decided to try CodeBlocks. It works! A few warnings but no errors.
BUT - the library works perfectly only when the main function is called with debug. I mean this works:
Code: Select all
ImportC "statLib.a"
go()
EndImport
Debug go()
Code: Select all
ImportC "statLib.a"
go()
EndImport
result = go()



Re: Static Linking of Library (no DLL dist.)
Could you try to make 'char* returnStr = "Hello PureBasic!";' static or global?