compile using only static libs

New to FreeBASIC? Post your questions here.
Iczer
Posts: 12
Joined: Jul 04, 2017 18:09

compile using only static libs

Postby Iczer » Jul 13, 2017 7:40

I wanted to compile Freebasic DLL of my Windows project using only static libxml2 libs (so my freebasic dll wont have dependences on other dll) but i'm do not know how - if i write

Code: Select all

#Define LIBXML_STATIC

at top of my *.bas project file or comment this line - resulted project dll size wont change, so, i assume, lbxml2 static libs not included in my dll?

From libxml site : https://www.zlatkovic.com/libxml.en.html
If you link to libxml statically, make sure that @lib@_STATIC macro is defined during the compilation of your sources, where @lib@ stands for LIBXML, LIBXSLT, LIBEXSLT and XMLSEC respectively.
TeeEmCee
Posts: 197
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: compile using only static libs

Postby TeeEmCee » Jul 13, 2017 12:34

Defining LIBXML_STATIC is an extra thing to need to do in addition, when you link the library statically.

There are several ways to statically link a library.

You can pass the libxml.a filename (with full path) to fbc when linking. Actually I'm not sure that this works (it depends on what order fbc passes arguments to the linker)

If this were C rather than FB, the correct way appears to be to pass -Wl -Bstatic,-lxml,-Bdynamic to fbc. Again, I think there may be a problems with the order fbc passes arguments.

If you pass "-static" to fbc that causes all libraries to be linked statically if possible, including the C runtime library, which you are not allowed to do in a .dll as it can causes bugs or crashes due to using more than copy of the C runtime library in the final application that uses your the .dll.
MrSwiss
Posts: 2020
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: compile using only static libs

Postby MrSwiss » Jul 13, 2017 12:43

Do you really have the static XML-Lib's available, for linking?

You cannot use the DLL's, for that purpose.
Iczer
Posts: 12
Joined: Jul 04, 2017 18:09

Re: compile using only static libs

Postby Iczer » Jul 13, 2017 14:29

yes, if i'm not wrong - it's v2.9.3 from ftp://ftp.zlatkovic.com/libxml/64bit/
also i get v2.9.4 from https://github.com/mhils/libxml2-win-binaries/releases but it's only "*.lib" files, no "*.a" files, so as i understand, i cannot use them with freebasic...

so i cannot use static libs while compiling freebasic windows dll?
srvaldez
Posts: 1354
Joined: Sep 25, 2005 21:54

Re: compile using only static libs

Postby srvaldez » Jul 13, 2017 15:19

by default FreeBASIC links against dll libs, I had problems in the past trying to link to static lib by using -static compiler switch, my hack solution was to rename the shared lib.
for example if you have libxml2.dll.a and libxml2.a then by default FB would link against libxml2.dll.a, it may even apply if you have libxml2.dll in your FB lib folder, (have not tested that).
suggestion: try compiling with -static compiler switch, if that does not work then rename the shared lib.
fxm
Posts: 7356
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: compile using only static libs

Postby fxm » Jul 13, 2017 16:40

ProPgStaticLibraries → fxm [Added link to "-static" compiler option]
TeeEmCee
Posts: 197
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: compile using only static libs

Postby TeeEmCee » Jul 15, 2017 15:48

Ah, so according to that page a static version of the C runtime library won't be available on Windows (as it would be if you compiled using MS Visual C/C++), which means using -static to create a .dll on Windows is probably safe. Assuming you don't have any other dependencies which might cause bugs if linked twice into the program.
JohnK
Posts: 259
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Re: compile using only static libs

Postby JohnK » Sep 12, 2017 21:32

Just to reiterate a previous question ... if an external library only has a .lib file for distribution, then fbc cannot static link the library in the exe file?

If not is there a way to convert the *.lib file to a static *.a file? I have done a lot of searching the forum and docs, neither is specific... THANKS
dodicat
Posts: 4409
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: compile using only static libs

Postby dodicat » Sep 12, 2017 22:26

JohnK
Posts: 259
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Re: compile using only static libs

Postby JohnK » Sep 13, 2017 0:20

Thank you sir. That's simple
srvaldez
Posts: 1354
Joined: Sep 25, 2005 21:54

Re: compile using only static libs

Postby srvaldez » Sep 13, 2017 15:48

my question is: does reimp correctly handle static libs or just import libs?
because I have the impression that it only handles import libs.
JohnK
Posts: 259
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Re: compile using only static libs

Postby JohnK » Sep 13, 2017 18:40

Once i got reimp, that really helped my search through the forum:
See this
viewtopic.php?f=14&t=14036&p=121607&hilit=reimp#p121607
JohnK
Posts: 259
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Re: compile using only static libs

Postby JohnK » Sep 15, 2017 4:28

I guess I spoke too soon. I reinstalled MinGW, and made sure bin-utils was in the list. However reimp.exe is nowhere to be found in version 2.28-1. I went directly to SourceForge page to download archive - no go.
Do you know which, item in the huge list of packages I need to include. I am using the GUI installer now.
dodicat
Posts: 4409
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: compile using only static libs

Postby dodicat » Sep 15, 2017 8:17

I got hold of the reimp source and compiled it using my mingw.
http://www.mediafire.com/file/dttr5qr498l58pz/reimp_new.zip

Last year I downloaded a zip file containing mingw.
I put he unzipped mingw on my C: drive.
I put this folder on path.
When I got this new computer I copied the mingw to the C: drive here.
And set it on path.
If I don't want to use mingw I rename the folder _mingw.
With Win 10 I really try to avoid any form of installer, I use only zip files.

Good luck with reimp.
JohnK
Posts: 259
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Re: compile using only static libs

Postby JohnK » Sep 15, 2017 14:54

Thanks much!

Return to “Beginners”

Who is online

Users browsing this forum: Google [Bot] and 2 guests