Very new to C++ and the VS IDE, and I'm trying to start working with Dear imGUI and openGL with a hello world function. I've added resources with lib and dll files before for c++ (for openGL), but not something like imGUI which only has .h and .cpp files - feels like I'm struggling to understand how to inform VS of where those are and how they link up.
Here's an example of an error I saw when building:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _glfwGetWindowSize referenced in function "void __cdecl ImGui_ImplGlfw_NewFrame(void)" (?ImGui_ImplGlfw_NewFrame##YAXXZ) imGUITrial1 ..\Coding\imGUITrial1\imgui_impl_glfw.obj 1
So I opened up imgui_impl_glfw and found the function, and it appears to reference a function declared in glfw3.h...but that function looks like just a declaration, with no definition. I had previously added each folder with these files in it to the project additional directories, so I went ahead and added glfw3.h as a resource to my sources folder in the solution as well. That didn't change anything, so now I'm not sure how to find where the function is actually defined, or if the issue is that I need to somehow tell VS that this file exists in a another nested properties window?
Maybe it will help to have a screenshot of the solution. These are largely files copied from the github that I haven't changed (which I chose from looking through the backend examples), so I don't think I broke anything in the files themselves.
enter image description here
Related
Probably the most asked question on GLFW ever. But I've tried everything I can think of and after 3 hours of googling I give up.
What I've been able to understand is that this error occours when:
The compiled code for function makes a reference or call to symbol, but that symbol isn't defined in any of the libraries or object files specified to the linker.
That means I must have simply failed linking the library as I understand.
Ok so located in: "C:\dev\MyVSProjects\MyWorld\dependencies\OpenGL\GLFW\lib-vc2015"
is my glfw3.lib file.
Inside of my solutions Property Pages I set "Additional Library Directories" to "$(SolutionDir)dependencies\OpenGL\GLFW\lib-vc2015" which is where the above file is located relavtive to the .sln file.
Then finally in the linker I set Additional Dependencies to: "opengl32.lib;glfw3.lib;%(AdditionalDependencies)"
Thats pretty simple, and I just dont understand how that cannot be linked correctly.
Im using glad in my project btw and it works correctly, also both the glfw3.h and glad.h files are found. (And yes im including glad.h first).
Yet every GLFW function gets the unresolved external symbol error.
So my question is why am i still getting these unresolved external symbol linking errors.
Alright so it turns out I did do everything correctly. The 64-bit binaries simply does not work with Visual studio 17...
If your experienceing the same issue simply get the 32 bit binaries.
I've been trying to resolve a serious memory leak in my C++ application. I've narrowed it down to the creation of MySQL connections and the mysqlpp doc (plus lots of googling) indicates that I need to call mysql_library_end() to tell the C API to clean up after itself.
When I try to use this function, Visual Studio throws a Link error for "mysql_library_end()". Fair enough, I didn't tell it where to look.
When I include the header file mysql.h and rebuild, Visual Studio then throws a Link error for "mysql_server_end()" instead. I checked mysql.h (in my build environment) and the only reference to the function I want to use ( mysql_library_end() ) is:
#define mysql_library_end mysql_server_end
There is a function declaration for mysql_server_end() in the file but Visual Studio can't seem to see it. I'm just stuck with this Linker error and I have no idea why it is happening.
Can anyone help?
Cheers,
Adam.
EDIT
I'm using Visual Studio 2005.Error message from the IDE is:
Error 6 error LNK2019: unresolved external symbol _mysql_server_end#0 referenced in function "public: __thiscall CConnectionParams::~CConnectionParams(void)" (??1CConnectionParams##QAE#XZ) CConnectionParams.obj
Where CConnectionParams is the .cpp file of the call to mysql_library_end().
Found the solution. The header file on it's own isn't enough, the whole library needs to be linked in. There are two libraries that can be used to interface the MySQL C API: libmysql.lib and mysqlclient.lib. One is static, one is dynamic. The one that worked for me was libmysql.lib. Note that I therefore didn't need to #include mysql.h as a result.
To link this library in Visual studio you just need to include it as part of your project dependencies. I dragged it into the solution tree from it's directory, the mysql install, but this is not a very elegant method because it only works for VS and not other build environments.
I was advised by some of you not to long ago to use FreeImage as a library for image processing in C++.
I now have some trouble in getting the library to work (still relatively new here).
I've tried loading the various vcxproj and sln tiles and they gave me a blank project. Since there isn't any installation instructions provided for that, I gave up on making it a visual studio solution.
I next tried the old-fashion way of compiling the source code using the Makefile and then adding "FreeImage/Source" to the linker. While the IDE does not raise any red flags when I call functions declared in FreeImage.h, it gave me a bunch of "error LNK2019: unresolved external symbol" during compilation, as if the functions do not exist. What I suspect is that the IDE could not find the .cpp files that define the said functions, but I still get that same problem when I added FreeImage/Source/FreeImage to the linker.
Now when I directly included some of the .cpp files (i.e. Plugin.cpp and FreeImage.cpp) for a test, I get even more unresolved external symbol errors as well as things like "inconsistent dll linkage" for this within... for example FreeImage.cpp:
const char * DLL_CALLCONV
FreeImage_GetVersion() {
static char s_version[16];
sprintf(s_version, "%d.%d.%d", FREEIMAGE_MAJOR_VERSION, FREEIMAGE_MINOR_VERSION, FREEIMAGE_RELEASE_SERIAL);
return s_version;
}
So, I am totally stuck. What am I doing wrong? I felt I've followed the adequate steps in adding library dependencies, such as adding the specific folders that are immediate parents to the relevant .h and .cpp files in C/C++ -> General -> Additional Included Directories and Linker -> General -> Addition Library Directories.
Some help will be greatly appreciated!
Using FreeImage v3.15.3 I had no problems converting the VS2008 project to VS2010.
Also the building worked as expected. But when I linked to the static lib, I got some unresolved externals. First I tried al kinds of tricks setting /MT /MD linking, but that did not solve these linking problem.
After reading Some Newbie's comment I dug into freeimage.h. There I found a macro switch FREEIMAGE_LIB that controls the calling conventions of the function.
Use a #define FREEIMAGE_LIB before including the freeimage.h file. That way you can easily static link to FreeImage.lib
I wrote a porgram with a few standard dialogs in an SDI (Doc/View enabled) project.
Now that I want to send it to some friends i did set the Use of MFC Use MFC in a static library.
But when i try to build the solution i get the following error:
error LNK2001: unresolved external symbol _IID_IWICImagingFactory
My problem is, that i donĀ“t know what exactly this interface id is, because i did not write any code for COM manually or using any image factory things or equal...
Im a bit lost atm...
May anyone tell me how to solve this and make it work with the static MFC usage?
Thanks in advance!
There is also a .lib file:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\ windowscodecs.lib
IWICImagingFactory is defined in wincodec.idl
Locate and add wincodec.idl to your MFC project
Rebuild and MIDL compiler will generate wincodec_i.c and wincodec_i.h
wincodec_i.* files contain the declaration and definition of _IID_IWICImagingFactory
This wasn't my exact problem (different .idl), but same linker error. Google found your question anyway. I copied the .idl file out to a new directory, launched a VS command line, and ran this:
midl thefile.idl
After it made my .c file, I just copied the const for the IID that I needed, and threw away the rest.
I'm a real beginner and I'm programming in C++ using Visual Studio.
I've a simple cpp code that recalls some functions written in a .c and .h file. I included that file by means of #include directive and the IDE "sees" the function.
When I compile, I get this
Error 7 error LNK2019: unresolved external symbol _IMUsendAccelToFIFO referenced in function _main D:\Cprojects\Pencil\Pencil\Pencil.obj Pencil
What am I missing here?
Thank you all!
It is a linker error, not a compiler error. The compiler is happy, it saw the declaration of function in the .h file. The linker isn't, it cannot find the definition of the function.
Add the .c file to your project.
If you get an error in Visual Studio you can actually google for the error code and you will get pretty extensive information for that. In this case, googling LNK2019 gives this MSDN page as first hit, which also provides some examples on how you get the error.
Your vendor should have provided some .lib files for you (usually found in a folder named lib?). Make sure that these are added in the project via:
Project > Properties > Configuration Properties > Linker > Input > Additional Dependencies
You could also see if there is any "get started" information for you from your vendor, which explains which dependencies you have to include in your project.
If you feel unsure of what a compiler and what a linker does, pick up a book that explains it, or browse some free alternatives.
Are you using ghettopilot? that's the only reference I can find on the web to the function you're missing. If you are, then you need to include the .lib file for that library in your link options.
Visual Studio will compile .c files as C and .cpp files as C++ by default, and this can cause trouble because if you want to call functions defined in a .c file from a .cpp file, then you must wrap the header in extern "C" { }, as the compiler will expect all functions not declared extern "C" to be from C++. This is because of an implementation detail called name mangling. Alternatively, you could force all files to be compiled as C or as C++ in the project settings.
Solved! Thank you very much!
The libraries I was using needed to be built. I tried but I couldn't build them as I used to get "heap space" error!
I installed Visual Studio 2005 (with which the code was produced by the vendor) and it worked at first attempt! There are probably some back-compatibility issues..