Subject: [libssh2] #272: Build errors on Windows

[libssh2] #272: Build errors on Windows

From: libssh2 Trac <trac_at_libssh2.stuge.se>
Date: Mon, 23 Sep 2013 12:48:35 -0000

#272: Build errors on Windows
-------------------------+--------------------
 Reporter: kdekker | Owner:
     Type: defect | Status: new
 Priority: normal | Milestone: 1.4.3
Component: misc | Version: 1.4.2
 Keywords: build error | Blocked By:
   Blocks: |
-------------------------+--------------------
 1. Visual Studio 2010 SP1 complains about /Og (on both 32-bit and 64-bit
 build) when building libssh2 version 1.4.3.

 The errors happen during:
 a. during compilation:

         cl -c /nologo /GL /Zi /EHsc /Og /Oi /O2 /Oy /GF /Y- /MD /DNDEBUG
 /Iwin32 /Iinclude
 /IW:\common\thirdparty\OpenSSL\build\Windows\Win32\include
 -DLIBSSH2_HAVE_ZLIB=1
 /IW:\common\thirdparty\zlib\build\Windows\Win32\..\include -DLIBSSH2_WIN32
 /Fo"Release\src\\" src\channel.c src\comp.c src\crypt.c src\hostkey.c
 src\kex.c src\mac.c src\misc.c src\packet.c src\publickey.c src\scp.c
 src\session.c src\sftp.c src\userauth.c src\transport.c src\version.c
 src\knownhost.c src\agent.c src\openssl.c src\libgcrypt.c src\pem.c
 src\keepalive.c src\global.c
 1>cl : Command line warning D9035: option 'Og' has been deprecated and
 will be removed in a future release

 b. during link:

 1> cl -o libssh2.dll /nologo /GL /Zi /EHsc /Og /Oi /O2 /Oy /GF /Y-
 /MD /DNDEBUG /Iwin32 /Iinclude
 /IW:\common\thirdparty\OpenSSL\build\Windows\Win32\include
 -DLIBSSH2_HAVE_ZLIB=1
 /IW:\common\thirdparty\zlib\build\Windows\Win32\..\include -DLIBSSH2_WIN32
 /DEBUG /LD Release\src\channel.obj Release\src\comp.obj
 Release\src\crypt.obj Release\src\hostkey.obj Release\src\kex.obj
 Release\src\mac.obj Release\src\misc.obj Release\src\packet.obj
 Release\src\publickey.obj Release\src\scp.obj Release\src\session.obj
 Release\src\sftp.obj Release\src\userauth.obj Release\src\transport.obj
 Release\src\version.obj Release\src\knownhost.obj Release\src\agent.obj
 Release\src\openssl.obj Release\src\libgcrypt.obj Release\src\pem.obj
 Release\src\keepalive.obj Release\src\global.obj
 Release\src\libssh2.res
 W:\common\thirdparty\OpenSSL\build\Windows\Win32\lib\libeay32.lib
 W:\common\thirdparty\OpenSSL\build\Windows\Win32\lib\ssleay32.lib
 ws2_32.lib user32.lib
 W:\common\thirdparty\zlib\build\Windows\Win32\lib\zlib.lib
 1>cl : Command line warning D9035: option 'o' has been deprecated and will
 be removed in a future release
 1>cl : Command line warning D9035: option 'Og' has been deprecated and
 will be removed in a future release
 1> Creating library libssh2.lib and object libssh2.exp

 2. Link errors:
 1>libeay32.lib(cryptlib.obj) : error LNK2001: unresolved external symbol
 __imp__DeregisterEventSource_at_4
 1>libeay32.lib(cryptlib.obj) : error LNK2001: unresolved external symbol
 __imp__ReportEventA_at_36
 1>libeay32.lib(cryptlib.obj) : error LNK2001: unresolved external symbol
 __imp__RegisterEventSourceA_at_8
 1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol
 __imp__DeleteDC_at_4
 1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol
 __imp__DeleteObject_at_4
 1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol
 __imp__GetBitmapBits_at_12
 1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol
 __imp__BitBlt_at_36
 1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol
 __imp__GetObjectA_at_12
 1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol
 __imp__SelectObject_at_8
 1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol
 __imp__CreateCompatibleBitmap_at_12
 1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol
 __imp__GetDeviceCaps_at_8
 1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol
 __imp__CreateCompatibleDC_at_4
 1>libeay32.lib(rand_win.obj) : error LNK2001: unresolved external symbol
 __imp__CreateDCA_at_16
 1>libssh2.dll : fatal error LNK1120: 13 unresolved externals
 1>NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual
 Studio 10.0\VC\bin\cl.EXE"' : return code '0x2'

 To address these issues, I propose a change on config.mk, see attached
 file.

 I also made some makefile variables configurable by setting environment
 variables (to find e.g. OpenSSL and zlib directories).

 You also cannot rely on default libraries, so I had to add advapi32 and
 gdi32 libraries to get the libssh2 DLL linking.

 3. static libssh2.lib could not be build. I added a static library target
 to src\NMakfile.

 Affected changed files are attached. Diff (in diff format) is shown below.

 diff src\NMakefile.org src\NMakefile
 6a7,9
> AR = lib
> ARFLAGS = -nologo /LTCG
>
 8d10
 <
 9a12
> STATICLIB=$(INTDIR)\libssh2.lib
 10a14
> !if "$(BUILD_STATIC_LIB)" == ""
 11a16,18
> !else
> all: $(STATICLIB)
> !endif
 15a23,25
> $(STATICLIB): $(OBJECTS)
> $(AR) $(ARFLAGS) -out:$@ $(OBJECTS)
>

 diff win32\config.mk.org win32\config.mk
 2a3
> !if "$(OPENSSLINC)" == ""
 3a5,7
> !endif
>
> !if "$(OPENSSLLIB)" == ""
 5c9,11
 <
 ---
> !endif
>
> !if "$(ZLIBINC)" == ""
 6a13,15
> !endif
>
> !if "$(ZLIBLIB)" == ""
 7a17
> !endif
 18c28
 < CPPFLAGS=/Og /Oi /O2 /Oy /GF /Y- /MD /DNDEBUG
 ---
> CPPFLAGS=/Oi /O2 /Oy /GF /Y- /MD /DNDEBUG
 22c32
 < CPPFLAGS=/nologo /GL /Zi /EHsc $(CPPFLAGS) /Iwin32 /Iinclude
 /I$(OPENSSLINC) $(ZLIBINC) -DLIBSSH2_WIN32
 ---
> CPPFLAGS=/nologo /GL /Zi /EHsc $(CPPFLAGS) /Iwin32 /Iinclude
 /I$(OPENSSLINC) $(ZLIBINC)
 26c36
 < LIBS=$(OPENSSLLIB)\libeay32.lib $(OPENSSLLIB)\ssleay32.lib ws2_32.lib
 user32.lib $(ZLIBLIB)\zlib.lib
 ---
> LIBS=$(OPENSSLLIB)\libeay32.lib $(OPENSSLLIB)\ssleay32.lib
 $(ZLIBLIB)\zlib.lib ws2_32.lib user32.lib advapi32.lib gdi32.lib

-- 
Ticket URL: <https://trac.libssh2.org/ticket/272>
libssh2 <https://trac.libssh2.org/>
C library for writing portable SSH2 clients
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2013-09-23