CATCH Unit Testing Suite with Visual Studio 2010 - c++

As far as I understand it, I can simply place catch.hpp into my project directory, add it to the project, and then start writing tests. I'm running into a few, or 11 to be exact, linker errors once I try using some of the macros outlined in the tutorial.
#include "catch.hpp"
unsigned int Factorial( unsigned int number ) {
return number <= 1 ? number : Factorial(number-1)*number;
}
TEST_CASE( "Factorials are computed", "[factorial]" ) {
REQUIRE( Factorial(1) == 1 );
REQUIRE( Factorial(2) == 2 );
REQUIRE( Factorial(3) == 6 );
REQUIRE( Factorial(10) == 3628800 );
}
I'm able to create a single file out of the first example and compile it with g++, but when I just paste the same code into my VS2010 project and then try to run it, I run into the linker errors. Unfortunately I'm not familiar enough with C++ at this point to decode the errors myself, and after taking a look at the single file here, I was unable to discern the issue.
Error 1 error LNK2019: unresolved external symbol "public: __thiscall Catch::AutoReg::AutoReg(void (__cdecl*)(void),struct Catch::SourceLineInfo const &,struct Catch::NameAndDesc const &)" (??0AutoReg#Catch##QAE#P6AXXZABUSourceLineInfo#1#ABUNameAndDesc#1##Z) referenced in function "void __cdecl `anonymous namespace'::`dynamic initializer for 'autoRegistrar27''(void)" (??__EautoRegistrar27#?A0x3911e331##YAXXZ) C:\Users\Mark\documents\visual studio 2010\Projects\FirstCPPApplication\FirstCPPApplication\FirstCPPApplication.obj 1 1 FirstCPPApplication
Error 2 error LNK2019: unresolved external symbol "public: __thiscall Catch::ExpressionResultBuilder::ExpressionResultBuilder(enum Catch::ResultWas::OfType)" (??0ExpressionResultBuilder#Catch##QAE#W4OfType#ResultWas#1##Z) referenced in function __catch$?____C_A_T_C_H____T_E_S_T____27##YAXXZ$0 C:\Users\Mark\documents\visual studio 2010\Projects\FirstCPPApplication\FirstCPPApplication\FirstCPPApplication.obj 1 1 FirstCPPApplication
Error 3 error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl Catch::translateActiveException(void)" (?translateActiveException#Catch##YA?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) referenced in function __catch$?____C_A_T_C_H____T_E_S_T____27##YAXXZ$0 C:\Users\Mark\documents\visual studio 2010\Projects\FirstCPPApplication\FirstCPPApplication\FirstCPPApplication.obj 1 1 FirstCPPApplication
Error 4 error LNK2019: unresolved external symbol "public: class Catch::ExpressionResultBuilder & __thiscall Catch::ExpressionResultBuilder::endExpression(enum Catch::ResultDisposition::Flags)" (?endExpression#ExpressionResultBuilder#Catch##QAEAAV12#W4Flags#ResultDisposition#2##Z) referenced in function "void __cdecl ____C_A_T_C_H____T_E_S_T____27(void)" (?____C_A_T_C_H____T_E_S_T____27##YAXXZ) C:\Users\Mark\documents\visual studio 2010\Projects\FirstCPPApplication\FirstCPPApplication\FirstCPPApplication.obj 1 1 FirstCPPApplication
Error 5 error LNK2019: unresolved external symbol "public: __thiscall Catch::AssertionInfo::AssertionInfo(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct Catch::SourceLineInfo const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,enum Catch::ResultDisposition::Flags)" (??0AssertionInfo#Catch##QAE#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##ABUSourceLineInfo#1#0W4Flags#ResultDisposition#1##Z) referenced in function "void __cdecl ____C_A_T_C_H____T_E_S_T____27(void)" (?____C_A_T_C_H____T_E_S_T____27##YAXXZ) C:\Users\Mark\documents\visual studio 2010\Projects\FirstCPPApplication\FirstCPPApplication\FirstCPPApplication.obj 1 1 FirstCPPApplication
Error 6 error LNK2019: unresolved external symbol "struct Catch::IContext & __cdecl Catch::getCurrentContext(void)" (?getCurrentContext#Catch##YAAAUIContext#1#XZ) referenced in function "struct Catch::IResultCapture & __cdecl Catch::getResultCapture(void)" (?getResultCapture#Catch##YAAAUIResultCapture#1#XZ) C:\Users\Mark\documents\visual studio 2010\Projects\FirstCPPApplication\FirstCPPApplication\FirstCPPApplication.obj 1 1 FirstCPPApplication
Error 7 error LNK2019: unresolved external symbol "public: class Catch::ExpressionResultBuilder & __thiscall Catch::ExpressionResultBuilder::setOp(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?setOp#ExpressionResultBuilder#Catch##QAEAAV12#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "private: class Catch::ExpressionResultBuilder & __thiscall Catch::ExpressionLhs<int const &>::captureExpression<0,int>(int const &)" (??$captureExpression#$0A#H#?$ExpressionLhs#ABH#Catch##AAEAAVExpressionResultBuilder#1#ABH#Z) C:\Users\Mark\documents\visual studio 2010\Projects\FirstCPPApplication\FirstCPPApplication\FirstCPPApplication.obj 1 1 FirstCPPApplication
Error 8 error LNK2019: unresolved external symbol "public: class Catch::ExpressionResultBuilder & __thiscall Catch::ExpressionResultBuilder::setRhs(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?setRhs#ExpressionResultBuilder#Catch##QAEAAV12#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "private: class Catch::ExpressionResultBuilder & __thiscall Catch::ExpressionLhs<int const &>::captureExpression<0,int>(int const &)" (??$captureExpression#$0A#H#?$ExpressionLhs#ABH#Catch##AAEAAVExpressionResultBuilder#1#ABH#Z) C:\Users\Mark\documents\visual studio 2010\Projects\FirstCPPApplication\FirstCPPApplication\FirstCPPApplication.obj 1 1 FirstCPPApplication
Error 9 error LNK2019: unresolved external symbol "public: class Catch::ExpressionResultBuilder & __thiscall Catch::ExpressionResultBuilder::setLhs(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?setLhs#ExpressionResultBuilder#Catch##QAEAAV12#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "private: class Catch::ExpressionResultBuilder & __thiscall Catch::ExpressionLhs<int const &>::captureExpression<0,int>(int const &)" (??$captureExpression#$0A#H#?$ExpressionLhs#ABH#Catch##AAEAAVExpressionResultBuilder#1#ABH#Z) C:\Users\Mark\documents\visual studio 2010\Projects\FirstCPPApplication\FirstCPPApplication\FirstCPPApplication.obj 1 1 FirstCPPApplication
Error 10 error LNK2019: unresolved external symbol "public: class Catch::ExpressionResultBuilder & __thiscall Catch::ExpressionResultBuilder::setResultType(bool)" (?setResultType#ExpressionResultBuilder#Catch##QAEAAV12#_N#Z) referenced in function "private: class Catch::ExpressionResultBuilder & __thiscall Catch::ExpressionLhs<int const &>::captureExpression<0,int>(int const &)" (??$captureExpression#$0A#H#?$ExpressionLhs#ABH#Catch##AAEAAVExpressionResultBuilder#1#ABH#Z) C:\Users\Mark\documents\visual studio 2010\Projects\FirstCPPApplication\FirstCPPApplication\FirstCPPApplication.obj 1 1 FirstCPPApplication
Error 11 error LNK2019: unresolved external symbol "public: __thiscall Catch::AutoReg::~AutoReg(void)" (??1AutoReg#Catch##QAE#XZ) referenced in function "void __cdecl `anonymous namespace'::`dynamic atexit destructor for 'autoRegistrar27''(void)" (??__FautoRegistrar27#?A0x3911e331##YAXXZ) C:\Users\Mark\documents\visual studio 2010\Projects\FirstCPPApplication\FirstCPPApplication\FirstCPPApplication.obj 1 1 FirstCPPApplication
Error 12 error LNK1120: 11 unresolved externals C:\Users\Mark\documents\visual studio 2010\Projects\FirstCPPApplication\Debug\FirstCPPApplication.exe FirstCPPApplication

long story short: split your single project solution into 3, use a .lib of the old exe, add the projects to the appropriate paths, update the linker, and you're good to go.
AE Drew's answer helped solve my problem, but I want to put a more full
solution to the question's title, in case anyone's coming from Google,
especially if they are looking for a simple breakdown from a beginner's
perspective.
If you only had one project in your solution that built a .exe for you, CATCH
wouldn't work: your solution needs 3 projects (as far as I know) to be able to
test your code.
Source_project, The main codebase project (in which the source code for
your application resides)
Test_project, The test suites project (in which the REQUIRES tests appear
as outlined in the above question)
Main_project, The project where you actually call and run the code from the
source codebase.
In order to convert your original single-project solution into something that
you can use in both tests and to properly run, you'll need to build a .lib or
a .dll so that other projects (including other people's projects) can use the
same code. Altering this answer, all it takes is to
right-click on your project in the Solution Explorer, and select >
Properties.... Under Configuration Properties -> General there's an > option
called Configuration Type. If you change it to [Static Library > (.lib)], your
project will generate a [.lib] when it is built.
And then in the 3rd project, main_project, where you have a barebones setup
from a Win32 Console Application that only contains a file that looks something
like:
#include "stdafx.h"
#include "HEADER_FROM_FIRST_PROJECT.h"
int _tmain(int argc, _TCHAR* argv[])
{
METHOD_FROM_FIRST_PROJECT();
return 0;
}
where you import a header file from Source_project, the first project that we
created (the one that used to be an exe, but is now building to a lib). But
that's not going to run yet, you need to add the Source_project's directory to
this projects additional directories, by right clicking the project in the
Solution Explorer, under Properties > Configuration Properties > C/C++ > General >
Additional Include Directories, add the source_project's folder to the list. This'll
allow the #include lines to automatically search that directory for the appropriate
files, saving you from having to write ../source_project/HEADER_FROM_FIRST_PROJECT.h.
Finally, the last step is to make sure that the linker will be able to actually
find the objects that you are trying to include. And since we're building a
.lib, we're able to do this rather simply. In the same settings dialog box as
before, the Projects Properties dialog, we'll navigate instead to Configuration
Properties > Linker > Input > Additional Dependencies and add the relative path to the
source_project.lib file, which would look something like ../Debug/source_project.lib.
Note that if you have any .dlls that are in the old exe project, it'll
need to be moved into the new main_project.
Also note that this is all very new to me and some of the terms and information are bound to be incorrect.

Just scanning through the links you provide, I think you may need to add this line at the top of your file.
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
It looks like the functions you are trying to link are within #if defined CATCH_CONFIG_MAIN .... #endif preprocessor directives.

Related

Errors on running a sample PCL code on Visual Studio 2017

I'm trying to run a sample PCL code just to start developing PCL on Visual Studio (2017) on my Windows 10. I followed the guides here: http://dominoc925.blogspot.com/2016/07/set-up-visual-studio-to-use-all-in-one.html
As suggested in their blog post, I downloaded the all-in-one 64bit installer from here: https://github.com/PointCloudLibrary/pcl/releases/tag/pcl-1.8.1rc1
While I followed all steps, they didn't have a link to a property sheet for PCL 1.8.1 (where can I find it?)
Anyways, when I try to compile my project (no errors on editor), I get 3 link errors as below. How can I run a sample PCL code in Visual Studio? Please help.
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "void __cdecl pcl::console::print(enum pcl::console::VERBOSITY_LEVEL,char const *,...)" (?print#console#pcl##YAXW4VERBOSITY_LEVEL#12#PEBDZZ) referenced in function "public: void __cdecl pcl::detail::FieldMapper<struct pcl::PointXYZ>::operator()<struct pcl::fields::x>(void)" (??$?RUx#fields#pcl###?$FieldMapper#UPointXYZ#pcl###detail#pcl##QEAAXXZ) PCLViewer c:\Users\xxx\documents\visual studio 2017\Projects\PCLViewer\PCLViewer\Source.obj 1
Error LNK2001 unresolved external symbol "public: virtual int __cdecl pcl::PLYReader::readHeader(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct pcl::PCLPointCloud2 &,class Eigen::Matrix<float,4,1,0,4,1> &,class Eigen::Quaternion<float,0> &,int &,int &,unsigned int &,int)" (?readHeader#PLYReader#pcl##UEAAHAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AEAUPCLPointCloud2#2#AEAV?$Matrix#M$03$00$0A#$03$00#Eigen##AEAV?$Quaternion#M$0A##7#AEAH4AEAIH#Z) PCLViewer c:\Users\xxx\documents\visual studio 2017\Projects\PCLViewer\PCLViewer\Source.obj 1
Error LNK2001 unresolved external symbol "public: virtual int __cdecl pcl::PLYReader::read(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct pcl::PCLPointCloud2 &,class Eigen::Matrix<float,4,1,0,4,1> &,class Eigen::Quaternion<float,0> &,int &,int)" (?read#PLYReader#pcl##UEAAHAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AEAUPCLPointCloud2#2#AEAV?$Matrix#M$03$00$0A#$03$00#Eigen##AEAV?$Quaternion#M$0A##7#AEAHH#Z) PCLViewer c:\Users\xxx\documents\visual studio 2017\Projects\PCLViewer\PCLViewer\Source.obj 1
Error LNK1120 3 unresolved externals PCLViewer c:\users\xxx\documents\visual studio 2017\Projects\PCLViewer\x64\Debug\PCLViewer.exe 1

OpenCV via NuGet packages with Visual Studio 2015, how to configure?

I'm trying to use OpenCV via NuGet packages with Visual Studio 2015 and I can't seem to get everything configured. I'm not sure if I'm making a mistake somewhere or what I'm trying is not supported.
A little background, I made this tutorial a while back:
https://www.youtube.com/watch?v=7SM5OD2pZKY
https://github.com/MicrocontrollersAndMore/OpenCV_3_Windows_10_Installation_Tutorial
And I'd like to update this to use NuGets if possible. I use NuGets on the job every day so I'm familiar with the concept, but I've only previously used NuGets with .Net (Visual Basic or C#) applications.
I'm trying to make this work with plane jane C++ OpenCV, not within a .NET or UWP app.
For the record, in a separate .Net test project, I tried the EmguCV NuGet package:
With Visual Studio 2015 and everything worked as expected (for those not familiar, Emgu CV is probably the oldest/best known/most stable .Net wrapper for OpenCV)
Here are the steps I tried to get regular C++ OpenCV to work within Visual Studio 2015 using NuGets:
Start Visual Studio 2015, make an Empty Project:
Bring up the NuGet package manager:
I choose OpenCV.Win.ImgProc as that seemed to be the only OpenCV 3.x NuGet available, this also auto imported Core as expected:
Then I added a .cpp file and copied/pasted in known-good OpenCV code, the OpenCV libraries are not recognized:
I tried Build -> Clean, Build -> Build, same concern. I also tried "Solution Configurations" and "Solution Platforms" set to Debug / Release / x86 / x64, same concern.
Am I missing a step here? Do NuGets only work within a managed environment such as .Net or UWP, or can they work with regular C++ as well? I did notice the mention in the Description about UWP:
But I'm not using VideoIO, so I'm not sure that should matter.
Has anybody had any success with this? I can always go back to the "old school" way of directly referencing libraries in Project -> (project name) Properties as shown in my tutorial linked to above, but I'd like to use NuGets if possible.
----------- Edit ---------------
I had to place my response to Leo-MSFT here to allow for enough characters and screenshots. Thanks for the suggestion Leo-MSFT, but two problems with that. For one, that package is OpenCV 2.4.10, very outdated by now:
2nd, if I use that package the red underlines are gone, but I get the following linker errors when I try to build and run:
1>------ Build started: Project: Test2, Configuration: Debug x64 ------
1> test.cpp
1>test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree#cv##YAXPEAX#Z) referenced in function "public: __cdecl cv::Mat::~Mat(void)" (??1Mat#cv##QEAA#XZ)
1>test.obj : error LNK2019: unresolved external symbol "public: __cdecl cv::_InputArray::_InputArray(class cv::Mat const &)" (??0_InputArray#cv##QEAA#AEBVMat#1##Z) referenced in function main
1>test.obj : error LNK2019: unresolved external symbol "public: __cdecl cv::_OutputArray::_OutputArray(class cv::Mat &)" (??0_OutputArray#cv##QEAA#AEAVMat#1##Z) referenced in function main
1>test.obj : error LNK2019: unresolved external symbol "public: void __cdecl cv::Mat::deallocate(void)" (?deallocate#Mat#cv##QEAAXXZ) referenced in function "public: void __cdecl cv::Mat::release(void)" (?release#Mat#cv##QEAAXXZ)
1>test.obj : error LNK2019: unresolved external symbol "public: void __cdecl cv::Mat::copySize(class cv::Mat const &)" (?copySize#Mat#cv##QEAAXAEBV12##Z) referenced in function "public: class cv::Mat & __cdecl cv::Mat::operator=(class cv::Mat const &)" (??4Mat#cv##QEAAAEAV01#AEBV01##Z)
1>test.obj : error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd#cv##YAHPEAHH#Z) referenced in function "public: class cv::Mat & __cdecl cv::Mat::operator=(class cv::Mat const &)" (??4Mat#cv##QEAAAEAV01#AEBV01##Z)
1>test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class std::basic_string,class std::allocator > const &,int)" (?namedWindow#cv##YAXAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function main
1>test.obj : error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey#cv##YAHH#Z) referenced in function main
1>test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string,class std::allocator > const &,class cv::_InputArray const &)" (?imshow#cv##YAXAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AEBV_InputArray#1##Z) referenced in function main
1>test.obj : error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string,class std::allocator > const &,int)" (?imread#cv##YA?AVMat#1#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function main
1>test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::GaussianBlur(class cv::_InputArray const &,class cv::OutputArray const &,class cv::Size,double,double,int)" (?GaussianBlur#cv##YAXAEBV_InputArray#1#AEBV_OutputArray#1#V?$Size_#H#1#NNH#Z) referenced in function main
1>test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::Canny(class cv::_InputArray const &,class cv::_OutputArray const &,double,double,int,bool)" (?Canny#cv##YAXAEBV_InputArray#1#AEBV_OutputArray#1#NNH_N#Z) referenced in function main
1>test.obj : error LNK2019: unresolved external symbol "void __cdecl cv::cvtColor(class cv::_InputArray const &,class cv::_OutputArray const &,int,int)" (?cvtColor#cv##YAXAEBV_InputArray#1#AEBV_OutputArray#1#HH#Z) referenced in function main
1>C:\Users\cdahms\Documents\Test2\x64\Debug\Test2.exe : fatal error LNK1120: 13 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
After trying various options, I've settled on this package:
Which seems to work, although it's not very confidence inspiring that it is clearly labeled "not an official package" and also that it's slightly out of date (not many changes from OpenCV 3.1.0 to 3.2.0 however). I suppose I'll use this until a proper updated package is released.
The OpenCV libraries package is OpenCV3.1 rather than OpenCV.Win.ImgProc for your test OpenCV code.
Below is my test result, so you just need to install the OpenCV3.1 NuGet package instead of OpenCV.Win.ImgProc for that OpenCV code.
Note that: OpenCV3.1 is not an official package.

Mixing native C++ and C++/CLI

I have a solution which consists of a native C++ DLL and a C++/CLI wrapper. My aim is to create a wrapper in C++/CLI of the native C++ DLL.
Whenever I try to create an instance of a native C++ class within the wrapper, I am met with many linker errors (see below).
2> .NETFramework,Version=v4.0.AssemblyAttributes.cpp
2>NFileOperation.obj : error LNK2028: unresolved token (0A000208) "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z) referenced in function "[T2M] void __clrcall `dynamic initializer for 'public: static float * tagVARIANT::* ATL::CVarTypeInfo<float *>::pmField''(void)" (__t2m#???__E?pmField#?$CVarTypeInfo#PAM#ATL##2QQtagVARIANT##PAMQ3###YMXXZ#?A0x22b777aa##YMXXZ)
2>DeskUpdateManaged.obj : error LNK2028: unresolved token (0A00021C) "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z) referenced in function "public: bool __clrcall DeskUpdateManaged::Conversion::FileExist(class System::String ^)" (?FileExist#Conversion#DeskUpdateManaged##$$FQ$AAM_NP$AAVString#System###Z)
2>DeskUpdateManaged.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z) referenced in function "public: bool __clrcall DeskUpdateManaged::Conversion::FileExist(class System::String ^)" (?FileExist#Conversion#DeskUpdateManaged##$$FQ$AAM_NP$AAVString#System###Z)
2>NFileOperation.obj : error LNK2001: unresolved external symbol "public: static bool __cdecl CFileOperation::FileExists(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?FileExists#CFileOperation##$$FSA_NABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z)
2>C:\Users\ABGZAMANK\Music\DeskUpdate\Dev\Source\Solution\Debug\DeskUpdateManaged.dll : fatal error LNK1120: 3 unresolved externals
Function call within the C++/CLI to the native C++ DLL:
bool NFileOperation::FileExists(CAtlString sPathName)
{
return CFileOperation::FileExists(sPathName);
}
Is there a more adequate approach to what I am trying to achieve?
Any advice relating to the issue is much appreciated.
It seems that your native C++ code is using ATL/MFC. Assuming you are compiling under VS, go to the C++/CLI project's project properties->Configuration properties->General and select "Use of MFC" and "Use of ATL" to be either static library or shared dll (depending on your project type). This flag will add the necessary include paths, linking paths and libs to your project to make use of ATL/MFC types from within your project. Also, make sure that you are linking your C++/CLI project against your native C++ project to avoid linking errors from your project (easily found in the Linker segment of the project properties in General and Input).

Linking error while using Visual Studio 2005(VC8)

I am getting a bunch of linking errors while trying to link the release version of an executable(debug version does not have the same issue). Comparing the command line for the link does not reveal any issues.
there are broadly 2 types of errors neither of which I can get a handle on.
The first kind complains about a unresolved external symbol _declspec(dllimport)
As an example:
error LNK2019: unresolved external symbol
"_declspec(dllimport)
public: __thiscall
stlpd_std::basic_string,class stlpd_std::allocator >::basic_string,class stlpd_std::allocator >(class stlpd_std::basic_string,class stlpd_std::allocator > const &)" (_imp??0?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std##QAE#ABV01##Z) referenced in function "public: __thiscall Springfield::generic::runtime_error::runtime_error(class stlpd_std::basic_string,class stlpd_std::allocator > const &)" (??0runtime_error#generic#Springfield##QAE#ABV?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std###Z)
for a more human readable version(replacing all the strings):
error LNK2019: unresolved external symbol
"__declspec(dllimport)
public: __thiscall
string::basic_string,class stlpd_std::allocator >(class string const &)" (_imp??0?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std##QAE#ABV01##Z) referenced in function "public: __thiscall Springfield::generic::runtime_error::runtime_error(class string const &)" (??0runtime_error#generic#Springfield##QAE#ABV?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std###Z
The sceond class of errors complains about
unresolved external symbol __CrtDbgReportW
I hope I can get some kind of insight in dealing with this.
From the errors it looks like you are not including the CRT as one of your linked libraries. Here is a link to the different CRT lib's offered in Visual Studio 2005. Choose the one which is most appropriate and make sure it's in the list of lib's to link against
http://msdn.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx
It looks like you're either including a file that's been built using the debug settings or you're mixing runtime libraries (DLL and static).

VC++ linker errors on std::exception::_Raise and std::exception::exception

I am using Visual C++ 2005 Express Edition and get the following linker errors:
19>mylib1.lib(mylibsource1.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::exception::_Raise(void)const " (__imp_?_Raise#exception#std##QBEXXZ) referenced in function "protected: static void __cdecl std::vector<class mytype,class std::allocator<class mytype> >::_Xlen(void)" (?_Xlen#?$vector#Vmytype##V?$allocator#Vmytype###std###std##KAXXZ)
19>mylib2.lib(mylibsource2.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::exception::_Raise(void)const " (__imp_?_Raise#exception#std##QBEXXZ)
19>mylib1.lib(mylibsource1.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::exception::exception(char const *,int)" (__imp_??0exception#std##QAE#PBDH#Z) referenced in function "public: __thiscall std::logic_error::logic_error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0logic_error#std##QAE#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##1##Z)
19>mylib2.lib(mylibsource2.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::exception::exception(char const *,int)" (__imp_??0exception#std##QAE#PBDH#Z)
I turned off exceptions in generated code, and I am using before including the vector header file:
#define _HAS_EXCEPTIONS 0
A few Google results turned up some stuff, but no "aha!" solutions that worked for me.
EDIT:
As noted "_HAS_EXCEPTIONS 0" doesn't turn off exceptions, per se. What it does is, at least in the vector header file, is call _Raise on an exception object instead of calling the C++ "throw". In my case, it can't link to the exception object's _Raise function since I am not including the correct library. What that library is, though, is not obvious.
Adding this line:
#define _STATIC_CPPLIB
before including the vector header seems to do the trick.
The third error makes it clear that #define the _HAS_EXCEPTIONS 0 does not affect . Now, might include (makes sense, sharing code might reduce the size of your executable). That would explain why you still have errors if you define it before your inclusion of . This kind of defines should be done in your project settings.
Note that _HAS_EXCEPTIONS is an unsupported feature in Visual Studio. It does not turn off exceptions as such.