Subject: Re: Compile error in examples under MinGW

Re: Compile error in examples under MinGW

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

On Sat, Dec 11, 2010 at 3:14 PM, Daniel Stenberg <daniel_at_haxx.se> 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/libssh2.la -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
`_imp__libssh2_init'
direct_tcpip.o:direct_tcpip.c:(.text+0x20b): undefined reference to
`_imp__libssh2_session_init_ex'
direct_tcpip.o:direct_tcpip.c:(.text+0x25a): undefined reference to
`_imp__libssh2_session_startup'
direct_tcpip.o:direct_tcpip.c:(.text+0x2a1): undefined reference to
`_imp__libssh2_hostkey_hash'
direct_tcpip.o:direct_tcpip.c:(.text+0x347): undefined reference to
`_imp__libssh2_userauth_list'
direct_tcpip.o:direct_tcpip.c:(.text+0x44d): undefined reference to
`_imp__libssh2_userauth_password_ex'
direct_tcpip.o:direct_tcpip.c:(.text+0x4d2): undefined reference to
`_imp__libssh2_userauth_publickey_fromfile_ex'
direct_tcpip.o:direct_tcpip.c:(.text+0x6ff): undefined reference to
`_imp__libssh2_channel_direct_tcpip_ex'
direct_tcpip.o:direct_tcpip.c:(.text+0x74a): undefined reference to
`_imp__libssh2_session_set_blocking'
direct_tcpip.o:direct_tcpip.c:(.text+0x8d0): undefined reference to
`_imp__libssh2_channel_write_ex'
direct_tcpip.o:direct_tcpip.c:(.text+0x93b): undefined reference to
`_imp__libssh2_channel_read_ex'
direct_tcpip.o:direct_tcpip.c:(.text+0x9e0): undefined reference to
`_imp__libssh2_channel_eof'
direct_tcpip.o:direct_tcpip.c:(.text+0xa37): undefined reference to
`_imp__libssh2_channel_free'
direct_tcpip.o:direct_tcpip.c:(.text+0xa5c): undefined reference to
`_imp__libssh2_session_disconnect_ex'
direct_tcpip.o:direct_tcpip.c:(.text+0xa69): undefined reference to
`_imp__libssh2_session_free'
direct_tcpip.o:direct_tcpip.c:(.text+0xa7e): undefined reference to
`_imp__libssh2_exit'
collect2: ld returned 1 exit status
make[2]: *** [direct_tcpip.exe] Error 1
make[2]: Leaving directory
`/c/Users/Luis/Projects/oss/oci/rubyinstaller/sandbox/src-libssh2/example'
make[1]: *** [all] Error 2
make[1]: Leaving directory
`/c/Users/Luis/Projects/oss/oci/rubyinstaller/sandbox/src-libssh2/example'
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
.libs/channel.o

Could this be the linking issue?

-- 
Luis Lavena
AREA 17
-
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
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-12-11