Unresolved external symbol _glfwInit due to 32-bit/64-bit mismatch - c++

How do I link the library in a way that visual studio 2015 can actually see it?
Here's a few screenshot of my folders:
glfw3, glfw3/include/glfw/, glfw3/lib
I've attempted to link these folders into visual studio, under "vc++ directories => include/library directories as such: include, library
also linking the same to my project directly, under linker => input => additional dependencies
to me, that seems like everything is correct (this is how it was in the tutorial i am following, learnopengl.com)
note: I am also doing the same with the GLAD library, which that has a .c file that I put directly into my sources, along with the header files linked the same way as with GLFW.
but despite trying to run this code:
#include <glad/glad.h>
#include <GLFW/glfw3.h>
int main() {
glfwInit();
return 0;
}
it will always return this error, or similar ones:
1>------ Build started: Project: opengl_test, Configuration: Debug Win32 ------
1> main.cpp
1>main.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function _main
1>C:\Users\Honza\Desktop\C++ programs\lib\glfw3\lib\glfw3.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86'
1>c:\users\honza\documents\visual studio 2015\Projects\opengl_test\Debug\opengl_test.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I'm guessing there is something wrong with how I linked the libraries. I am willing to literally re-install visual studio if I have to, just please give me some possible solutions. I want to start learning opengl but all this jazz with linking libraries is leaving me frustrated and confused.
EDIT: The problem here was that I was using 64-bit GLFW binaries instead of the 32-bit ones, and compiling in 32-bit. I've fixed that, and now I get even more errors:
1>------ Build started: Project: opengl_test, Configuration: Debug Win32 ------
1>libglfw3.a(init.c.obj) : error LNK2019: unresolved external symbol ___chkstk_ms referenced in function __glfwInputError
1>libglfw3.a(init.c.obj) : error LNK2019: unresolved external symbol _vsnprintf referenced in function __glfwInputError
1>MSVCRTD.lib(vsnprintf.obj) : error LNK2001: unresolved external symbol _vsnprintf
1>libglfw3.a(context.c.obj) : error LNK2019: unresolved external symbol _sscanf referenced in function __glfwRefreshContextAttribs
1>MSVCRTD.lib(vsnprintf.obj) : error LNK2001: unresolved external symbol __vsnprintf
1>C:\Users\Honza\Documents\Visual Studio 2015\Projects\opengl_test\Debug\opengl_test.exe : fatal error LNK1120: 4 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

You write that you tried to link "these folders", while in fact, you need 2 separate things in order to use a function from a static library.
Use the proper header file so compilation succeeds. From the error you quoted, compilation went well. The program knows there is an external function named _glfwInit.
Link to the specific library (.lib file). Looks like you placed a path of a folder and not the full path of the .lib file.
Under Linker => input => additional dependencies, place the full path of the gfw3.lib file.

I faced the same problem while following learnopengl.com, The issue is that you need to rebuild glfw library with cmake again,
but this time when you choose visual studio 2015 or whatever for your generator for this project, you must also choose: OPTIONAL PLATFORM FOR GENERATOR -> x64
you can make sure that every thing is OK when you build glfw inside Visual Studio and the platform that appears is x64

Related

LNK2019 error when using a library installed with vcpkg

