I have a C++ program, ProgramA, which is an executable that has a static library, LibraryB, which in turn relies on another static library (libcurl, actually) that is not compiled within my project.
Now, on OSX this works fine. I make sure to link libcurl and ProgramA and LibraryB compile and ProgramA runs great.
However, on Windows, I keep getting linking errors:
error LNK2019: unresolved external symbol __imp_curl_global_init referenced in function
I've double and triple checked that I'm linking the libcurl static library into the project. And actually, in the Visual Studio solution, I have another executable, ProgramB, which doesn't use LibraryB but instead references the libcurl library directly, and this works fine. Unless I include LibraryB in which case the unresolved errors come back.
Suggestions? Thoughts? Thank you!
The problem is that you are linking against the static version of the library but building against the shared version (DLL) of the library. When building against the shared version symbols are exported using __declspec(export) (or a .def file) which causes the compiler to add __imp to the beginning of the exported symbol name.
Te resolve this you can add CURL_STATICLIB to the preprocessor definitions of the dependent project to build against the static library correctly.
Related
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
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?
I keep getting
error LNK2019: unresolved external symbol _MH_CreateHook#12 referenced
in function _DllMain#12
yet I put
#include "MinHook.h"
#pragma comment(lib,"libMinHook.x64.lib")
and have the locations to include and libs set
The library can be downloaded from here https://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=44326
or from https://github.com/TsudaKageyu/minhook
I have even compiled the source and yet the same problem :/
Make sure you are building your application as a 64 bit application if you are using a x64 library. You can not use a 64 bit library with a 32 bit application.
Forgive the convoluted title.
The setup for this problem is as follows:
I have an open source lib I have built into a bunch of .libs (VTK if you were curious)
I have a library that uses the aforementioned static lib. Lets call it Lib A.
I also have an application that uses the aforementioned library (i.e. VTK) AND also uses Lib A.
During build time, I get a linker error telling me that a function called from Lib A has already been defined in a library that is linked to the application (error: LNK2005)
Any ideas on how to fix this short of switching everything to be dynamically linked?
Alright. I figured out what I was doing wrong.
Lib A was using the statically built version of VTK while the main app was linking against a dynamic-linked version of VTK.
So the problem really was that I had the same functions defined in a .lib and a .dll which caused the linker to fail.
I'm writing a c++ program that is dependent on a c/c++ 3rd-party library. I compiled the 3rd-party library as a static library both on windows and linux. My code works correctly on linux, but on windows there's linking error indicating that my code fails to resolve the symbols in the 3rd-party library.
After some debugging, I found that the unresolved references are non-inline functions in that library and inline functions can be resolved (I've tested). Originally I thought it's the incompatibility between gcc and msvc, because I compiled the .lib files using msvc while attempted to compile my code with g++ through mingw. I recompiled the library with g++ on windows and there's the same problem.
Any idea what might be the solution?
=========Edit===============
Just to clarify, the 3rd-party library is not templated.
I found the problem: I put both the lib*.a (generated on linux) and .lib (generated on windows) of the 3rd-party library in the same directory, because I want this code to be cross-platform. While compiling my code in windows with g++, it seems link to the lib.a files in priority which leads to "unresolved symbols" error. I deleted the lib*.a files and g++ now link to the *.lib file, and works correctly.