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.
Related
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
I'm using boost in my project. I've downloaded pre-compiled binaries from here http://boost.teeks99.com/
When linking I receive such error:
Error 18 error LNK2005: "public: void __cdecl boost::thread::join(void)" (?join#thread#boost##QEAAXXZ) already defined in boost_thread-vc110-mt-1_52.lib(boost_thread-vc110-mt-1_52.dll) C:\Oleg\projects\MBClient\FastNativeAdapter\libboost_thread-vc110-mt-1_52.lib(thread.obj) FastNativeAdapter
Why boost contains two lib with so similar name, what is the difference between them?
libboost_thread-vc110-mt-1_52.lib
boost_thread-vc110-mt-1_52.lib
How to fix linking error?
upd I've compiled boost myself. I've added boost_1_53_0\stage\lib directory to linker. This directory actually contains 3 "copies" of "each" file, for example:
boost_atomic-vc110-mt-1_53.dll
boost_atomic-vc110-mt-1_53.lib
libboost_atomic-vc110-mt-1_53.lib
So It's clear what compiler claims about. Somehow it can't understand which version of lib file to use. It's likely connected with static/dinamic linking, but I still can not find the solution. I'm sure my problems is pretty common so I hope someone can suggest me what to do.
I've tried to delete all "libboost*" files from folder but then I receive such error:
Error 15 error LNK1104: cannot open file 'libboost_date_time-vc110-mt-1_53.lib'
I've tried to delete all "boost*lib" files from folder but then I receive such error:
Error 15 error LNK1104: cannot open file 'boost_thread-vc110-mt-1_53.lib'
Then I copied boost_thread-vc110-mt-1_53.lib back and I receive a lot of errors like that:
Error 16 error LNK2005: "public: virtual __cdecl boost::detail::thread_data_base::~thread_data_base(void)" (??1thread_data_base#detail#boost##UEAA#XZ) already defined in boost_thread-vc110-mt-1_53.lib(boost_thread-vc110-mt-1_53.dll)
So when there are no boost_thread-vc110-mt-1_53.lib compiler claims that it's missing, when there is boost_thread-vc110-mt-1_53.lib compiler claims that "function is already defined". Probaly somehow I do use dinamic and static linking at the same time or something like that?
upd2 i've uncommented #define BOOST_ALL_DYN_LINK as suggested here and now code compiles! i'm investigating if everything else is fine. however i didn't understand why I should uncomment #define BOOST_ALL_DYN_LINK so comments are welcome.
Edit: Initial statement removed since an edit to the post changed the situation.
Based on http://www.boost.org/doc/libs/1_53_0/more/getting_started/unix-variants.html#library-naming (as provided by Igor R.):
libboost_thread-vc110-mt-1_52.lib is a static lib (no need for the DLL)
boost_thread-vc110-mt-1_52.lib is the import lib for the DLL
You only need to use one of these.
Another idea/solution to try if you hit the error LNK1104: cannot open file 'libboost_date_time-*.lib' error:
In our project, we include the boost/date_time.hpp file. We define the constant BOOST_ALL_NO_LIB instead of BOOST_ALL_DYN_LINK in our project settings to tell boost not to automatically select which libraries to link against.
See the Boost documentation for more information about this option.
So you could add BOOST_ALL_NO_LIB in Project Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions and check whether this linker error goes away.
I think first of all you need to correct your question. Do you mean (I guess you already know the difference between DLL and LIB )
libboost_thread-vc110-mt-1_52.lib
boost_thread-vc110-mt-1_52.dll
or
libboost_thread-vc110-mt-1_52.lib
boost_thread-vc110-mt-1_52.lib
Anyway, it seems the issue is you're mixing static(libboost_thread-vc110-mt-1_52.lib) and shared (boost_thread-vc110-mt-1_52.lib) boost libraries. But without the working environment and platform details I cannot purpose an exact solution. If you work in Visual Studio ,then you can go to right click on project file > properties > linker > input > ignore specific library and add libboost_thread-vc110-mt-1_52.lib there and try.
asking myquestion myself.
need to uncomment #define BOOST_ALL_DYN_LINK (refer to description)
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..