3rd party extension on msvc, link errors, cmake

Hi all,

This isn’t so much an Avogadro question as it is a cmake/MSVC
question. Perhaps someone here will know the answer? I’ve asked in
#cmake and on stackoverflow, but haven’t gotten any replies.
Everything works fine with gcc, so I suspect a problem with MSVC,
which I am wholly unfamiliar with.

I build libssh as a static library as part of my application, adding
the target in cmake with

add_library(ssh_static STATIC $libssh_SRCS)

Libssh is in C, so I have ‘extern “C” {…}’ wrapping the includes in
my c++ sources. I then link the ssh_static target to my executable,
sshconnectiontest, with

target_link_libraries(sshconnectiontest … ssh_static …)

This all works fine in linux with gcc, but now in MSVC I get

error LNK2019: unresolved external symbol imp[function names here]
referenced in [filename]
for every libssh function I use.

Any ideas whats going wrong? I’ve read that the imp prefix on the
symbols means that the linker is expecting to link a .dll, but this
should not be the case since ssh_static is declared a static library
in the add_library call… I’ve also read that this can be caused by
linking to the wrong runtime, so I’ve tried manually setting
everything to build with the /MTd switch, but still no luck.

As I said, I’m pretty new to MSVC, so any ideas, no matter how
seemingly obvious or basic, are welcomed :slight_smile:

Dave

I guess this is because of missing dllexport/dllimport declarations


Regards,
Konstantin

On Sep 14, 2010, at 8:54 PM, Konstantin Tokarev wrote:

I guess this is because of missing dllexport/dllimport declarations

How is that involved in static linking? There is no symbol import/export when statically linking on Windows.

Marcus

On Tue, Sep 14, 2010 at 3:54 PM, Konstantin Tokarev annulen@yandex.ru wrote:

I guess this is because of missing dllexport/dllimport declarations

Should I need to worry about these, since I’m not building any dlls?
The heirarchy of my build goes:

libssh (static) → libglobalsearch (static) → sshconnectiontest (executable)

The errors occur when linking sshconnection test, due to missing
symbols that are in libssh. The static libssh library has the symbols
according to dumpbin.exe, they just don’t have the imp prefix that
sshconnectiontest is looking for (and they shouldn’t have it AIUI,
since libssh is static). So the symbols aren’t being mangled correctly
in sshconnection test it would seem.

Do I understand this correctly?

Dave

On Sep 14, 2010, at 8:08 PM, David Lonie wrote:

Hi all,

This isn’t so much an Avogadro question as it is a cmake/MSVC
question. Perhaps someone here will know the answer? I’ve asked in
#cmake and on stackoverflow, but haven’t gotten any replies.
Everything works fine with gcc, so I suspect a problem with MSVC,
which I am wholly unfamiliar with.

I build libssh as a static library as part of my application, adding
the target in cmake with

add_library(ssh_static STATIC $libssh_SRCS)

Libssh is in C, so I have ‘extern “C” {…}’ wrapping the includes in
my c++ sources. I then link the ssh_static target to my executable,
sshconnectiontest, with

target_link_libraries(sshconnectiontest … ssh_static …)

I assume you double checked this all links properly too on Linux? What you did looks correct to me.

This all works fine in linux with gcc, but now in MSVC I get

error LNK2019: unresolved external symbol imp[function names here]
referenced in [filename]
for every libssh function I use.

Any ideas whats going wrong? I’ve read that the imp prefix on the
symbols means that the linker is expecting to link a .dll, but this
should not be the case since ssh_static is declared a static library
in the add_library call… I’ve also read that this can be caused by
linking to the wrong runtime, so I’ve tried manually setting
everything to build with the /MTd switch, but still no luck.

As I said, I’m pretty new to MSVC, so any ideas, no matter how
seemingly obvious or basic, are welcomed :slight_smile:

I have done a lot of static linking on Windows, but have worked more than I would like with MSVC… Do you have this in a repository somewhere I could take a look at it? It would be good to see the whole thing, git repo or tarball would work.

I didn’t spot anything with a quick scan. It should not be necessary to import/export symbols for example. VTK will build statically on all platforms. What version of MSVC are you trying this with?

Marcus

On Tue, Sep 14, 2010 at 4:18 PM, Marcus D. Hanwell
mhanwell@gmail.com wrote:

On Sep 14, 2010, at 8:08 PM, David Lonie wrote:

Hi all,

This isn’t so much an Avogadro question as it is a cmake/MSVC
question. Perhaps someone here will know the answer? I’ve asked in
#cmake and on stackoverflow, but haven’t gotten any replies.
Everything works fine with gcc, so I suspect a problem with MSVC,
which I am wholly unfamiliar with.

I build libssh as a static library as part of my application, adding
the target in cmake with

add_library(ssh_static STATIC $libssh_SRCS)

Libssh is in C, so I have ‘extern “C” {…}’ wrapping the includes in
my c++ sources. I then link the ssh_static target to my executable,
sshconnectiontest, with

target_link_libraries(sshconnectiontest … ssh_static …)

I assume you double checked this all links properly too on Linux? What you did looks correct to me.

Everything compiles, links, and runs fine with gcc on linux.

This all works fine in linux with gcc, but now in MSVC I get

error LNK2019: unresolved external symbol imp[function names here]
referenced in [filename]
for every libssh function I use.

Any ideas whats going wrong? I’ve read that the imp prefix on the
symbols means that the linker is expecting to link a .dll, but this
should not be the case since ssh_static is declared a static library
in the add_library call… I’ve also read that this can be caused by
linking to the wrong runtime, so I’ve tried manually setting
everything to build with the /MTd switch, but still no luck.

As I said, I’m pretty new to MSVC, so any ideas, no matter how
seemingly obvious or basic, are welcomed :slight_smile:

I have done a lot of static linking on Windows, but have worked more than I would like with MSVC… Do you have this in a repository somewhere I could take a look at it? It would be good to see the whole thing, git repo or tarball would work.

I didn’t spot anything with a quick scan. It should not be necessary to import/export symbols for example. VTK will build statically on all platforms. What version of MSVC are you trying this with?

I’ve pushed the current version to the windows_fixes branch of
git://github.com/dlonie/XtalOpt.git . I’m using MSVC 2008, and
building against OB trunk and avogadro master. I’ve also built qt
4.6.3 and openssl-1.0.0a as dependencies.

The libssh stuff is in src/libssh. I’ve modified it a bit to build
with only the features xtalopt needs, maybe there’s a problem in how
I’ve modified src/libssh/CMakeLists.txt that I’m overlooking? The
sshconnectiontest is in test/sshconnectiontest.cpp, which tests the
src/globalsearch/sshconnection.* interface.

Windows is quite a foreign land to me, I appreciate the help :slight_smile: I’ll
give you commit access to the xtalopt repo in case you want to push
back a change.

Thanks,
Dave

On Tue, Sep 14, 2010 at 4:48 PM, David Lonie loniedavid@gmail.com wrote:

On Tue, Sep 14, 2010 at 4:18 PM, Marcus D. Hanwell
mhanwell@gmail.com wrote:

On Sep 14, 2010, at 8:08 PM, David Lonie wrote:

Hi all,

This isn’t so much an Avogadro question as it is a cmake/MSVC
question. Perhaps someone here will know the answer? I’ve asked in
#cmake and on stackoverflow,

Stackoverflow got it: User dlonie - Stack Overflow It turns
out that LIBSSH_STATIC was defined while building ssh_static, but not
any of the other targets. Now the openssl symbols are unresolved, but
hopefully I’ll figure that one out quickly :slight_smile:

Dave