views:

162

answers:

4

I have to link dynamically with OpenSSL libeay32.dll. I'm writing native c++ console application using Visual C++ Express 2008.

I'm including a header evp.h from OpenSSL distribution. Building and...:

error LNK2001: unresolved external symbol _EVP_aes_256_cbc
error LNK2001: unresolved external symbol _EVP_DecryptInit
error LNK2001: unresolved external symbol _EVP_CIPHER_CTX_init

How to make calls to libeay32.dll methods? I don't know where to specify it's filename

+3  A: 

There is probably a .lib file you also need to add to your compiler's linker input. Check the documentation for the library you're using.

AshleysBrain
I have a .lib file. But as i know it is for static linking...
ILya
+2  A: 

In the project properties, configuration properties, linker, input - add the library name under "additional dependencies".

[Note, this will actually STATICALLY link with the library. If you truly want to load the library dynamically you will need to call LoadLibrary() on the DLL and then get function pointers for the functions you need using GetProcAddress().

See for example

http://msdn.microsoft.com/en-us/library/ms886736.aspx

and

http://msdn.microsoft.com/en-us/library/ms885634.aspx

Vicky
That's not really static linking... The actual symbol lookup and making sure callers point to callees still happens dynamically at runtime.
sblom
ILya
2. After using .lib to link can i simply replace a libeay32.dll to update it. Or i'll have t ore-link my project?
ILya
+1  A: 

Try using Win32 API's LoadLibrary function, the following link might be of some help :example

ryanlancer
+1  A: 
  1. if your application need to be able to run without the existence of OpenSSL, use dynamic linking with explicit run-time linking and handle the cases when the DLLs are not around (e.g. by changing your application's behavior / switching to other libraries).
    I recently found a nice examples on this:
  2. if your application may only run if the OpenSSL exist in the environment, use implicit run-time linking. add #pragma comment(lib,"libeay32.lib") in your source code (simplest if you need to use DLL. You will probably need the .lib to be produced by the same compiler you use)
  3. if your application need to be independent of the environment. Link OpenSSL statically.
afriza