FlyCapture SDK problems on Visual Studio 2012 - visual-c++

I am having problems with the flycapture SDK (FlyCapture v2.6 Rel 2) on Visual Studio. This is used for BlackFly camera.
I am getting the following errors:
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::Error::Error(void)" (__imp_??0Error#FlyCapture2##QAE#XZ) referenced in function _wmain C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::Error::Error(class FlyCapture2::Error const &)" (__imp_??0Error#FlyCapture2##QAE#ABV01##Z) referenced in function _wmain C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 3 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall FlyCapture2::Error::~Error(void)" (__imp_??1Error#FlyCapture2##UAE#XZ) referenced in function "void __cdecl PrintError(class FlyCapture2::Error)" (?PrintError##YAXVError#FlyCapture2###Z) C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 4 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void __thiscall FlyCapture2::Error::PrintErrorTrace(void)const " (__imp_?PrintErrorTrace#Error#FlyCapture2##UBEXXZ) referenced in function "void __cdecl PrintError(class FlyCapture2::Error)" (?PrintError##YAXVError#FlyCapture2###Z) C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 5 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::BusManager::BusManager(void)" (__imp_??0BusManager#FlyCapture2##QAE#XZ) referenced in function _wmain C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 6 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall FlyCapture2::BusManager::~BusManager(void)" (__imp_??1BusManager#FlyCapture2##UAE#XZ) referenced in function _wmain C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 7 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class FlyCapture2::Error __thiscall FlyCapture2::BusManager::GetNumOfCameras(unsigned int *)" (__imp_?GetNumOfCameras#BusManager#FlyCapture2##UAE?AVError#2#PAI#Z) referenced in function _wmain C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 8 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class FlyCapture2::Error __thiscall FlyCapture2::BusManager::GetCameraFromIndex(unsigned int,class FlyCapture2::PGRGuid *)" (__imp_?GetCameraFromIndex#BusManager#FlyCapture2##UAE?AVError#2#IPAVPGRGuid#2##Z) referenced in function _wmain C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 66 error LNK2001: unresolved external symbol "public: virtual class FlyCapture2::Error __thiscall FlyCapture2::Camera::ValidateFormat7Settings(struct FlyCapture2::Format7ImageSettings const *,bool *,struct FlyCapture2::Format7PacketInfo *)" (?ValidateFormat7Settings#Camera#FlyCapture2##UAE?AVError#2#PBUFormat7ImageSettings#2#PA_NPAUFormat7PacketInfo#2##Z) C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 67 error LNK2001: unresolved external symbol "public: virtual class FlyCapture2::Error __thiscall FlyCapture2::Camera::WaitForBufferEvent(class FlyCapture2::Image *,unsigned int)" (?WaitForBufferEvent#Camera#FlyCapture2##UAE?AVError#2#PAVImage#2#I#Z) C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 68 error LNK2001: unresolved external symbol "public: virtual class FlyCapture2::Error __thiscall FlyCapture2::Camera::WriteRegister(unsigned int,unsigned int,bool)" (?WriteRegister#Camera#FlyCapture2##UAE?AVError#2#II_N#Z) C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 69 error LNK2001: unresolved external symbol "public: virtual class FlyCapture2::Error __thiscall FlyCapture2::Camera::WriteRegisterBlock(unsigned short,unsigned int,unsigned int const *,unsigned int)" (?WriteRegisterBlock#Camera#FlyCapture2##UAE?AVError#2#GIPBII#Z) C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\BlackFlyMultiTrigger\BlackFlyMultiTrigger.obj BlackFlyMultiTrigger
Error 70 error LNK1120: 69 unresolved externals C:\Users\dahl2\Documents\Visual Studio 2012\Projects\BlackFlyMultiTrigger\Debug\BlackFlyMultiTrigger.exe BlackFlyMultiTrigger
and to my understanding the problem lies in the directories (include and library).
I have downloaded the FlyCapture SDK v2.6 Release 2 for Windows 32-bit and 64-bit.
In my project I have added the following properties:
Configuration Properties -> Linker -> Additional Library Directories : C:\Program Files\Point Grey Research\FlyCapture2\lib64\FlyCapture2_v100.lib
Configuration Properties -> C/C++ -> Additional Include Directories : C:\Program Files\Point Grey Research\FlyCapture2\include
I have tried to do this with the 32-bit and 64-bit SDK and with different lib's. But I don't know where I have done something wrong. All help is appreciated!!!

I have been working on finding the problem, and now I have. The FlyCapture2 SDK is not supported by VS2012 by default. I had to make some changes.
First I added the properties (as written above), but using the 32-bit SDK.
Then I entered the folder where SDK was installed. Here I went to src\vsprops\VS10 and made a copy of the FlyCapture2.props file.
Then I renamed the copy, for example "FlyCapture2Changed.props"
Open the "FlyCapture2Changed.props" (notepad, text editor, etc) and found the line:
NB! there should not be space between < and AdditionalDependencies (same for < / ), had some trouble with the editor here (text went missing).
< AdditionalDependencies>FlyCapture2_$(PlatformToolset).lib;%(AdditionalDependencies)< /AdditionalDependencies>
and changed it to:
< AdditionalDependencies>FlyCapture2_v100.lib;%(AdditionalDependencies)< /AdditionalDependencies>
After this was done I had to do some changes to the project. Under your project you should go to property manager and rightclick on Debug | Win32 and select "Add Existing Property Sheet" and select the "FlyCapture2Changed.props" I have made.
After this was done it worked!

Related

unresolved external symbol referenced in function removed by /OPT:REF

I have a function bar() that I don't actually call, that calls unimplemented foo():
void foo();
void bar()
{
foo();
}
int main()
{
}
If I package each function in a separate section/COMDAT and ask the linker to remove unused sections/COMDAT, I can get gcc to compile the program
gcc -ffunction-sections -Xlinker --gc-sections LinkerFunctions.cpp
but the equivalent in Visual C++ 2019
cl /Gy LinkerFunctions.cpp /link /OPT:REF
barks that
error LNK2019: unresolved external symbol "void __cdecl foo(void)" (?foo##YAXXZ) referenced in function "void __cdecl bar(void)" (?bar##YAXXZ)
How can I get msvc to compile the program?
Got your example working by adding inline, even after adding __declspec(noinline) to prevent actual inlining.
void foo();
__declspec(noinline)
inline void bar()
{
foo();
}
int main()
{
}
Tried because the documentation says:
Inlined functions and member functions defined inside a class declaration are always COMDATs.
Not sure however if it is robust solution, or works just in this particular case.
Accidentally found a linker switch for that:
cl incomplete.cpp /link /FORCE:UNRESOLVED
Will give a warning but in fact will work.

error LNK2005 on an external dll

I am using MS Visual Studio 2012 and trying to use a dynamic linked library that I have not wrote myself. I can define something Foo *foo; and everything is fine until I create a new object using Foo *foo = new Foo( params );
I get a whole list of errors:
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR110D.dll)
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>cyclone.lib(pworld.obj) : error LNK2019: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran#_String_base#std##SAXXZ) referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::erase(unsigned int,unsigned int)" (?erase#?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##QAEAAV12#II#Z)
1>cyclone.lib(pfgen.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xran(void)" (?_Xran#_String_base#std##SAXXZ)
1>cyclone.lib(pworld.obj) : error LNK2019: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen#_String_base#std##SAXXZ) referenced in function "protected: bool __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Grow(unsigned int,bool)" (?_Grow#?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##IAE_NI_N#Z)
1>cyclone.lib(pfgen.obj) : error LNK2001: unresolved external symbol "public: static void __cdecl std::_String_base::_Xlen(void)" (?_Xlen#_String_base#std##SAXXZ)
1>C:\Users\deleo\Documents\Visual Studio 2012\Projects\AdvancedPhysics - Copy\Debug\AdvancedPhysics.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
So I cannot change any of the code of the dll itself.
I use a single #include (and I looked at the file, if is guarded with an #ifndef).
Anyone knows why this error occurs and how to fix it?
Your project and linked libraries must use the same VC++ version and the same compiler options. You can use PE (Portable Executable) viewer to view linker version to determine what compiler version that used to compile that DLL.
If your compiler version is same as DLL. Try to set Runtime Library in Project > Properties > Configuration Properties > C/C++ > Code Generation to MT or MTd.

How can you declare an object and invoke its methods from a class defined in a different Project in same solution?

I am trying to use Microsoft CppUnitTestFramework. I have two separate projects in one solution, one the actual code and the other one is the unit test code. Now I would like to test the "DijkstarImpl" class defined in the first project and I added the path for this class in project Properties->C++->General->AdditionalInclude directories. The test project compiles successfully, but when I run the test I get this error:
Error 2 error LNK2001: unresolved external symbol "public: static class DijkstarImpl * UnitTest_FasTrack::UnitTest1::dijkstarImpl" (?dijkstarImpl#UnitTest1#UnitTest_FasTrack##2PAVDijkstarImpl##A) C:\working\TestFastTrack\UnitTest_FasTrack\unittest1.obj
Error 3 error LNK2001: unresolved external symbol "public: __thiscall DijkstarImpl::DijkstarImpl(void)" (??0DijkstarImpl##QAE#XZ) C:\working\TestFastTrack\UnitTest_FasTrack\unittest1.obj
The error is the linker error, but I don't know what should I link? It is not a lib file to be included in Properties->Linker->Input.
The following snippet shows the unit test code.
#include "stdafx.h"
#include "CppUnitTest.h"
#include "DijkstarImpl.h"
#include "string.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTest_FasTrack
{
TEST_CLASS(UnitTest1)
{
static DijkstarImpl* dijkstarImpl;
public:
TEST_CLASS_INITIALIZE(Initialize)
{
static DijkstarImpl* UnitTest_FasTrack::UnitTest1::dijkstarImpl;
}
TEST_METHOD(TestMethod1)
{
}
};
}
You need to declare an instance of the variable outside the class, but in the same namespace.
namespace UnitTest_FasTrack
{
TEST_CLASS(UnitTest1)
{
static DijkstarImpl* dijkstarImpl;
public:
TEST_CLASS_INITIALIZE(Initialize)
{
}
TEST_METHOD(TestMethod1)
{
}
};
DijkstarImpl *UnitTest1::dijkstarImpl; //declared outside the scope of the class
}

Link errors between dialog application and library

I have a dialog application that used to work perfectly. It uses MFC.
I wanted to move some of the classes to a separate library (in the same solution), so I created a new project in the same solution, selected Win32 Console App, Static library and MFC and moved the classes to the new project. The library project seems to compile fine.
In the original project I added a reference to the new library.
I am getting these errors now, no idea how to solve them. If I edit the project properties and select Linker/Input/Ignore All Default Libraries I get much more errors.
1>afxnmcdd.lib(wincore2.obj) : error LNK2005: "void __stdcall DDX_Control(class CDataExchange *,int,class CWnd &)" (?DDX_Control##YGXPAVCDataExchange##HAAVCWnd###Z) already defined in nafxcwd.lib(wincore2.obj)
1>afxnmcdd.lib(wincore2.obj) : error LNK2005: "public: int __thiscall CWnd::ExecuteDlgInit(void *)" (?ExecuteDlgInit#CWnd##QAEHPAX#Z) already defined in nafxcwd.lib(wincore2.obj)
1>afxnmcdd.lib(afxctrlcontainer2.obj) : error LNK2005: "void __cdecl AfxRegisterMFCCtrlClasses(void)" (?AfxRegisterMFCCtrlClasses##YAXXZ) already defined in nafxcwd.lib(afxctrlcontainer2.obj)
1>afxnmcdd.lib(afxctrlcontainer2.obj) : error LNK2005: "protected: void __thiscall CMFCControlContainer::PreUnsubclassControl(class CWnd *)" (?PreUnsubclassControl#CMFCControlContainer##IAEXPAVCWnd###Z) already defined in nafxcwd.lib(afxctrlcontainer2.obj)
1>afxnmcdd.lib(afxctrlcontainer2.obj) : error LNK2005: "public: int __thiscall CMFCControlContainer::SubclassDlgControls(void)" (?SubclassDlgControls#CMFCControlContainer##QAEHXZ) already defined in nafxcwd.lib(afxctrlcontainer2.obj)
1>afxnmcdd.lib(afxctrlcontainer2.obj) : error LNK2005: "public: static int __stdcall CMFCControlContainer::UTF8ToString(char const *,class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > > &,int)" (?UTF8ToString#CMFCControlContainer##SGHPBDAAV?$CStringT#DV?$StrTraitMFC#DV?$ChTraitsCRT#D#ATL#####ATL##H#Z) already defined in nafxcwd.lib(afxctrlcontainer2.obj)
1>.\Debug\application-ui.exe : fatal error LNK1169: one or more multiply defined symbols found
How do I solve this issue?
In your static library go to the STDAFX.H and comment out following preprocessor macro:
#define _AFX_NO_MFC_CONTROLS_IN_DIALOGS

when I'm trying to use separate *.h and *.cpp I'm geting error LINK2019

I've code like
A.h
Class A{
public:
void FuncA();
}
A.cpp
#include "A.h"
void A::FuncA() {}
B.h
#include "A.h"
Class B{
public:
void FuncB();
}
B.cpp
#include "B.h"
void B::FuncB(){
A *a = new A();
a->FuncA();
}
When I'm trying to build this project I'm geting "error LNK2019: unresolved external symbol "public: void __thiscall A::FuncA()" (?FuncA#A##QAEXH#Z) referenced in function "public: void __thiscall B::FuncB(void)" (?FuncB#B##MAEXXZ) B.obj project"
It makes A.obj and B.obj.
The code looks ok. Make sure to rebuild everything first and that A.obj is really sent to the linker.
Response to comment
Check the build log in VS2008. See picture below:

Resources