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've got this MFC application I'm working on that needs to have an embedded database. So I went hunting for a slick, fast "embeddable" database for it and stumbled accross SQLite.
I created a DB with it, and I created a static library project with Visual Studio 2008. the library project will be used in another main project.
In the library project, I created a class DBClass with a method AddFeedToDB(CFeed f). The library project uses the .lib file from codeproject (cppsqlite3.lib).
When compiling the static library, no error is detected, but when I try to use the library project file in the main project, I get these type of errors:
error LNK2019: unresolved external symbol "public:void __thiscall
CppSQLite3DB::close(void)" (?close#CppSQLite3DB##QAEXXZ
referenced in function "public: int __thiscall
CTalkingFeedsDB::AddFeedToDB(class CFeed,char const*)" (?
AddFeedToDB#CTalkingFeedsDB##QAEHVCFeed##PDB#Z
What am I missing?
I know it is already 2 years since this question... but i run in the same situation here. Added all the header files... added the lib directories.. and keep having this error.
So i added manually the lib to the Configuration Properties -> Linker -> Input -> Aditional Dependencies
and all works for me.
It happened to me more than once that I thought symbol XXX (i.e. ?close#CppSQLite3DB##QAEXXZ) was in the import lib, while the actual symbol was __impXXX (i.e. __imp?close#CppSQLite3DB##QAEXXZ).
The reason for the linker error is then to be found in the compilation step: the compiler will generate the ?close#CppSQLite3DB##QAEXXZ symbol to be imported, where it should generate __imp?close#CppSQLite3DB##QAEXXZ. This often means that the function declaration itself didn't have __declspec( dllimport ). Which may be caused by some preprocessor symbol not being defined. Or the __declspec not being there at all...
Don't know if it is your case, but the imp prefix may mean that you are compiling a x64 library in a Win32 project.
You either need to link the codeproject SQLite lib to your executable, or to include the sources files in your project directly. (Which one did you do ?)
I would follow these steps:
think about what library or .obj file you expect the symbol to be exported by.
check whether it actually does export that very symbol (check character-wise). Sometimes, it's the calling convention differs.
check if the library you expect to contain the symbol is known to the linker - first check for the 'additional libraries', then check if the library is actually found (I mostly do this by using filemon.exe from sysinternals, and look for link.exe to open the lib file. )
After thinking a while, you may find that your library project will not export the sought for function. That function is in the database lib. You should add that lib to your main project. It's no use adding it to your static lib project.
The compiler and linker will not link one library into another (unless one is a DLL). You need to specify both libraries (cppsqlite3.lib and your own static library) in your main project.
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.
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 5 years ago.
I tried multiple PDF lybrary and MUPDF is my last chance to build my own small PDF application. But here I also have problems. Before that I had problem with LNK4098: defaultlib 'MSVCRT', but I solved that to set for all MUPDF library /MDd version. Most errors is solved after that, but still I can't to solve this:
error LNK2001: unresolved external symbol "void __cdecl pdfapp_open(struct pdfapp_s *,char *,int)" (?pdfapp_open##YAXPEAUpdfapp_s##PEADH#Z)
//more 3 errors
As MuPDF written on C, I do this:
extern "C" {
#include <pdfapp.h>
#include <mupdf\fitz\context.h>
}
But I get this errors:
error LNK2001: unresolved external symbol pdfapp_open
//more 3 errors
There is only three functions what I use in my application. I checked libs and headers linking, I set my project Debug, x64, /MDd also but I get the same.
Honestly, I can't find this three functons in no one libs. I'm not a expert in programming but I know that functions strings should be finding in libs, doesn't? What does mean this errors in my case?
Either your linker is failing to find the import library for mupdf or you have a name mangling/decoration type issue.
Once you download and build mupdf, there should be an import library for you to link to. Are you linking to it? Look in your project linker settings under Linker >> Input >> Additional Dependencies. Have you added such an import?
If not, add it in. It shouldn't be hard to find. It is likely right next to the mupdf DLL that you downloaded (or built).
Assuming you have added it, your next step is to verify that you are properly finding it. Look at the build output. Are you getting a warning about it? No, change the Linker >> General >> Show Progress to "Display all progress messages" and build again. Is there a warning about the library or function?
Last possibility that I can think of is that the DLL is actually exporting its functions as C++ (i.e. with name decoration), not as extern "C". In that case and your extern "C" brackets don't belong there. Or perhaps vice versa (i.e. maybe you failed to use extern "C" in all places you #include it). I can see that your example uses it but is that all the places?
If you are building the mupdf.DLL be sure it is being built the same way and with the same calling convention as your client code.
I am trying to use CImg library for some image processing task. Using VS 2012 on Windows 7 x64, I am building a project to create dll that I need for my application. I have included the only header file CImg.h from the library. But as soon as I initialize an CImg object, I get bunch of unresolved external symbol errors. One sample error is as follows:
layer.obj : error LNK2019: unresolved external symbol __imp_SetDIBitsToDevice referenced in function "public: struct cimg_library::CImgDisplay & __cdecl cimg_library::CImgDisplay::paint(void)" (?paint#CImgDisplay#cimg_library##QEAAAEAU12#XZ)
Can anyone explain to me what am I doing wrong and how to fix it? (I am a newbie when it comes to C++ terminologies.)
there is nothing other than the header file in the CImg library to link to.
You cannot link to a header file. If it is a header-only library, then you do not need to link anything. You include the header file and the functions it defines are compiled directly. That appears to be the case for CImg; the documentation says it is a self-contained template library that consists of only a single header file. So indeed, all you need to do is include it and you're off to the races.
The unresolved external symbol errors are coming from somewhere else. You have to read the error messages and look at the function names to see where.
A couple of hints:
The __imp_ prefix suggests that you're looking at a Windows API function.
If you didn't know that, you could always ignore the prefix and Google the readable part of the name, in this case, SetDIBitsToDevice. Chances are very good you'll turn up the documentation or at least something that points you in the right direction.
Indeed, in this case, you get right to Microsoft's SDK documentation for the SetDIBitsToDevice function. It's a Windows API function alright, and Microsoft's documentation always tells you what library you need to link to in order to consume it. Look at the bottom of the page:
Header: Wingdi.h (include Windows.h)
Library: Gdi32.lib
DLL: Gdi32.dll
The CImg library header file has obviously already included the Windows.h header file, or you'd have gotten a compile-time error. You're getting a linker error, which means that you have not told the linker to link in the Gdi32.lib library. This is what will allow you to call GDI functions. It is a stub that facilitates calling functions exported from Gdi32.dll.
In general, when building a Windows application, you will want to link with, at minimum, kernel32.lib, user32.lib, and gdi32.lib.
This question contains more information on dealing with undefined symbol errors, and also how to configure your linker. In Visual Studio, go to Project Properties → C/C++ → Linker → Input → Additional Dependencies. Or add #pragma comment(lib, "gdi32.lib") to a source file (your precompiled header is a good place, usually named StdAfx.h).
This function is part of the win32 API, specifically in GDI. You need to change your project settings to link with Gdi32.lib
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162974(v=vs.85).aspx
I am trying to statically link this library into my VS C++ project.First I compiled the source as a static lib.Linked it via VS Project properties.The .exe project works fine.Then I read this MS manual on how to compile the static lib into the executable and following the steps outlined there now if I am running the executable I am getting these errors:
Error 3 error LNK2019: unresolved external symbol __imp__glBlendFunc#8
referenced in function _text_buffer_render E:\Documents\visual studio
2012\Projects\XXXXEngine\FreeTypeTest\text-buffer.obj
Error 4 error LNK2019: unresolved external symbol __imp__glBindTexture#8
referenced in function _text_buffer_render E:\Documents\visual studio
2012\Projects\XXXXEngine\FreeTypeTest\text-buffer.obj
To me it seems like GLEW.lib errors.Does it mean I have to link also glew.lib statically as the freetype GL depends on it ?
Also, can I just use the lib with the executable without adding it to references, or it won't work in release build?I am asking it as I am quite confused with how the static linking should be done.I mean,now the executable works without adding the library to the project reference.Then why can't it be used just like this?
To me it seems like GLEW.lib errors
They are not, glBindTexture() is an OpenGL function. The MSDN library page is here. Scroll to the bottom, it shows you the .h file that declares it (you already that right since the compiler didn't complain) and the .lib you need to link.
Right-click your project, Properties, Linker, Input, Additional Dependencies setting. Add opengl32.lib. Or to use the upvoted answer's suggestion, you can inject the linker directive in your source code:
#include <gl\gl.h>
#pragma comment(lib, "opengl32.lib")
Have you tried to pragma mark your library?
Like so:
#pragma comment(lib, "any.lib");
I am building an application as a library, but to make sure I can get the output that I'd like, I switched it over to produce an exe. As soon as I did, I got several errors about unresolved external symbols.
At first I thought that I didn't have a path set to the 3rd party library that I was referencing, so I added the folder to my path variable and even added it to my include, references, and source files, just to make sure I had all the paths.
I still get the error:
error LNK2019: unresolved external
symbol "__declspec(dllimport) public:
static void
__cdecl xercesc_2_8::XMLPlatformUtils::Initialize(char
const * const,char const *
const,class xercesc_2_8::PanicHandler
* const,class xercesc_2_8::MemoryManager *
const,bool)"
(__imp_?Initialize#XMLPlatformUtils#xercesc_2_8##SAXQBD0QAVPanicHandler#2#QAVMemoryManager#2#_N#Z)
referenced in function "void __cdecl
xsd::cxx::xml::initialize(void)"
(?initialize#xml#cxx#xsd##YAXXZ)
The reason that I'm asking it here is because in Visual Studio, when I built it as a library, I didn't get these errors, but as a dll and exe, I do.
Anybody have any thoughts?
Building a library, the linker doesn't need to resolve imported symbols. That happens only when it starts linking object files and libraries together.
That's why you only started seeing the error when building an executable.
Indeed, in VC2008 (and 2005, if I remember well), use the project properties -> Linker -> Input -> Additional dependencies. The libraries you need are to be separated by spaces (odd, hey?)
Good Luck!
You also need to specify that you wish to link against that library in particular. The link paths merely tell the linker where the data you need to find is, not what to look for. You will also need to specify that you are linking against the library in question (xerces?).
Unfortunately, I don't know how to specify this in MSVC, but it's probably somewhere under 'Linker Options'.
As #coppro said, you need to specify that you want to link with that library. When you build an EXE or DLL, a linker is run, and it needs to find all the functions you are using, but to build a library, the librarian is run, and it doesn't have to resolve all function references (but when you use that lib in an EXE, you'll have to, again).
So go to the project's options, Linker Options, Input, and list the library that defines the missing function (xerces.lib?) under Additional Library Paths. You might need to add its location under Additional Library Paths.