linking errors after moving my class to "vc/include/" directory - c++

I am having "unresolved external symbol" linking error for a simple class i wrote along with a header file in VS 2008 using c++.
I moved this class to VS 2008's include directory, so that I don't have to copy the files from one project to other every time creating a new project.
I included the header file in some new project, the file got included alright, I can also see the list functions and data members inside the object of that class file, [ VS 2008 shows me this list after I type '.' ]
But this is not the weird part, the weird part is, the files which I moved to include directory works fine in the original project in which I wrote them.

As well as including the header file in your new project, you will need to add the implementing cpp file, otherwise you will get
"unresolved external symbol"
link errors.

to understand "unresolved external symbol" issue please refer to:
Unresolved external symbol in object files

Related

Resolving and understanding external symbol errors in Visual Studio (C++)

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

LNK2019 unresolved external symbol using GLFW

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.

LNK2001 on all private methods [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I have a project with source code, and a TestProject in same solution.
The test file using GTest framework in the TestProject has got an #include of the header file Composite.h from main project.
In the body of the first GTest, I instantiate the Composite class declared in the Composite.h. This line gives a compile error LNK2001: unresolved external symbol on each of the private methods of the Composite class.
Code in the myTest.cpp file looks like that
#include "Composite.h"
TEST(testComposite, testCase1)
{
Composite c; // error LNK2001
// my test here;
}
What's wrong with this instantiation ?
EDIT
I linked to the library containing the implementation of private methods in Composite class. Also, i tried alternatively to #inlcude the .cpp for the source code of this class. Either solution do not fix the problem.
EDIT -- QUESTION
Can this be that the folder with the moc files for the Composite classes and its parent class (with Q_OBJECT defined) are unseen ?
I tried adding in the Test Project properties' additionnal Directories the folder containing the moc files. This does not work either.
There should be nothing wrong with the instantiation. I assume that there is a Composite.cpp that contains your missing or unresolved code.
You will need to add this Composite.cpp into your project or link your application to the library that contains the Composite.cpp
The includes have nothing to do with the linking of a program. What you include matters for the compilation and that occurs before the linkage. To resolve the problem you show here, you need to link with whatever(object file, library) contains the implementation of the private methods you mention.

Link mysql_library_end()

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.

Getting FreeImage to work with Visual Studio 2010

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