I have installed libraries with vcpkg using the correct triplet :
C:\Users\***>vcpkg list libnoise
libnoise:x64-windows 1.0.0 A general-purpose library that generates three-d...
Then I have executed the following command :
C:\Users\***>vcpkg integrate install
Applied user-wide integration for this vcpkg root.
All MSBuild C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/Windows/vcpkg/scripts/buildsystems/vcpkg.cmake"
But in my Visual Studio 2019 project, with an x64 project, only the headers have been successfully integrated :
#include <noise/noise.h> // The header is found as well as the definition of noise::module::Perlin
int main()
{
noise::module::Perlin noise; // The implementation is not found
}
When trying to compile this, I get :
1>------ Build started: Project: Mayak, Configuration: Debug x64 ------
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl noise::module::Perlin::Perlin(void)" (__imp_??0Perlin#module#noise##QEAA#XZ) referenced in function main
1>NoiseVideoGenerator.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl noise::module::Perlin::Perlin(void)" (__imp_??0Perlin#module#noise##QEAA#XZ)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl noise::module::Perlin::~Perlin(void)" (__imp_??1Perlin#module#noise##UEAA#XZ) referenced in function main
1>NoiseVideoGenerator.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl noise::module::Perlin::~Perlin(void)" (__imp_??1Perlin#module#noise##UEAA#XZ)
1>C:\Users\sylva\source\repos\Mayak\x64\Debug\Mayak.exe : fatal error LNK1120: 2 unresolved externals
1>Done building project "Mayak.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
On a side note, I have looked for the name of the .lib files of the noise library and tried to add them in the Linker > Input properties, it still doesn't work.
What did I do wrong ?
To enable AutoLink, select your current project and go to properties. (Alt-Enter) Make sure you edit the right configuration. Then go to Configuration Properties -> vcpkg and make sure AutoLink is enabled.
It has been fixed by the developers, on GitHub : https://github.com/microsoft/vcpkg/issues/14127

Unresolved External Symbol __imp__Py_Finalize

I literally just got Python.h to link to my Visual Studio 2017 IDE and then when I ran it, it spat this error out for me.
I use VS2017, and I am learning C++, so I have no idea why this is happening. I linked my Python.h file's directory in the project properties.
Full Build Logs:
1>------ Build started: Project: PyC++, Configuration: Release Win32 ------
1>PyC++.obj : error LNK2001: unresolved external symbol __imp__Py_Finalize
1>PyC++.obj : error LNK2001: unresolved external symbol __imp__Py_SetProgramName
1>PyC++.obj : error LNK2001: unresolved external symbol __imp__Py_InitializeEx
1>C:\Users\maste\source\repos\PyC++\Release\PyC++.exe : fatal error LNK1120: 3 unresolved externals
1>Done building project "PyC++.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Try to include pythonxx.lib(such as python26.lib) in your references.
The answer is simple, like #Xiaoying Sun has stated, put the python38.lib file in your references, however, you're required to put it in your VC++ directories, this way it will work.

Code::blocks: |undefined reference to `_imp__glewExperimental] and glewGenBuffers [duplicate]

I am trying to build an opengl project in Visual Studio 2012. I wanted to statically include glew library, so I built it from source and copied the generated glew32sd.lib to my lib directory. I gave this lib path to Visual Studio and put "glew32sd.lib" to my additional dependencies in VS.
Now when I compile a sample code in main.cpp:
#define GLEW_STATIC
#include<GL/glew.h>
int main(){
glewInit();
return 0;
}
I get the following error:
1> main.cpp
1>glew32sd.lib(glew.obj) : error LNK2019: unresolved external symbol __imp__glGetString#4 referenced in function _glewGetExtension#4
1>glew32sd.lib(glew.obj) : error LNK2019: unresolved external symbol __imp__wglGetCurrentDC#0 referenced in function _wglewInit#0
1>glew32sd.lib(glew.obj) : error LNK2019: unresolved external symbol __imp__wglGetProcAddress#4 referenced in function _wglewInit#0
1>C:\Projects\OpenGL\opengl\Debug\opengl.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
In my understanding, this error should be because compiler could not find the definitions for the function call.
Here are a few relevant snapshots:
The Library dependencies of my project
Path to libs
Why could this error be coming? I tried rebuilding the solution but that didn't help either. Any suggestion would be helpful.
You have two problems in the linker settings:
You can link against the statically linked version of glew or the dynamically linked one, but never against both. So if you want glew statically linked remove glew32d.lib (or glew32.lib in release mode) from the additional dependencies.
Glew requires you to also link agains the opengl library. Add OpenGL32.lib to the additional dependencies.

OpenNN include unresolved external symbol in Visual Studio 2017

My name is Hector Perez. I am an international student from Guatemala studying Computer Science and Music. I am very interested in using OpenNN for a Computer-Music project. I have tried today to create a Visual C++ project that has the appropriate dependencies (as stated in http://www.opennn.net/documentation/building_opennn.html).
However, I think after some attempts, I realized I was probably doing something wrong. I include my procedure after the end of this message.
I would highly appreciate it if you can point me to a tutorial where it performs a project build step by step.
My procedure:
Created a C++ project in Visual Studio.
Right clicked the application folder in the Solution Explorer,
Went to Properties under VC++ Directories.
Copied the full paths for the dependencies into 'Include Directories'.
I built the project, but errors occur - as if the files are not found.
They are found if I explicitly use #include, but that's probably not the intent.
This is the kind of error I get. (JUST WAY BIGGER ! )
... SimplePatternRecognition.obj : error LNK2019: unresolved external symbol "public: void __cdecl OpenNN::NeuralNetwork::save(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (?save#NeuralNetwork#OpenNN##QEBAXAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function main
1>...C:\Users\Owner\documents\visual studio 2017\Projects\SimplePatternRecognition\x64\Debug\SimplePatternRecognition.exe : fatal error LNK1120: 46 unresolved externals
1>Done building project "SimplePatternRecognition.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I solved it!
I put on this repository my sample code and my steps to add OpenNN to Visual Studio: Look at the README.md file.
REPOSITORY: https://github.com/HectorGit/allMyOpenNNCode

Keep getting error LNK2019: unresolved external symbol

The IDE I use is Visual Studio 2010 Professional, and the library I use is ICU4C 4.8.1 for Win32 for MSVC10.
I have rebuilt all the source codes according to the manual for both Debug and Release, and all tests are successfully passed.
Then I do in the way I do with Boost.
I included \include in C/C++ > Additional Include Directories in Proprieties, which seems to be fine.
I also included \lib in Linker > Additional Library Directories.
However, I keep getting error LNK2019: unresolved external symbol.
Source Code:
#include <unicode/uchar.h>
int main () {
UBool b = u_isprint('c');
return 0;
}
Error
1>ClCompile:
1> Main.cpp
1>Main.obj : error LNK2019: unresolved external symbol _u_isprint_48 referenced in function _main
1>C:\Users\ ... \Documents\Visual Studio\Finger-Printing-Non-ASCII\Debug\Finger-Printing-Non-ASCII.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
Apart from setting additional include directories and library directories, you have to actually link to the library. Go to Project Properties -> Linker -> Input and write the name to the .lib in Additional dependencies textbox. HTH