سؤال

I'm working on a multithreaded multi-platform Qt-based program that uses libssh2. The program was occasionally crashing inside crypt_encrypt() and libssh2_transport_write() when several SSH-using threads were active at once, so I googled around and found some pages that say that for multithreaded libssh2 to work reliably, I need to call CRYPTO_set_locking_callback(), etc, before using libssh2.

Based on that advice I added the specified callback-setup calls to the top of main() and got it all to compile and run without crashing under MacOS/X... but under Windows I now get the following link errors that I'm not sure how to fix.

Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1 Copyright (C) Microsoft Corporation. All rights reserved. Linking... main.obj : error LNK2019: unresolved external symbol _CRYPTO_set_locking_callback referenced in function "void __cdecl do_crypto_locks_setup(void)" (?do_crypto_locks_setup@@YAXXZ) main.obj : error LNK2019: unresolved external symbol _CRYPTO_malloc referenced in function "void __cdecl do_crypto_locks_setup(void)" (?do_crypto_locks_setup@@YAXXZ) main.obj : error LNK2019: unresolved external symbol _CRYPTO_num_locks referenced in function "void __cdecl do_crypto_locks_setup(void)" (?do_crypto_locks_setup@@YAXXZ) main.obj : error LNK2019: unresolved external symbol _CRYPTO_free referenced in function "void __cdecl do_crypto_locks_cleanup(void)" (?do_crypto_locks_cleanup@@YAXXZ)

Does anyone have an idea about what I might need to do in order to link these calls under Windows? Is there some other .lib file I need to link in, or do I need to pass a particular flag to the "perl Configure VC-WIN32" command to enable these functions, or ???

Thanks, Jeremy

هل كانت مفيدة؟

المحلول

I'm not sure if this can help, but this link: http://www.lurklurk.org/linkers/linkers.html

list some diferences between linking on unixes and windows

An excerpt:

The most major difference between the two is that symbols are not automatically exported by Windows libraries. On Unix, all of the symbols from all of the object files that were linked into the shared library are visible to users of the library. On Windows, the programmer has to explicitly choose to make particular symbols visible—i.e. to export them.

There are three ways to export a symbol from a Windows DLL (and all three ways can be mixed together in the same library).

In the source code, declare the symbol as `__declspec(dllexport)`, thusly:

__declspec(dllexport) int my_exported_function(int x, double y);

On the invocation of the linker, use the /export:symbol_to_export option to LINK.EXE.

    LINK.EXE /dll /export:my_exported_function

Get the linker to pull in a module definition (.DEF) file (by using the /DEF:def_file linker option), and in that file include an

EXPORTS section that contains the symbols you want to export.

    EXPORTS
      my_exported_function
      my_other_exported_function

What would be left is to ask the MacOSX devs to search for those functions and tell you which specific library has those functions, recheck the code, redeclare if you can and try again.

Sorry that I could not pin point exactly what is your problem.

Also keep in mind that Visual Studio is a C++ compiler, not a C compiler, and while it is almost C90 compliant, the libssh libraries or others could use some C99 constructs which VS does not support.

I hope this can somehow help you to find your way.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top