Need help to compile LibPng into static lib

Everything else that doesn't fall into one of the other PB categories.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Need help to compile LibPng into static lib

Post by jack »

ok
adding /GS- to both zlib and libpng gets rid of all but two kinker errors
POLINK: error: Unresolved external symbol '__imp___stdio_common_vfprintf'.
POLINK: error: Unresolved external symbol '__imp___acrt_iob_func'.

can anyone advise?
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Need help to compile LibPng into static lib

Post by Olliv »

Denis wrote:Salut Oliv, (ça va ?)
Yes ! Salva.

Anyway ! Did you see this (caution : it is on ASCII flow) ?
Denis
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Need help to compile LibPng into static lib

Post by Denis »

jack wrote:hello Denis
the title says "Need help to compile LibPng into static lib" and yet in the first post you say that you built the library
so is your problem building a static libpng or using it in PB?
if you managed to build the static lib, did you use Cmake or some other way?
I managed to build a static libpng x64 using Cmake but it was a learning experience, and I don't know if I could clearly give the steps needed.
Hi jack,
My problem is to compile correctly LibPng into static lib using VS and after that to use it with PB.
Using it with PB is not really problematic (hope so :mrgreen: ).
I use VS to compile libpng (standard compilation build or rebuild solution, using batch build from VS menu give the same result but i don't know if VS batch build uses Cmake).
As i said, I discoverd VS 2 weeks ago and i'm not à C coder at all.
Tomorrow, i'll take a look to the way you explain.

@Olliv
I dont' really clearly understand the procedure Undec(Name.S), may be I'm tired...
A+
Denis
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Need help to compile LibPng into static lib

Post by jack »

compiling the library is no problem, the problem is that PB uses an old version of visual studio and is not compatible with newer versions, at least that's what I gather from this post viewtopic.php?f=5&t=41247
Denis
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Need help to compile LibPng into static lib

Post by Denis »

jack wrote:compiling the library is no problem, the problem is that PB uses an old version of visual studio and is not compatible with newer versions, at least that's what I gather from this post viewtopic.php?f=5&t=41247
Yeah, not clear.

in this Fred post (Wed Nov 13, 2019 ) viewtopic.php?f=7&t=74007
I thought I understood that current VS to compile .lib file is VS 2013, that's why i've installed it.

VS 2010 is still avalaible if i remember, so lets go!
Last edited by Denis on Fri Nov 15, 2019 7:34 pm, edited 1 time in total.
A+
Denis
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Need help to compile LibPng into static lib

Post by Olliv »

I am tired too...

PNG library seems to be open source. Maybe I am wrong.
Visual Studio does not seem to be open source.
Undec() calls ms API to undecorate a function name certainly create by Visual Studio.

When you list several function names in a DLL compiled by Visual Studio, the function names seems to have more characters than we need to call them in a source file.

Until here, no problem.
Undec("PrintPATATRA") will return the right syntax we need :
Value.L = Print(String.S, [Color.L] )

That is good : I give you my DLL containing beautiful functions as Print(), Input(), etc...

And with Undec() you get the right syntax.


But, imagine me to compile you my beautiful functions, instead of just using Visual Studio (MS, I suppose), I call others non-ms functions from non-ms compiler, I am not sure, name decorating symbols will be used.

Undec() will undecorate function names compiled by ms compilers (with right switch options too). But it could be possible a function call non-ms functions built by non-ms compilers.

In this way, 3 kinds of work :
1) find a linux equivalent function as Microsoft API UndecorateName() used by Undec()
2) Search in the source headers the right syntaxes and copy them manually (converting CPP declarings to PureBasic declarings)
3) find a application which copies right syntax (what I think it is available now on this subject) whatever the OS of the compiler which made libraries and sub-libraries.

Concerning decorating version, I give up... (and let you read all the other explaining to that...)
Denis
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Need help to compile LibPng into static lib

Post by Denis »

Olliv wrote:I am tired too...

PNG library seems to be open source. Maybe I am wrong.
You're right, it's open source.
Olliv wrote:Visual Studio does not seem to be open source.
It's MS 'tool'
Olliv wrote:Undec() calls ms API to undecorate a function name certainly create by Visual Studio.
When you list several function names in a DLL compiled by Visual Studio, the function names seems to have more characters than we need to call them in a source file.
Just wonder how PB will interpret this changes.
May be it's OK if you've done this
A+
Denis
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Need help to compile LibPng into static lib

Post by Olliv »

I just needed to call DLLs compiled by MS, not static LIB.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Need help to compile LibPng into static lib

Post by jack »

@Denis
compiling with visual 2008 using the /GS- switch makes it work with PB
as does with vs2013
Everything
Enthusiast
Enthusiast
Posts: 225
Joined: Sat Jul 07, 2018 6:50 pm

