Thursday 17 May 2012

Finally, building libssh2

Building libssh2 turned out to be simpler than building OpenSSL. Partly, because of the lessons I learned building OpenSSL.

I went straight for the win32/GNUmakefile. I set my paths for zlib and OpenSSL, after checking how the vars OPENSSL_PATH and ZLIB_PATH were used, i.e., if I should point them to the sources or the libs I built. In case you're wondering, I pointed to the libs.

Then, I got in trouble because of _libssh2_gettimeofday(). Apparently, getting the time of day on Windows using anything other than VC++ is terribly complex (or, rather, complicated). Once again, I searched the net, but this time found no conclusive answer. So, I decided to improvise, and turned

#if defined(LIBSSH2_WIN32) && !defined(__MINGW32__)

into

#if defined(LIBSSH2_WIN32)
// && !defined(__MINGW32__)


One step forward, problem "solved" (although I can't claim to be entirely certain of the consequences).

Then, GDI decided to rear its ugly head again, courtesy of OpenSSL, so I had to add it here:
LDLIBS += $(OPENSSL_PATH)/lib/libcrypto.$(LIBEXT) $(OPENSSL_PATH)/lib/libssl.$(LIBEXT) -lgdi32

And bingo! We have build!

Then, I built an example. Looking for something simple, I went for ssh2.c.

Compiling was simple enough:
gcc -c -g -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -I"<PATH TO LIBSSH2>/include" -o ssh2.o ssh2.c

And, this time, so was linking:
gcc -Wl,-subsystem,console -mthreads -o ssh2.exe ssh2.o -L"<PATH TO OPENSSL>/lib" -L"<PATH TO ZLIB>/zlib" -L"<PATH TO LIBSSH2>/lib" -lssh2 -lzlib1 -lssl -lcrypto -lws2_32 -lgdi32

Regarding the options used, I've copied what Qt Creator uses, to maintain the similiarity between what I'm doing on the command line and what I'll be doing on the IDE.

I intend to run some tests with static linking and dynamic linking, so I tried to follow GCC's rule about libraries with dependencies being first on the list. If you're just linking dynamically, then it should probably be a non-issue.

No comments:

Post a Comment