libjpeg-turbo static

Windows specific forum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: libjpeg-turbo static

Post by wilbert »

I wish msvcrt could be statically linked so the exe doesn't need a dll.
Other solution might be to use the dll version of libjpeg-turbo if it would be possible to embed the dll into the exe.
I have also attempted to compile the lib using MinGW and while it compiled fine, the output of MinGW seems to be incompatible with the polink linker PB uses. :(
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: libjpeg-turbo static

Post by Keya »

silly me there's no t in msvcr100
anyway i tried with VC2008 and VC2005 libs, the dll dependency remains but changes to msvcr90 for 2008 and msvcr80 for 2005, so maybe you could just use one of those instead?
also i tried hex editing msvcr80.dll to msvcrt.dll[0] and it seemed to be a valid patch, but then "The procedure entry point _snprintf_s could not be located in MSVCRT.DLL"
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: libjpeg-turbo static

Post by Keya »

> cl.exe /?

Code: Select all

                                -LINKING-

/LD Create .DLL                         /LDd Create .DLL debug library
/LN Create a .netmodule                 /F<num> set stack size
/link [linker options and libraries]    /MD link with MSVCRT.LIB
/MT link with LIBCMT.LIB                /MDd link with MSVCRTD.LIB debug lib
/MTd link with LIBCMTD.LIB debug lib
so i edited all the flags.make files, as there were some that were /MT, others were /MD, so i changed them all to /MD

Code: Select all

C_FLAGS =  /DWIN32 /D_WINDOWS /W3 /MD /O2 /Ob2 /D NDEBUG   -W3 -wd4996
and the libs seemed to be made ok, but still with the msvcr80/90/100.dll dependency
So then i tried all with /MT instead, again all successfully compiled, but same dependency result. I was hoping /MD wouldve been the solution!
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: libjpeg-turbo static

Post by wilbert »

Thanks for trying Keya.
I wonder if it would be possible to build the lib using Pelles C.
It doesn't seem to use msvcrt and the linker PureBasic uses (polink) also comes from Pelles.
Confusing stuff :?
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: libjpeg-turbo static

Post by Keya »

Keya wrote:also i tried hex editing msvcr80.dll to msvcrt.dll[0] and it seemed to be a valid patch, but then "The procedure entry point _snprintf_s could not be located in MSVCRT.DLL"
I thought hmmm, we probably dont need printf functions for this sort of a lib? so i checked and there was only half a dozen or so calls to it (in the main turbojpeg.c), all just console error messages like "Invalid blah", so i commented those out.
I then recompiled, re-patched msvcr80 to msvcrt in hex editor, and that fixed that problem, so now the PE editor is showing that there's just 1 invalid function left ... _crt_debugger_hook.
If we can remove that then it seems it might work, but i cant find any references to it in the source like i could with the snprintf
Image
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: libjpeg-turbo static

Post by wilbert »

Keya wrote:I thought hmmm, we probably dont need printf functions for this sort of a lib?
OSX is my main platform. If it works in Windows it's fine. I don't need console output.
Keya wrote:I then recompiled, re-patched msvcr80 to msvcrt in hex editor, and that fixed that problem, so now the PE editor is showing that there's just 1 invalid function left ... _crt_debugger_hook.
If we can remove that then it seems it might work, but i cant find any references to it in the source like i could with the snprintf
:shock: :shock: :shock:
I only understand half of what you are doing I'm afraid. :lol:
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: libjpeg-turbo static

Post by Keya »

wilbert wrote:I only understand half of what you are doing I'm afraid. :lol:
i don't understand anything i'm doing lol, this is all new for me, but i need to learn!

re that screenshot, basically... the PB-compiled test.exe file (one of your simple demos from earlier in this thread that uses the lib) imports functions from kernel32, msvcr80 etc...
so i just patched msvcr80 to msvcrt, afterall they both have the same basic functions, and it shows that there are only two functions that don't exist on my XP32's msvcrt.dll ... the snprintf one which i successfully commented out, and the _crt_debugger_hook one. So, if you try to run the exe you just get the error saying missing function in msvcrt.dll, but if i can get rid of the crt_debugger_hook import then i think it should load fine
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: libjpeg-turbo static

Post by wilbert »

Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: libjpeg-turbo static

Post by Keya »

no i dont think /NODEFAULTLIB or /DEFAULTLIB is of help, but what do i know lol

Try this!! (ive just tried in VC2005/2008/2010), im downloading VC2013 but it will take a while so you can try it with your 2013 install in the meantime

[edit] whoops just noticed you have 2015 not 2013, have modified post accordingly!

1) install CMake, and then also NASM, if u havent already. i found them both quick and painless
2) open a new command prompt to ensure the new cmake/nasm environment variables are loaded (so u can type "cmake" from anywhere)
3) type: cd c:\libjpeg
or wherever youve got all the .c source files, or more to the point where the cmakelists.txt file is but yes thats the same dir
4) type: cmake -G "Visual Studio 14 2015"
(type "cmake --help" to get list of all environments)
AHHH! So THAT generates all the Visual Studio files for us, ok nice :) So then...
5) in Visual Studio, File Open, and select the newly created ALL_BUILD.vcproj or .vcsln or whatever it is
6) Build menu -> Configuration Manager (or Project -> Properties -> Build Manager), and switch from Debug to Release if theyre not already
7) click Build -> Rebuild Solution
And that should build everything including the .libs and all the annoying little .exes we dont need lol

