2

I have a C++ dll project in visual studio 10 that I am trying to use libssh for. I would like to statically link the libssh functionality. When I use the non-static libary and include the dll during runtime, the code compiles and executes as expected. But if I change to the static library then I cannot compile and get linker errors for the libssh functions I am trying to use e.g.:

error LNK2019: unresolved external symbol __imp__ssh_free referenced in function ...
kevincw01
  • 69
  • 2
  • 8

1 Answers1

2

Did you by chance forget to set LIBSSH_STATIC? This page says you have to define it yourself in the compiler options.

Michael Kristofik
  • 34,290
  • 15
  • 75
  • 125
  • im using the ssh.lib binary in the folder named "static" that came from the libssh website. The file is much larger than the shared lib but I guess Im assuming they compiled it correctly. Does vs10 have a tool like nm to look at symbols in the lib? – kevincw01 Jan 11 '12 at 01:21
  • If you read the page I linked, it looks like you have to define that symbol yourself in the compiler options. The VS project properties should have a section for your own defines (`/D` I think). – Michael Kristofik Jan 11 '12 at 02:56
  • I did read the page but I assumed they were talking about building libssh, not linking with libssh. I will try your suggestion and post back. – kevincw01 Jan 11 '12 at 14:34
  • this question provides more proof for your answer and also has an explanation: http://stackoverflow.com/questions/3704374/linking-error-lnk2019-in-msvc-unresolved-symbols-with-imp-prefix-but-shoul – kevincw01 Jan 11 '12 at 14:40
  • well that resolved the unresolved symbols for that libssh functions I'm calling directly, but now I have 30 new unresolved symbols coming from ssh.lib. I wonder if that library needs another library? ssh.lib(misc.c.obj) : error LNK2019: unresolved external symbol __imp__WSAStringToAddressA@20 referenced in function _ssh_is_ipaddr_v4 – kevincw01 Jan 11 '12 at 14:56
  • added w2_32.lib which resolved that one but now I have 69 more unresolved symbols. e.g. ssh.lib(keyfiles.c.obj) : error LNK2019: unresolved external symbol _RSA_free referenced in function _privatekey_from_file – kevincw01 Jan 11 '12 at 15:01
  • I'm thinking these are openssl symbols. Probably need to track down/build a static openssl library – kevincw01 Jan 11 '12 at 15:07
  • Before you chase down every missing library, you might want to see [this answer](http://stackoverflow.com/a/8204677/46821). – Michael Kristofik Jan 11 '12 at 15:07
  • added static versions of libeay32.lib and ssleay32.lib and I'm down to 7 unresolved symbols. However these don't look good. e.g. LIBCMT.lib(tidtable.obj) : error LNK2005: __encoded_null already defined in MSVCRT.lib(MSVCR100.dll) – kevincw01 Jan 11 '12 at 15:11
  • I read that but if I understand correctly, it's telling you how to build a static openssl lib. I've got those already. – kevincw01 Jan 11 '12 at 15:13
  • building with /MDd temporarily resolves the "already defined" errors. This is probably bc I've got mixed debug/release libraries. Static zlib is next. – kevincw01 Jan 11 '12 at 15:20
  • ok, all compiled. if it works, i'll go back and compile all these static libs myself to get rid of the "already defined" business – kevincw01 Jan 11 '12 at 15:33
  • Nice! Glad you could figure it out. – Michael Kristofik Jan 11 '12 at 15:36