Unresolved external symbol in library in C++ - c++

I am trying to compile un software which is written in C++ at visual studio 2017,but I face un problem in the library. The description is like this.
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "public: virtual void __thiscall CEZOptionsDlg::AddButton(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > >,unsigned int)" (?AddButton#CEZOptionsDlg##UAEXV?$CStringT#DV?$StrTraitMFC_DLL#DV?$ChTraitsCRT#D#ATL#####ATL##I#Z)
I have already included the path of library in the "VC++ directories" and added the *.lib in "Additional library directories".
The setting is in the mode "Debug" , "x86".
I have tried to change the setting in "Runtime library" but it doesn't work.
I have tried to change the "calling convention", but it doesn't work ,too.
Because it is a software who is written a bit long ago, I doubt that is it possible that the problem is on the x86 and x32. But in the "configuration manager", it runs at platform win32. It shouldn't be wrong.
I also doubt it might be the problem in the .dll, but I just compile the software. It should only be related to .lib
I don't know if the *.lib is complete because I don't have source code of this library.
I have been trapped in the problem for 2 days. Can anyone come and help me.

Your checklist
1) Confirm toolkit V110, v120,v14,v141
2) Confirm x86 or x64
3) Confirm MT ( static -> need only lib) or ML ( dynamic -> need a dll & lib)
4) DLL may be release or debug version
5) VS SDK version ( SDK 7.xx , SDK 8.1, SDK 10.xxx etc)
Use dumpbin.exe from your VS 2017 to find details for the exported methods and other signatures from the lib file. Use dependency-walker ( free download on net) to analyze the DLL file.

I finally found out it is caused by a very old version of de Visuel C++(VS 98), who is probably the same age as I am. After I used the VS98 in Visuel Stdio 2017( which sound ridiculous ), the code can build correctly.
I think this problem may only be occured to me. But, anyway, I hope this solution will help others.

Related

Problems linking Nlopt-2.4.2 in visual studio 2017