Re: Need help to compile LibPng into static lib

Post by Everything »

jack wrote:using the /GS- switch
I had to do this for almost every studio .lib (and sometimes we have to add some other dependencies libs from WinSDK)
Denis
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Need help to compile LibPng into static lib

Post by Denis »

jack wrote:@Denis
compiling with visual 2008 using the /GS- switch makes it work with PB
as does with vs2013
Hi jack,
excellent but for me it doesn't work with 2013 :cry:
/GS was enabled for all except zlib. I changed it but no difference.
After that i disabled this switch to all but without succes.

Here is the content from libpng.log and zlib.log.
can you tell me the differences with yours if any or post here your result?

Thank you for your help. :wink:

With following i now get "unable to find symbol _CRC32" witch comes from Zlib config i I think.
Build started 16/11/2019 08:48:28.
1>Project "C:\Users\user\source\repos\lpng1637\projects\vstudio\libpng\libpng.vcxproj" on node 2 (Rebuild target(s)).
1>ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /IC:\Users\user\source\repos\zlib /Zi /nologo /Wall /WX- /Ox /Oi /Oy- /GL /D WIN32 /D NDEBUG /D _WINDOWS /D _UNICODE /D UNICODE /GF /Gm- /EHsc /MT /GS /Gy /fp:precise /fp:except- /Zc:wchar_t- /Zc:forScope /Yc"pngpriv.h" /Fp"libpng16.pch" /Fd"vc120.pdb" /FR /Gd /TC /wd4255 /wd4668 /wd4710 /wd4711 /wd4746 /wd4820 /wd4996 /analyze- /errorReport:prompt ..\..\..\png.c
png.c
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /IC:\Users\user\source\repos\zlib /Zi /nologo /Wall /WX- /Ox /Oi /Oy- /GL /D WIN32 /D NDEBUG /D _WINDOWS /D _UNICODE /D UNICODE /GF /Gm- /EHsc /MT /GS /Gy /fp:precise /fp:except- /Zc:wchar_t- /Zc:forScope /Yu"pngpriv.h" /Fp"libpng16.pch" /Fd"vc120.pdb" /FR /Gd /TC /wd4255 /wd4668 /wd4710 /wd4711 /wd4746 /wd4820 /wd4996 /analyze- /errorReport:prompt ..\..\..\pngerror.c ..\..\..\pngget.c ..\..\..\pngmem.c ..\..\..\pngpread.c ..\..\..\pngread.c ..\..\..\pngrio.c ..\..\..\pngrtran.c ..\..\..\pngrutil.c ..\..\..\pngset.c ..\..\..\pngtrans.c ..\..\..\pngwio.c ..\..\..\pngwrite.c ..\..\..\pngwtran.c ..\..\..\pngwutil.c
pngerror.c
pngget.c
pngmem.c
pngpread.c
pngread.c
pngrio.c
pngrtran.c
pngrutil.c
pngset.c
pngtrans.c
pngwio.c
pngwrite.c
pngwtran.c
pngwutil.c
Lib:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\Lib.exe /OUT:"C:\Users\user\source\repos\lpng1637\projects\vstudio\Release Library\libpng16.lib" "C:\Users\user\source\repos\lpng1637\projects\vstudio\Release Library\zlib.lib" /NOLOGO /MACHINE:X86 /LTCG png.obj
pngerror.obj
pngget.obj
pngmem.obj
pngpread.obj
pngread.obj
pngrio.obj
pngrtran.obj
pngrutil.obj
pngset.obj
pngtrans.obj
pngwio.obj
pngwrite.obj
pngwtran.obj
pngwutil.obj
libpng.vcxproj -> C:\Users\user\source\repos\lpng1637\projects\vstudio\Release Library\libpng16.lib
BscMake:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\bscmake.exe /nologo /o"C:\Users\user\source\repos\lpng1637\projects\vstudio\Release Library\libpng16.bsc" png.sbr pngerror.sbr pngget.sbr pngmem.sbr pngpread.sbr pngread.sbr pngrio.sbr pngrtran.sbr pngrutil.sbr pngset.sbr pngtrans.sbr pngwio.sbr pngwrite.sbr pngwtran.sbr pngwutil.sbr
1>Done Building Project "C:\Users\user\source\repos\lpng1637\projects\vstudio\libpng\libpng.vcxproj" (Rebuild target(s)).

Build succeeded.

