Linking to openssl 64-bit static library - c++

I'm using Visual Studio 2017 and I'm trying to link to openssl 1.0.2 built by me as 64-bit Release static library as shown here. Actually it's my lib (also static) that is using openssl functions directly and executable is linking to this lib. I tried two approaches:
Put openssl's symbols into mylib.lib (using a tab in VS mylib's project properties called "Librarian")
Link to openssl (libeay32.lib, ssleay32.lib) and to my lib using Linker in executable's project
Both are resulting in linker errors like
error LNK2001: unresolved external symbol EVP_EncryptInit_ex
concerning mylib.lib library.
I looked into libeay32.lib (also into mylib.lib while using the Librarian approach), using dumpbin.exe provided by Visual Studio, and there's _EVP_EncryptInit_ex (note the _ at the beggining) symbol defined. So I'm wondering whether it is possible that openssl defines _EVP_EncryptInit_ex and the executable is trying to link to EVP_EncryptInit_ex? What could be the cause and solution? Also: How can I check for sure what symbols is exectuable trying to link to?

Related

openssl Could Not Find libcrypto-3-x64.dll

I connected openssl to my project and it compiles and runs well, but next to the program after compiling there is a file libcrypto-3-x64.dll, without which the program will not run, so the question is how do I use openssl without this dll how to integrate it into the project?
I found out what the problem is, with the dynamic library it does not exist, EVP_CIPHER_CTX_t ctx(EVP_CIPHER_CTX_new()); when I compile a program (static lib openssl) with this line there are so many errors unresolved external character (example __imp_getsockname)
VERSION 3.0.5
I compiled the library according to this guide https://youtu.be/PMHEoBkxYaQ x64 static and still errors like this "unresolved external symbol __imp_WSAGetLastError" "unresolved external symbol __imp_CertOpenStore.".
I solved my problem and leave the answer here, just add 2 libraries in Linker => Additional Dependencies
Ws2_32.lib
Crypt32.lib

Cannot open curl/libcurl_a_debug.lib

In my current project I'm using the library libcurl, previously installed by powershell. I'm including it using #include "curl/curl.h" and compiling works but I have a linking error that says:
:LNK1104:cannot open file curl/libcurl_a_debug.lib
I dont have this file. In my current directory i found only libcurl.lib. I already added the path to the directory in Additional library directories and Additional include directories. I'd like to know is any other way to solve this error.
In release mode i have an error that linker cannot open file libcurl_a.lib. On the other hand in debug folder i have a libcurl-d.lib file.
According to Microsoft Docs, there are several common causes for this issue:
The path to your library file may be incorrect, or not wrapped in
double-quotes. Or, you may not have specified it to the linker.
You may have installed a 32-bit version of the library but you're
building for 64 bits, or the other way around.
The library may have dependencies on other libraries that aren't
installed.
By the way, could you add libcurl.lib in Properties->Linker->Additional Dependencies? If not, you could add it.
You could try to use compiled statements instead of settings.
#ifdef _DEBUG
#pragma comment(lib,"..\\debug\\lib name")
#else
#pragma comment(lib,"..\\release\\lib name")
#endif
Also, I read the official documentation of curl. There is a description of Windows link errors:
5.7 Link errors when building libcurl on Windows!
You need to make sure that your project, and all the libraries (both static and dynamic) that it links against, are compiled/linked against the same run time library.
This is determined by the /MD, /ML, /MT (and their corresponding /M?d) options to the command line compiler. /MD (linking against MSVCRT dll) seems to be the most commonly used option.
When building an application that uses the static libcurl library, you must add -DCURL_STATICLIB to your CFLAGS. Otherwise the linker will look for dynamic import symbols. If you're using Visual Studio, you need to instead add CURL_STATICLIB in the "Preprocessor Definitions" section.
If you get linker error like "unknown symbol __imp__curl_easy_init ..." you have linked against the wrong (static) library. If you want to use the libcurl.dll and import lib, you don't need any extra CFLAGS, but use one of the import libraries below. These are the libraries produced by the various lib/Makefile.* files:
Target: static lib. import lib for libcurl*.dll.
-----------------------------------------------------------
MingW: libcurl.a libcurldll.a
MSVC (release): libcurl.lib libcurl_imp.lib
MSVC (debug): libcurld.lib libcurld_imp.lib
Borland: libcurl.lib libcurl_imp.lib
I suggest that you could try the method.

