I wanted to create new OpenGl/GLEW/GLFW Visual Studio project in 64 bit. So I downloaded glew binaries and glfw binaries. My project settings are as followed:
Additional Libraries:
glew-2.1.0\lib\Release\x64
glfw-3.3.bin.WIN64\lib-vc2019
Additional Dependencies:
glew32s.lib (I dont get why its named glew32 and its in x64 folder)
opengl32.lib
glfw3.lib
With such setting for every glew function like glGenBuffers or glUseProgram or anything I get LNK2001 unresolved external symbol error.
Any clue where I did a mistake?
(And since I am a new to all of these can someone explain why do I have to link opengl32.lib on 64 bit app and why there is no opengl64.lib and so on?)
When you want to link the static glew library on windows, then you've to define the GLEW_STATIC preprocessor definition when you compile your application.
See Building Your Project with GLEW
and GLEW - why should I define GLEW_STATIC?.
If you use gnu (g++), then just add -D GLEW_STATIC to the build command.
In Visual Studio add GLEW_STATIC to the Project properties -> C/C++ -> Preprocessor -> Preprocessor Definitions
Well it seems to work when I link it dynamicly (glew32.lib instead of glew32s.lib).
Still no clue why static linking didnt work out.
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
To the best of my knowledge, this isn't a duplicate of an existing question. This question is specifically about Visual Studio's auto-linking SDL2 libraries.
I've installed SDL2 (x64-windows variant) with vcpkg:
vcpkg install sdl2 --triplet x64-windows
And I've made vpkg libraries available to Visual Studio:
vcpkg integrate install
My VS 2019 project is configured to use the Console subsystem, and my main program looks like that:
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
int main(int, char*[])
{
}
Why do I need to specify SDL_MAIN_HANDLED? It seems that auto-linking with SDLmain2.lib doesn't happen for some reason?
If I don't specify SDL_MAIN_HANDLED, linking fails:
unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ)
I've also tried adding extern "C" on main() declaration but to no avail.
I've written many apps with SDL2 but this is the first time I'm using vcpkg to locate it.
It appears to be a deliberate decision made by those who created the package.
If you look at the package description file, you can see that SDL2main.lib is being moved into the manual-link directory. I'm not familiar with vcpkg, so I don't know how exactly you can "manually link" against it, but I assume it's possible.
Linking SDL2 manual-link libraries while using vcpkg with VS
My answer is a follow-up to #HolyBlackCat, thanks for help.
In your case, the directory is x64-windows, by default it is x86-windows.
Right-click on your project -> Properties -> Configuration Properties
First step
Go to: VC++ Directories -> Library Directories
For Debug configuration, add:
$(VCPKG_ROOT)\installed\x64-windows\debug\lib\manual-link
For Release configuration, add:
$(VCPKG_ROOT)\installed\x64-windows\lib\manual-link
Second step
Go to: Linker -> Input -> Additional Dependencies
For Debug configuration, add:
SDL2maind.lib
For Release configuration, add:
SDL2main.lib
Now you should not be bother by "main() redefinition" errors.
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.
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 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.