I tried to make console application that is using my DLL that is taking care of Kinect.
When I am building my project I get:
2>e:\projects\c++\vs\kinect dll\consoleapplication1\consoleapplication1.cpp(4):
warning C4627: '#include "KinectDLL.h"': skipped when looking for precompiled header use
2> Add directive to 'stdafx.h' or rebuild precompiled header
2> e:\michał\projects\c++\vs\kinect dll\kinect dll\depthreader.h(4):
fatal error C1083: Cannot open include file: 'NuiApi.h': No such file or directory
Note: ConsolApplication1 and Kinect DLL are 2 projects in the same solution, first one have one dependency – Kinect DLL project as DLL. I have “use precompile headers” turned off in both projects!
Kinect DLL projects:
KinectDLL.h:
#ifdef KINECTDLL_EXPORTS
#define KINECTDLL_API __declspec(dllexport)
#else
#define KINECTDLL_API __declspec(dllimport)
#endif
DepthReader.h:
#pragma once
#include <ole2.h>
#include <Windows.h>
#include "NuiApi.h"
#include "KinectDLL.h"
namespace KinectDLL{
class DepthReader{
static KINECTDLL_API const int depthWidth = 640;
static KINECTDLL_API const int depthHeight = 480;
static KINECTDLL_API const int bytesPerPixel = 4;
public:
KINECTDLL_API DepthReader(void);
KINECTDLL_API ~DepthReader(void);
KINECTDLL_API int Run(HINSTANCE hInstance, int nCmdShow);
private:
HANDLE depthStreamHandle;
HANDLE nextDepthFrameEvent;
HANDLE depthStream;
BYTE* depthRGBX;
bool nearMode;
INuiSensor* sensor;
//HWND m_hWnd;
HRESULT CreateFirstConnected();
void Update();
void ProcessDepth();
};
}
DepthReader.cpp
#include "stdafx.h"
#include "DepthReader.h"
namespace KinectDLL{
DepthReader::DepthReader(void) :
nextDepthFrameEvent(INVALID_HANDLE_VALUE),
depthStreamHandle(INVALID_HANDLE_VALUE),
nearMode(false),
sensor(NULL)
{
// create heap storage for depth pixel data in RGBX format
depthRGBX = new BYTE[depthWidth*depthHeight*bytesPerPixel];
}
… and so on, mostly copy and pase from MS Kinect examples...
Consoleapplication1 project:
Consolapplication1.cpp:
#include "KinectDLL.h"
#include "stdafx.h"
#include "Rotations.h"
#include "Camera.h"
#include "FileLoader.h"
#include "DepthReader.h"
using namespace std;
Camera camera;
Rotations rotations;
FileLoader fileLoader;
KinectDLL::DepthReader depthReader;
… then there is OpenGL, points from file. I am using Kinect to contole the scene, not to display data from it. No depthReader for now.
Clearly I am doing something stupid but I can't see what. I am reading Microsoft examples about DLL in VC++ but I can't see what is wrong.
I have just finished created a dll with some functions that depend on the skeleton stream from the kinect. What I did was something like this:
#ifdef KINECTFUNCTIONSDLL_EXPORTS
#define KINECTFUNCTIONSDLL_API __declspec(dllexport)
#else
#define KINECTFUNCTIONSDLL_API __declspec(dllimport)
#endif
#include <Windows.h>
#include <NuiApi.h>
using namespace std;
#include <string>
namespace KinectFunctions{
class GestureRecognizer
{
public:
Vector4 KINECTFUNCTIONSDLL_API resta(Vector4 vector1,Vector4 vector2);
}
}
and now for the .cpp:
#include "KinectFunctionsDLL.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <fstream>
using namespace std;
namespace KinectFunctions{
Vector4 GestureRecognizer::resta(Vector4 vector1,Vector4 vector2){
Vector4 salida;
salida.x=vector1.x-vector2.x;
salida.y=vector1.y-vector2.y;
salida.z=vector1.z-vector2.z;
return salida;
}
}
Keep in mind that the project you use to create the dll must be created checking the DLL option (it's a checkbox that appears when you choose to create a new project. Like it is shown here:
https://www.youtube.com/watch?v=yEqRyQhhto8
And of course you need to add the dependencies for the kinect dll, the kinect10.lib and the headers, like in any project where you want to use the device.
Related
I am facing ERROR "C3702 atl is required for com events" in my source code but nothing help me to resolve this one.
Including these headers in stafx.h or .h file does not work:
#include <comdef.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
commenting and un commenting this line in stdafx.h or .h file does work:
//using namespace ATL;
Adding below line in stdafx.h or .h file does not work:
#define _ATL_ATTRIBUTES 1
Adding ATL support in MFC also does not work for me.
CoInitialize(NULL) and CoUninitialize() are also written in the main but not solved
Commenting this line change the error nature but no solution:
//[event_receiver(com)]
This line cause Compiler Error C3731 (incompatible event 'function1' and handler 'function2'; event source and event handler must be the same type)
.H File
#define _ATL_ATTRIBUTES 1
#pragma once
#include "stdafx.h"
[event_receiver(com)]
class CMainDlg
{
public:
CMainDlg() {};
~CMainDlg() {};
public:
bool OnCallStart();
HRESULT AbtoPhone_OnInitialized(BSTR Msg);
void HookPhoneEvents(IAbtoPhone* pSource);
void UnHookPhoneEvents(IAbtoPhone* pSource);
};//CMainDlg
CPP File
#include "stdafx.h"
#include "MainDlg.h"
bool CMainDlg::OnCallStart()
{
HRESULT hr = m_AbtoPhone.CreateInstance(__uuidof(CAbtoPhone));
if (FAILED(hr))
{
AfxMessageBox(_T("Can't load CAbtoPhone component.\nCheck is registered 'SIPVoIPSDK.dll'"));
}
HookPhoneEvents(m_AbtoPhone);
return true;
}
void CMainDlg::HookPhoneEvents(IAbtoPhone* pSource)
{
__hook(&_IAbtoPhoneEvents::OnInitialized, pSource, &CMainDlg::AbtoPhone_OnInitialized);
}
void CMainDlg::UnHookPhoneEvents(IAbtoPhone* pSource)
{
__unhook(pSource);
}
HRESULT CMainDlg::AbtoPhone_OnInitialized(BSTR Msg)
{
return S_OK;
}
I am using Microsoft Visual Studio 2017 Community edition.
Your way to solve it is correct. _ATL_ATTRIBUTES must be defined.
But you did it in changing code before the #innclude of "stdafx.h"
#define _ATL_ATTRIBUTES 1
#pragma once
#include "stdafx.h"
As long as you use precompiled header all statements before the #include "stdafx.h" are ignored. You must do it in the stdafx.h! (Even you wrote that this doesn't work, you don't told us why...)
This is the first time I deal with dll. I am using Opencv3 and Visual C++ to write a face recognition program. I have to load the CascadeClassigier, FaceRecognizer and VideoCapture into the memory before recognizing. They are all classes defined in opencv. And I want to package these classes into a new class and export that with a DLL. The intention I am doing so is to avoid include that many opencv files in my application program.
Here is my code (file name is RecFuncs.h):
#pragma once
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/face/facerec.hpp"
#include "opencv2/face/predict_collector.hpp"
#include <stdio.h>
#include <conio.h>
using namespace std;
using namespace cv;
#ifdef FACEDLL_EXPORTS
#define FACEDLL_API __declspec(dllexport)
#else
#define FACEDLL_API __declspec(dllimport)
#endif
namespace FaceFuncs {
class FACEDLL_API Load
{
public:
Ptr<face::FaceRecognizer> a;
CascadeClassifier b;
VideoCapture c;
};
}
And when I import my dll class, It seems that the class is not complete or undefined. How can I achieve my intention? Any idea or?
I am writing a plugin for Autodesk Maya using C++ and have a linker error.
My main class is Maya_Search_Plugin.cpp
#include <Utilities.h>
DeclareSimpleCommand( search_face, PLUGIN_COMPANY, "4.5");
//doIt method is entry point for plugin
MStatus search_face::doIt( const MArgList& )
{
//calls to Maya types/functions and Utilities functions
}
Then I have a Utilities class containing some static methods with header looking like this
#ifndef __Maya_CPP_Plugin__Utilities__
#define __Maya_CPP_Plugin__Utilities__
//#pragma once
//standard libs
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <math.h>
//maya libs
#include <maya/MDagPath.h>
#include <maya/MFn.h>
#include <maya/MFileIO.h>
#include <maya/MIOStream.h>
#include <maya/MFnMesh.h>
#include <maya/MFnTransform.h>
#include <maya/MGlobal.h>
#include <maya/MSelectionList.h>
#include <maya/MSimple.h>
#include <maya/MTypes.h>
#include <maya/MPointArray.h>
#include <maya/MObjectArray.h>
class Utilities{
public: static const int max_mov = 50;
public:
static double get_mesh_error(MPointArray, MPointArray, int);
static MStatus translateManipulator(double amount, MObject *path);
static void GetSelected(MObjectArray* objects, MFn::Type type);
};
#endif /* defined(__Maya_CPP_Plugin__Utilities__) */
with the implementation like this
#include <Utilities.h>
double Utilities::get_mesh_error(MPointArray a, MPointArray b, int vertexCount){
...
}
MStatus Utilities::translateManipulator(double amount, MObject *path){
...
}
void Utilities::GetSelected(MObjectArray* objects, MFn::Type type) {
...
}
However I am getting the following error
duplicate symbol _MApiVersion in:
/Users/tmg06qyu/Library/Developer/Xcode/DerivedData/Maya_CPP_Plugin-hjrwvybwlvqyyscbmixdkcpdzjqr/Build/Intermediates/Maya_CPP_Plugin.build/Debug/Maya_CPP_Plugin.build/Objects-normal/x86_64/Maya_Search_Plugin.o
/Users/tmg06qyu/Library/Developer/Xcode/DerivedData/Maya_CPP_Plugin-hjrwvybwlvqyyscbmixdkcpdzjqr/Build/Intermediates/Maya_CPP_Plugin.build/Debug/Maya_CPP_Plugin.build/Objects-normal/x86_64/Utilities.o
ld: 1 duplicate symbol for architecture x86_64
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld failed with exit code 1
Which I presume is a linking error and there is some circular reference somewhere, but I can't work out where it is.
Any help appreciated.
Thanks.
I know this is a year old. But I stumbled on this again a couple minutes ago...
Add
#define MNoVersionString
#define MNoPluginEntry
#include <maya/MFnPlugin.h>
to your header or cpp files where you wrote your plugin code. Include
#include <maya/MFnPlugin.h>
directly in your main.cpp that initializes the plugin.
Most of the examples in maya have the following string:
// This is added to prevent multiple definitions of the MApiVersion string.
#define _MApiVersion
before including anything. For example here.
The issue may happen if you have multiple files which include MFnPlugin.h
I'm currently using the triangle library in my program. The library contains only .c and .h files (no .lib). I get the following error on Visual Studio C++ 2010:
1>data.obj : error LNK2019: unresolved external symbol _triangulate referenced in function "struct triangulateio __cdecl readfile(void)" (?readfile##YA?AUtriangulateio##XZ)
The header file of my data.cpp is the following:
#ifndef DATA_H
#define DATA_H
#include <WinSock2.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <time.h>
#include <GL/gl.h> //include the gl header file
#include <GL/glut.h> //include the glut header file
#include <GL/glu.h> //include the glut header file
#include <armadillo>
//Namespace
using namespace std;
using namespace arma;
extern "C"
{
#ifdef SINGLE
#define REAL float
#else /* not SINGLE */
#define REAL double
#endif /* not SINGLE */
#include "triangle.h"
}
triangulateio readfile();
#endif
Data.cpp
triangulate("pczAevn", &in, &mid, &vorout);
I've already made my program work with a Makefile of mine on Ubuntu, but I need to run my program on windows.
Feel free to ask for more information.
EDIT #1:
If you use the triangle library with VS, you have to put the following instruction on top of the triangle.c file #define TRILIBRARY
Now it compile. Thank you very much for the help.
The linker can't find a definition for "triangulateio readfile()", if it's defined in the .c file my guess is that it isn't built. If you include it in the project it could work.
I'm trying to test a library that I've done (Calculus), in QTCreator for Windows.
I've created a main file, and a class in a separate file for the testing. If I compile the example found in http://www.boost.org/doc/libs/1_47_0/libs/test/doc/html/utf/user-guide/test-organization/manual-test-suite.html it works, and so the example found in http://www.boost.org/doc/libs/1_47_0/libs/test/doc/html/utf/user-guide/test-organization/manual-nullary-test-case.html also works.
But when I try to compile my project I've a lot (over 500) errors of multiple definitions. Below you can find my files. As you can see I've also tried to put some guard around boost headers, but it does not work. What am I doing wrong?
main.cpp
#include "testcalculus.h"
#ifndef USE_BOOST_HEADERS
#define USE_BOOST_HEADERS
#include <boost/test/included/unit_test.hpp>
#include <boost/bind.hpp>
#endif
using namespace boost::unit_test;
test_suite*
init_unit_test_suite( int argc, char* argv[] )
{
WRayTesting::TestCalculus xTestCalculus;
test_suite* pxTestSuiteCalculus = BOOST_TEST_SUITE("Test Calculus");
pxTestSuiteCalculus->add(BOOST_TEST_CASE( boost::bind(&WRayTesting::TestCalculus::testCartesianPoint2D, &xTestCalculus)));
framework::master_test_suite().add(pxTestSuiteCalculus);
return 0;
}
testcalculus.h
#ifndef TESTCALCULUS_H
#define TESTCALCULUS_H
#ifndef USE_BOOST_HEADERS
#define USE_BOOST_HEADERS
#include <boost/test/included/unit_test.hpp>
#include <boost/bind.hpp>
#endif
#include "cartesianpoint2d.h"
#include "cartesianvector2d.h"
namespace WRayTesting
{
/** Class for testing the Calculus project */
class TestCalculus
{
public:
//! Constructor
TestCalculus();
//! Testing class point
void testCartesianPoint2D();
private:
};
} // namespace WRayTesting
#endif // TESTCALCULUS_H
testcalculus.cpp
#include "testcalculus.h"
#ifndef USE_BOOST_HEADERS
#define USE_BOOST_HEADERS
#include <boost/test/included/unit_test.hpp>
#include <boost/bind.hpp>
#endif
namespace WRayTesting
{
using ::Calculus::CartesianPoint2D;
using namespace boost::unit_test;
/**
* Constructor
*/
TestCalculus::TestCalculus()
{
}
/**
* Test the CartesianPoint2D class.
*/
void TestCalculus::testCartesianPoint2D()
{
// Default constructor
CartesianPoint2D xTestingPoint;
BOOST_CHECK(0.0 == xTestingPoint.getX());
BOOST_CHECK(0.0 == xTestingPoint.getY());
}
} // namespace WRayTesting
Compile output
debug/testcalculus.o:c:/lib/boost/boost/test/impl/compiler_log_formatter.ipp:62: multiple definition of `boost::unit_test::output::compiler_log_formatter::log_start(std::ostream&, unsigned long)'
debug/main.o:c:/lib/boost/boost/test/impl/compiler_log_formatter.ipp:62: first defined here
debug/testcalculus.o:c:/lib/boost/boost/test/impl/compiler_log_formatter.ipp:72: multiple definition of `boost::unit_test::output::compiler_log_formatter::log_finish(std::ostream&)'
debug/main.o:c:/lib/boost/boost/test/impl/compiler_log_formatter.ipp:72: first defined here
debug/testcalculus.o:c:/lib/boost/boost/test/impl/compiler_log_formatter.ipp:80: multiple definition of `boost::unit_test::output::compiler_log_formatter::log_build_info(std::ostream&)'
debug/main.o:c:/lib/boost/boost/test/impl/compiler_log_formatter.ipp:80: first defined here
debug/testcalculus.o:c:/lib/boost/boost/test/impl/compiler_log_formatter.ipp:93: multiple definition of `boost::unit_test::output::compiler_log_formatter::test_unit_start(std::ostream&, boost::unit_test::test_unit const&)'
debug/main.o:c:/lib/boost/boost/test/impl/compiler_log_formatter.ipp:93: first defined here
debug/testcalculus.o:c:/lib/boost/boost/test/impl/compiler_log_formatter.ipp:103: multiple definition of `boost::unit_test::output::compiler_log_formatter::test_unit_finish(std::ostream&, boost::unit_test::test_unit const&, unsigned long)'
debug/main.o:c:/lib/boost/boost/test/impl/compiler_log_formatter.ipp:103: first defined here
...........
You cannot include #include in multiple files within the same test module. You either need to switch to library or put everything inside single file