CURL Static Link Unresolved External Symbols

I built CURL static lib from source using this command in the x64 Native Tools Command Prompt Visual Studio
nmake /f Makefile.vc mode=static MACHINE=AMD64
I added the lib folder to the linker library folder, added libcurl_a.lib to the linker input, and added the include folder to additional include directories. I also used the pre-processor define CURL_STATICLIB.
The library links successfully and the header is found. But I get 60 unresolved external symbols when I try to compile. https://hastebin.com/vukekakoti.tex
Dynamic linking is working with no problems.
How can I solve this?
I was missing definitions contained in these libraries:
libcurl_a.lib;ws2_32.lib;wldap32.lib;advapi32.lib;kernel32.lib;comdlg32.lib;crypt32.lib;normaliz.lib
Add those to your additional dependencies.
if compiling CURL with static linking, you will need to specify on the preprocessor field:
CURL_STATICLIB
and also as mentioned above, you`ll need to link with dependent libraries.

LibPNG static linking with VS2012 64bit

I can't manage to link LibPNG statically to my VS2012(64bit) project.
I did the following:
Download libPNG source code for the latest version(1614).
Open the enclosed VisualStudio solution (projects/vstudio/vstudio.sln).
Select "Release Library" and set C/C++ -> Code Generation ->Runtime Library to "MDd" (same as in my project.
4.Compile static lib.
Then in the target project in the linker I specify in Additional Library directories the location of the lib and in the Input the name of the lib.
I also configured Zlib to be static as is proposed here.
Yet,when compiling I am getting :
error LNK2019: unresolved external symbol png_sig_cmp referenced in
function
For the very first function call to LibPNG API.
I have tried to tweak different properties of the lib but it doesn't work.Can it happen because the libPNG built as x86 lib and not x64?
So to sum up the comments, the solution here was to compile libPNG in 64bit mode.
You cannot compile 32bit assembly with 64bit assembly.

Boost autolinks libraries which are not built by Boost, but the intended ones are built

I am developing a Math application which can be extended by writing python scripts.
I am using Qt 4.6.3 (built as static library, debug and release versions) and Boost 1.43.0 (built as static library, runtime-link also set to static, multi-threaded version, debug and release). Everything is built with MSVC++2008. Boost built the following libraries:
libboost_python-vc90-mt-s-1_43.lib
libboost_python-vc90-mt-s.lib
libboost_python-vc90-mt-sgd-1_43.lib
libboost_python-vc90-mt-sgd.lib
My project compiles, but gives the following error during the linking phase:
1>Linking...
1>LINK : fatal error LNK1104: cannot open file 'boost_python-vc90-mt-gd-1_43.lib'
Why is it not selecting one of my compiled libraries?
I think the s in the library names stands for static, but then the auto-linking feature seems to select a dynamic library, and I want it all linked statically in one executable.
The same happens with the regex library: I have the same 4 regex libraries compiled and a quick test shows this linking error:
1>LINK : fatal error LNK1104: cannot open file 'libboost_regex-vc90-mt-gd-1_43.lib'
What to do?
You can define BOOST_ALL_NO_LIB. This prevents automatic linking of boost libraries and you must then link the required boost libs manually.
If 's' stands indeed for static (I don't know all those modifiers by heart), define the BOOST_ALL_DYN_LINK symbol while compiling (add it to the command line options). It tells boost to link to the DLL libraries. Alternatively, compile/install static boost libraries.
The problem is fixed, during the compilation of the boost libraries, I selected the link=static option. Which creates static libraries. I also selected runtime-link=static option, and this was wrong!
The solution for this problem was compiling boost with runtime-link=shared. Now some extra libraries are added, with the correct filenames, so the linker can find them. At first the compiler still searches for the dll library (boost_python-vc90-mt-gd-1_43.lib, instead of libboost_python-vc90-mt-gd-1_43.lib), everything else from boost links automatically to a static library, but because boost.python has a different auto-linkage set up, when you provide BOOST_PYTHON_STATIC_LIB, it finally links to the right library and it works!