Some back story: I am trying to get the bolt-lmm software to compile on a Windows machine, because it would be a nice addition to the research group I am in. The developers of the software have only made a linux static executeable, but made the source code available. I am used to programming in R or python, and this is my first ever encounter with C++.
I have solved a fair bit of problems, but for some reason I have not been able to get visual studio to link properly with Nlopt-2.4.2.
I downloaded it
and followed the steps given there on how to install it.
I can tell I have done the same to link the Nlopt library to the project as is described in How to add additional libraries to Visual Studio project?
I still get errors like:
Error LNK2019 unresolved external symbol __imp__nlopt_create referenced in function "public: __thiscall nlopt::opt::opt(enum nlopt::algorithm,unsigned int)" (??0opt#nlopt##QAE#W4algorithm#1#I#Z) boltCompiler C:\Users\au483192\source\repos\boltCompiled\boltCompiler\NonlinearOptMulti.obj 1
(there are a total of 12 of this type of error, and an error link 1120, which just tells me there are 12 unresolved eternals.)
I hope this is enough information to provide a hint of what is going wrong.
I did some more digging, and it seems the linker needed more than just the folder for the .lib file.
This post sums it up:
Linking a static library to my project on Visual Studio 2010
Essentially you just need to tell the linker the placement of the lib and the actual name of the .lib file.
Hopefully this will help others who forgot/did not know that added library names manually could be needed for some libraries.
TL;DR:
open configuration properties for the project > linker > general
Then add the path to the .lib file in the "addition library directories" line
Then (still in configuration properties) go to linker > input
add the .lib file name to the "addition dependencies" line, e.g. libnlopt-0.lib (don't forget to separate with ";")

SCIP and Visual Studi: error LNK2019

I want to solve the n-queens problem using SCIP (version 3.2.1) in Visual Studio 2010 (version 10.0.40219.1).
Source files can be found here: http://scip.zib.de/download/files/Queens.tgz
I did not write any code myself, but just included queens.hpp, scip_exceptions.hpp, queens.cpp and queens_main.cpp in my VS project.
In the project properties I did the following:
C/C++ -> General -> Additional Include Directories -> C:\scipoptsuite-3.2.1\scip-3.2.1\src\.
When building, I get errors like:
LNK2019: unresolved external symbol SCIPaddCons referenced in function "public: __thiscall cipexamples::QueensSolver::QueensSolver(unsigned int)"
I understand that I will have to link SCIP libraries to my project? But I do not know which ones and where to find them?
You need to compile the SCIP Optimization Suite first to obtain the libscipopt that you need to link to your project. It will contain everything necessary to work with SCIP.
Alternatively, you may also just use the precompiled dlls from the webpage:
http://scip.zib.de/#download

pthread mutex: error LNK2019: unresolved external symbol c++

I'm obtaining this link error and I cannot find the solution. Can you maybe put me in the right direction where to search for it?
I get: error LNK2019: unresolved external symbol _imp_pthread_mutex_lock referenced in function "private: bool __thiscall... here comes the whole name of my function with parameters.
pthread_mutex_lock and pthread_mutex_unlock are used in this function (not as arguments).
Including "pthread.h" doesn't change anything.
I used pthread-win32 available from sourceware.org/pthreads-win32.
I've been facing this issue for couple hours now and was finally able to fix it by adding the 'lib', 'include' and 'bin' folder content provided with the download, in the appropriate folders in Visual Studio dependency installation folder.
Mine is in
"C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\VC\Tools\MSVC\14.10.25017"
Then i added the library dependency 'pthreadVC2.lib;' in
Project -> Properties -> Linker -> Input -> Additional Dependancies
And voila! pthreads started to work.
The pthread library is for POSIX systems (Linux, BSD, Mac OS). You indicated that you're on Visual Studio in Windows - if you are looking to do multithreading on Windows, see this page.
Better yet, if you can use more recent tools, C++11 offers built-in threading functionality.
You need to add
-lpthread
or
-lthread
to your compiler command line (depending on OS and compiler)
UPDATE: #nos correctly points out that this seems to be a MS linker error. You shouldn't be using pthreads in Visual Studio. Windows Threading API is very different.

build xerces c++ version 3 with icu

I want to build Xerces 3.1.1 with ICU using Visual c++ express 2010.
I've downloaded ICU source and built it like it says in the readme.
Now i need to build Xerces with the ICU binaries i just built.
The build instructions for version 3.1.1 in Xerces's site state that "You can also select whether the Xerces-C++ library should use ICU for transcoding" but they don't say exactly how. I looked at all the build options and the only thing i found (maybe i missed something?) that may be related is the pre processor macro list, i saw the following definition - XERCES_USE_TRANSCODER_WINDOWS.
I thought that maybe i need to change it to XERCES_USE_TRANSCODER_ICU. It's just a guess, so first i looked in the Xerces code and i saw XERCES_USE_TRANSCODER_ICU does appear (for example, they check if it's defined before including ICU headers).
So I've changed XERCES_USE_TRANSCODER_WINDOWS to XERCES_USE_TRANSCODER_ICU, added ICU include directory to the include directory path and all ICU .lib files to the linker dependencies and tried to build it like that. I get unresolved external errors:
PlatformUtils.obj : error LNK2019: unresolved external symbol "public: __thiscall xercesc_3_1::ICUTransService::ICUTransService(class xercesc_3_1::MemoryManager *)" (??0ICUTransService#xercesc_3_1##QAE#PAVMemoryManager#1##Z) referenced in function "private: static class xercesc_3_1::XMLTransService * __cdecl xercesc_3_1::XMLPlatformUtils::makeTransService(void)" (?makeTransService#XMLPlatformUtils#xercesc_3_1##CAPAVXMLTransService#2#XZ)
1>C:\cpp_lib\xerces-c-3.1.1\projects\Win32\VC10\xerces-all\XercesLib...........\Build\Win32\VC10\Debug\xerces-c_3_1D.dll : fatal error LNK1120: 1 unresolved externals
The Xerces site provide more specific instructions for building Xerces 2.8 with ICU (it won't work on version 3 because it's done through a script that isn't provided with version 3). I tried that also (although i need to use the latest version) and it also didn't work well. No .dll or .lib files were created.
Thanks.
Because I had the same problem and this is one of the first Google hits looking for it, I will give an answer although it's been some time now since you asked the question.
These are the steps to build Xerces-c in Visual Studio (worked in VS10 for me) with ICU:
Download and build ICU as described.
Open the xerces-all.sln solution file with VS.
Select the ICU Debug/Release build configuration - it sets XERCES_USE_TRANSCODER_ICU for you.
Add the include and library paths for ICU to the porperties of the XercesLib project, add the icu libs in the additional linker dependencies of that project.
Build and be happy - no need to exclude WIN32TransService.cpp

How to add MySQL connector/C++ 1.1 to Visual Studio 2010 project?

I'm trying to add MySQL Connector/C++ to my visual Studio 2010 project.
I followed the steps (here, mysql docs) to add it to Visual Studio (I also added Boost in the "Additional include Directories").
It asked for a "sqlstring.h" file ( How a release can miss a file ?! ), so I had it from the source files (mysql source archives).
Then, It asked for libmyql.lib, I had the lib directory of MySQL Server 5.5\lib.
And now, I'm on this error:
Error 127 error LNK1120: 31 unresolved externals C:\Users\Haks\Documents\Visual Studio 2010\Projects\ProductManager\Debug\ProductManager.exe ProductManager
Error 60 error LNK2001: unresolved external symbol "__declspec(dllimport) bool __cdecl std::operator<<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??$?MDU?$char_traits#D#std##V?$allocator#D#1##std##YA_NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##0#0#Z) C:\Users\Haks\Documents\Visual Studio 2010\Projects\ProductManager\ProductManager\mysqlcppconn-static.lib(mysql_ps_resultset.obj) ProductManager
So, maybe it's because I got the binary release of MySQL Connector/C++ 1.1 and maybe it's not compatible with VS 2010...
But I don't find the good way to compile the source files, and I never use Boost or CMake and it's seem to be needed.
I found no reference to my problem, so if someone got a response or a good way, it will be very useful for me and a lot of people I think.
Thank you
First of all, thanx to the dar7yl for pointing in the right direction.
After spending much time debugging mysql connection (VS 2010, C++), which proves to be a much hair raising experience, I am compelled to say something about it.
(assumed you setup C++ include files directory and link directory + additional dependence file correctly, else refer to the website on point 2 for reference)
0.) Yes, we need boost library. Download boost library (search google) and unpack it into your development folder and have your c++ additional include directories point to it(boost main directory, not the boost child directory).
1.) Need to be clear on the difference in VS solution configuration mode "debug" and "release". The .lib files provided provided after full installation of MYSQL under directory ...\mysql\Connector C++ ____\lib\ has two directories of debug and opt for use with solution mode "debug" and "release" accordingly. The main difference being "debug" mode uses the extra .pdb files.
2.) http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-apps-windows-visual-studio.html gives a very detail outline for VS2008 mysql connection setup. Particularly the need to include under [Project, Properties tree view, under C++, Preprocessor] two statement of CPPCONN_PUBLIC_FUNC= and HAVE_INT8_T=1
3.) be clear which mode of connection you would like with the library, mysqlcppconn.lib is dll based while mysqlcppconn-static.lib is static based. For dll based lib, related dll mysqlcppconn.dll needs to be deposited into \windows\system32\ or other system path for access.
For static connection remember its using extern C connection so you will need libmysql.lib + libmysql.dll (libmysql.pdb if under "debug") from ...\mysql\connectorc c ___\, if not you will get the unresolved external symbol error LNK 2019. So promptly update your c++ include files directory, link include file directory, additional dependency accordingly and deposite the .dll file into system path or ....\windows\system32\
4.) At this point, things should work for some of us. And no, it didn't work for me. Reason? Library comparability issue as outlined by dar7yl. So if this is the case, download source code for the connector under http://dev.mysql.com/downloads/connector/cpp/ by select platform to source code. Unpack and it get a bit complicated from here.
No VS solution or project files? No worries, see the cmake__.txt file? that's our solution.
Download cmake and have the source directory and destination directory point to your unpacked source code directory. Then open cmake__.txt in the directory and search for keyword "boost" and update the boost directory to point to your boost directory. Run configure and set to VS 2010, check the outlined configuration and change whatever is necessary Name/Value table then press generate.
By now your project + solution files should have been generated, open it and you will see many projects. We are only concerned with mysqlcppconn and mysqlcppconn-static. check and update the include files, link files + dependency in the two project's property and compile. Drop the generated .lib + .dll (and .pdb if using "debug" mode) into the corresponding directories and your project should work now.
By this point mysql connection now works for me, hope it works for you too. Some details might be missing from the above and I do apologies.
Just a small addition to dddddd great post. If you are compiling on Windows7 then you will probably get some 'unresolved externals' from the libmysql.lib library. I found this was due to the fact that the libmysql.lib came from a 64bit installation of the server. You will need to find the 32 bit version and link with that, or just install the 32 bit server instead.
I finally got MySQL Connector/C++ working with visual Studio 2010 by downloading the source and compiling it with the same settings as my project. It still warns about SqlString library:
j:\mysql-connector-c++-1.1.0\cppconn\sqlstring.h(36): warning C4251: 'sql::SQLString::realStr' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'sql::SQLString'
but, it seems to be ok with that.