Time Elapsed 00:00:03.12
zlib.log
Build started 16/11/2019 08:48:28.
1>Project "C:\Users\user\source\repos\lpng1637\projects\vstudio\zlib\zlib.vcxproj" on node 2 (Rebuild target(s)).
1>ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /Zi /nologo /Wall /WX- /Ox /Oi /Oy- /GL /D WIN32 /D NDEBUG /D _WINDOWS /D Z_SOLO /D _UNICODE /D UNICODE /GF /Gm- /EHsc /MT /GS /Gy /fp:precise /fp:except- /Zc:wchar_t /Zc:forScope /Fo"Release Library\\" /Fd"Release Library\vc120.pdb" /FR"Release Library\\" /Gd /TC /wd4255 /wd4668 /wd4710 /wd4711 /wd4746 /wd4820 /wd4996 /wd4127 /wd4131 /wd4242 /wd4244 /analyze- /errorReport:prompt C:\Users\user\source\repos\zlib\adler32.c C:\Users\user\source\repos\zlib\compress.c C:\Users\user\source\repos\zlib\crc32.c C:\Users\user\source\repos\zlib\deflate.c C:\Users\user\source\repos\zlib\infback.c C:\Users\user\source\repos\zlib\inffast.c C:\Users\user\source\repos\zlib\inflate.c C:\Users\user\source\repos\zlib\inftrees.c C:\Users\user\source\repos\zlib\trees.c C:\Users\user\source\repos\zlib\uncompr.c C:\Users\user\source\repos\zlib\zutil.c
adler32.c
compress.c
crc32.c
deflate.c
infback.c
inffast.c
inflate.c
inftrees.c
trees.c
uncompr.c
zutil.c
Lib:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\Lib.exe /OUT:"C:\Users\user\source\repos\lpng1637\projects\vstudio\Release Library\zlib.lib" /NOLOGO /MACHINE:X86 /LTCG "Release Library\adler32.obj"
"Release Library\compress.obj"
"Release Library\crc32.obj"
"Release Library\deflate.obj"
"Release Library\infback.obj"
"Release Library\inffast.obj"
"Release Library\inflate.obj"
"Release Library\inftrees.obj"
"Release Library\trees.obj"
"Release Library\uncompr.obj"
"Release Library\zutil.obj"
zlib.vcxproj -> C:\Users\user\source\repos\lpng1637\projects\vstudio\Release Library\zlib.lib
BscMake:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\bscmake.exe /nologo /o"C:\Users\user\source\repos\lpng1637\projects\vstudio\Release Library\zlib.bsc" "Release Library\adler32.sbr" "Release Library\compress.sbr" "Release Library\crc32.sbr" "Release Library\deflate.sbr" "Release Library\infback.sbr" "Release Library\inffast.sbr" "Release Library\inflate.sbr" "Release Library\inftrees.sbr" "Release Library\trees.sbr" "Release Library\uncompr.sbr" "Release Library\zutil.sbr"
1>Done Building Project "C:\Users\user\source\repos\lpng1637\projects\vstudio\zlib\zlib.vcxproj" (Rebuild target(s)).

Build succeeded.

Time Elapsed 00:00:00.61
Edit :
jack, did u use the way you explain to compile, i not, i only use VS to set libpng/zlib up.
A+
Denis
Justin
Addict
Addict
Posts: 961
Joined: Sat Apr 26, 2003 2:49 pm

Re: Need help to compile LibPng into static lib

Post by Justin »

I used vs2013 to compile the solution(not the method jack described) with all projects with the /GS- the builds succeeds as always but i get the exact same error as before when i import the lib in pb.

jack, when you say it works do you mean you are able to import the lib in PB as a static lib included in the pb exe?
User avatar
idle
Always Here
Always Here
Posts: 6095
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Need help to compile LibPng into static lib

Post by idle »

If you're getting unresolved c functions you will be using a different version of VS to that of PB
so you will have to add references to the crt libs for your build by explicitly adding them as dependencies.
libcrt.lib or libucrt.lib, libcmt.lib, libvcruntime.lib and use the /MT switch
Windows 11, Manjaro, Raspberry Pi OS
Image
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Need help to compile LibPng into static lib

Post by jack »

@Denis
it's /GS- not /GS
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: Need help to compile LibPng into static lib

Post by jack »

@justin
you need to add GS- to zlib also, just edit the Makefile.msc file and add -GS- to CFLAGS
also, in the cmake-gui steps to correct the zlib paths you can add the /GS- option in the CFLAGS - you will see it near the top of the list
I am not familiar with using the libpng library so my example is the following

Code: Select all

Import "zlib.lib"
EndImport
Import "libpng16_static.lib"
  png_access_version_number()
EndImport

Debug png_access_version_number()
not sure if it should be ImportC or Import but you need to import the zlib as in my example
Last edited by jack on Sun Nov 17, 2019 5:49 am, edited 1 time in total.
Post Reply