And because we're now building from the IDE it gives a lot easier control over all the options! Project -> Properties is then at your full disposal :D

ps if you want to build 64bit https://github.com/libjpeg-turbo/libjpe ... UILDING.md says regarding the cmake -G commandline:
NOTE: Add "Win64" to the generator name (for example, "Visual Studio 10 Win64") to build a 64-bit version of libjpeg-turbo. Recent versions of CMake no longer document that. A separate build directory must be used for 32-bit and 64-bit builds.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: libjpeg-turbo static

Post by wilbert »

I tried several different options to build the lib but so far no luck.
There are so many configuration options and I have no clue what's it all about.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: libjpeg-turbo static

Post by Keya »

try v1.4.1, that was the latest one i was able to build from the cmdline yesterday using VC2010; i had hiccups with the 1.4.2 and the latest whatever it is Beta, but then again maybe the newest Beta does like 2013/2015. I'll try some more when my VC2013 download finishes in one and a half hours
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: libjpeg-turbo static

Post by Keya »

========== Rebuild All: 20 succeeded, 0 failed, 4 skipped ==========
:) successful 1.4.1 build in VC2008 IDE. 2013 still downloading but i might not need it

I had to manually add the path to NASM, it stopped complaining then. So in XP that was right-click My Computer -> Properties -> Advanced -> Environment Variables, and add your nasm path to both User and System PATH, and restart Visual Studio. Make sure CMAKE is there also! but it probably already is. Just need to add nasm so it can create the .obj's

Ok so basically it seems if we use the MSVCRT.LIB from Visual Studio 2005 or later we have to link against msvcr80/90/100 instead of msvcrt... so if we just use an older msvcrt.lib like the one from Visual Studio 6, or even better the one from Purebasic which is still old (intentionally - for these reasons!) but more recent, then we're linking against msvcrt.dll. (no hex-edit patching required lol)

But then there's the problem of some missing functions...
Image

If we turn off Buffer Checks that gets rid of the two __security ones:
Image

So now it's just iob_func..... *googling*
lol, one of the search results is Fred providing solution for the exact problem of iob_func! http://www.purebasic.fr/english/viewtop ... 28#p317028

so ive added the macro thingy as per Fred's direction, im assuming ive added it to the right place here in Additional Options:
Image

... SUCCESS! compiles and runs :)

Here is the resulting static 32bit lib from VS2008:
v1.4.1: https://www.sendspace.com/file/jfzrgp
So dont forget to use the existing msvcrt.lib that comes with PB and not a newer Visual Studio one :)

I was also able to get 1.4.2 compiled this time, i had to comment-out the putenv and printf's again the same as 1.4.1:
v1.4.2: https://www.sendspace.com/file/w441ap

and then because all the planets have aligned or something i was also able to build the latest, but its a beta, don't go there wilbert we beg you!
v.1.4.90 (1.5 beta 1): https://www.sendspace.com/file/hl1qnn

Hope you like these optimization settings heehee, it sounded like you were after extra speed from this lib:
Image

*looks around for another waiter* GONNA NEED SOME MORE COFFEE HERE!
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: libjpeg-turbo static

Post by wilbert »

Great work Keya !!! Thank you very much :)
I can't test on Windows 7 at the moment but on Windows 10 it seems to work fine 8)
Keya wrote:Hope you like these optimization settings heehee, it sounded like you were after extra speed from this lib
Speed is one reason (important) but not the only one.
The lib supports lossless crop and rotation of a jpeg and it has also some built in accelerated scaling factors meaning that you can decode at for example half the size of the original if you don't need a large image. When it comes to encoding, you have better control of the output quality compared to the encoder that comes with PureBasic.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: libjpeg-turbo static

Post by Keya »

it seems fine all the way back on XP too :) no idea about Win9x but it seems all NT are good. [edit] just tried Win7-64, fine there also
anyway that was a really good learning experience for me, thankyou! lol
Last edited by Keya on Sun Mar 06, 2016 2:26 pm, edited 1 time in total.
sys64802
Enthusiast
Enthusiast
Posts: 105
Joined: Sat Sep 12, 2015 6:55 pm

Re: libjpeg-turbo static

Post by sys64802 »

First of all, great job in making it work.
Personally I gave up using static libraries with PB some time ago because every time it was a fight like the one described here, and I wasn't always successful.
Sometimes I had to modify the source of the lib to make it work, this means every time I want to update the lib I have to do the same.
The same if I am lucky and nothing else changed in some way.
The same thing happens between different compilers in general, it's not something specific to PB, but with another language (for example C/C++) you just have to use the same compiler for your program and the library and you are fine.
With PB you can't do that obviously, so you have every time the problem of linking the product of two different compilers together.
With DLLs, you don't have problems because a DLL is exactly as an exe, so everything is already resolved and linked there.
So I "simply" embed the DLL in my exe and load the DLL from memory, there is some lib (which you can successfully link!) for that in the forum.
Or at worst you can extract it to temp and load from there.
But I had enough of all the problems above, every time.
Post Reply