Subject: Re: Compile error in examples under MinGW

Re: Compile error in examples under MinGW

From: Luis Lavena <>
Date: Sat, 11 Dec 2010 17:33:14 -0300

On Sat, Dec 11, 2010 at 3:14 PM, Daniel Stenberg <> wrote:
> On Fri, 10 Dec 2010, Luis Lavena wrote:
>> Anyhow, there is a problem compiling examples:
>> In file included from direct_tcpip.c:2:0:
>> ../include/libssh2.h:134:16: error: expected '=', ',', ';', 'asm' or
>> '__attribute__' before 'libssh2_socket_t'
>> ../include/libssh2.h:447:43: error: expected declaration specifiers or
>> '...' before 'libssh2_socket_t'
>> Anyone seen this too?
> I don't use windows so I've not seen this. Does this happen because the
> windows.h and family headers are included after and not before libssh.h?

Thank you for answering.

You're correct, moving:

#include "libssh2_config.h"
#include <libssh2.h>

After #ifdef WIN32 block solves the compilation problem, also Peter
Stuge patch works (removing all the windows stuff from
direct_tcpip.c), If oyu can commit that change will be great.

There is another problem also:

/bin/sh ../libtool --tag=CC --mode=link gcc -DLIBSSH2_WIN32
-DWINSOCK_VERSION=0x0200 -o direct_tcpip.exe direct_tcpip.o
../src/ -lws2_32
libtool: link: gcc -DLIBSSH2_WIN32 -DWINSOCK_VERSION=0x0200 -o
.libs/direct_tcpip.exe direct_tcpip.o ../src/.libs/libssh2.a -lssl
-lcrypto -lz -lws2_32
direct_tcpip.o:direct_tcpip.c:(.text+0xf4): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0x20b): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0x25a): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0x2a1): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0x347): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0x44d): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0x4d2): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0x6ff): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0x74a): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0x8d0): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0x93b): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0x9e0): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0xa37): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0xa5c): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0xa69): undefined reference to
direct_tcpip.o:direct_tcpip.c:(.text+0xa7e): undefined reference to
collect2: ld returned 1 exit status
make[2]: *** [direct_tcpip.exe] Error 1
make[2]: Leaving directory
make[1]: *** [all] Error 2
make[1]: Leaving directory
make: *** [all-recursive] Error 1

I've tried both --enable-shared and --disable-static, but the same issue.

Above is a common problem of usage of __declspec(dllexport) versus
__declspec(dllimport). All that is generated by LIBSSH2_LIBRARY,
defined in libssh2_priv and included by every single source file that
the library uses, but is never defined during the library compilation.

Instead, libtool defined DLL_EXPORT:

libtool: compile: gcc -DHAVE_CONFIG_H -I../../include -I../src
-DLIBSSH2_WIN32 -DWINSOCK_VERSION=0x0200 -MT channel.lo -MD -MP -MF
.deps/channel.Tpo -c ../../src/channel.c -DDLL_EXPORT -DPIC -o

Could this be the linking issue?

Luis Lavena
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry
Received on 2010-12-11