如何在Visual c++ Windows窗体应用程序中包含文件
How to include files in a Visual C++ Windows Forms application
我创建了一个新的Windows窗体应用程序。
之后,我添加了一个新表单。在我的表单中,我添加了Form_Load
事件(通过使用表单编辑器)。
在我的记忆中,Visual Studio生成了MainForm.c和MainForm.h文件。我必须编辑MainForm.c,添加main函数,等等。
我还创建了一个名为CVEngine
的类。
我想做什么
我想在我的MainForm中创建一个CVEngine
类的实例(参见我的MainForm.h文件,MainForm_Load函数在文件末尾)。
我有什么问题?
我猜我的包有问题。我对c++了解不多,这是我的第一个Windows Forms c++应用程序。我有一点c#、PHP和Java的背景知识。我对c++和头文件有基本的了解,但是这个由Visual Studio生成的MainForm.h很奇怪(.h文件中有代码),我有点迷路了。
1>------ Build started: Project: Sensor Cam, Configuration: Debug Win32 ------
1> CVEngine.cpp
1> MainForm.cpp
1> Generating Code...
1>CVEngine.obj : error LNK2005: "public: __thiscall CVEngine::CVEngine(void)" (??0CVEngine@@QAE@XZ) already defined in MainForm.obj
1>CVEngine.obj : error LNK2005: "public: __thiscall CVEngine::~CVEngine(void)" (??1CVEngine@@QAE@XZ) already defined in MainForm.obj
1>CVEngine.obj : error LNK2005: "public: __thiscall CVEngine::CVEngine(void)" (??0CVEngine@@$$FQAE@XZ) already defined in MainForm.obj
1>CVEngine.obj : error LNK2005: "public: __thiscall CVEngine::~CVEngine(void)" (??1CVEngine@@$$FQAE@XZ) already defined in MainForm.obj
1>CVEngine.obj : warning LNK4248: unresolved typeref token (0100001A) for 'CvCapture'; image may not run
1>MainForm.obj : warning LNK4248: unresolved typeref token (01000021) for 'CvCapture'; image may not run
1>CVEngine.obj : error LNK2028: unresolved token (0A00052F) "extern "C" struct CvCapture * __cdecl cvCreateCameraCapture(int)" (?cvCreateCameraCapture@@$$J0YAPAUCvCapture@@H@Z) referenced in function "public: __thiscall CVEngine::CVEngine(void)" (??0CVEngine@@$$FQAE@XZ)
1>MainForm.obj : error LNK2028: unresolved token (0A000532) "extern "C" struct CvCapture * __cdecl cvCreateCameraCapture(int)" (?cvCreateCameraCapture@@$$J0YAPAUCvCapture@@H@Z) referenced in function "public: __thiscall CVEngine::CVEngine(void)" (??0CVEngine@@$$FQAE@XZ)
1>CVEngine.obj : error LNK2028: unresolved token (0A00065F) "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@$$FYAHPAHH@Z) referenced in function "public: void __thiscall cv::SparseMat::addref(void)" (?addref@SparseMat@cv@@$$FQAEXXZ)
1>MainForm.obj : error LNK2028: unresolved token (0A000672) "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@$$FYAHPAHH@Z) referenced in function "public: void __thiscall cv::SparseMat::addref(void)" (?addref@SparseMat@cv@@$$FQAEXXZ)
1>CVEngine.obj : error LNK2020: unresolved token (0A00066D) "public: void __thiscall cv::Mat::copySize(class cv::Mat const &)" (?copySize@Mat@cv@@$$FQAEXABV12@@Z)
1>MainForm.obj : error LNK2028: unresolved token (0A000680) "public: void __thiscall cv::Mat::copySize(class cv::Mat const &)" (?copySize@Mat@cv@@$$FQAEXABV12@@Z) referenced in function "public: __thiscall cv::Mat::Mat(class cv::Mat const &)" (??0Mat@cv@@$$FQAE@ABV01@@Z)
1>MainForm.obj : error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@$$FYAHPAHH@Z) referenced in function "public: void __thiscall cv::SparseMat::addref(void)" (?addref@SparseMat@cv@@$$FQAEXXZ)
1>CVEngine.obj : error LNK2001: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@$$FYAHPAHH@Z)
1>MainForm.obj : error LNK2019: unresolved external symbol "extern "C" struct CvCapture * __cdecl cvCreateCameraCapture(int)" (?cvCreateCameraCapture@@$$J0YAPAUCvCapture@@H@Z) referenced in function "public: __thiscall CVEngine::CVEngine(void)" (??0CVEngine@@$$FQAE@XZ)
1>CVEngine.obj : error LNK2001: unresolved external symbol "extern "C" struct CvCapture * __cdecl cvCreateCameraCapture(int)" (?cvCreateCameraCapture@@$$J0YAPAUCvCapture@@H@Z)
1>MainForm.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::copySize(class cv::Mat const &)" (?copySize@Mat@cv@@$$FQAEXABV12@@Z) referenced in function "public: __thiscall cv::Mat::Mat(class cv::Mat const &)" (??0Mat@cv@@$$FQAE@ABV01@@Z)
1>CVEngine.obj : error LNK2001: unresolved external symbol "public: void __thiscall cv::Mat::copySize(class cv::Mat const &)" (?copySize@Mat@cv@@$$FQAEXABV12@@Z)
1>e:documentsvisual studio 2013ProjectsSensor CamDebugSensor Cam.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
MainForm.h文件:
#pragma once
#include "CVEngine.cpp"
namespace SensorCam {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
// using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for MainForm
/// </summary>
public ref class MainForm : public System::Windows::Forms::Form
{
public:
MainForm(void)
{
InitializeComponent();
//
// TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MainForm()
{
if (components)
{
delete components;
}
}
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->SuspendLayout();
//
// MainForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(633, 418);
this->Name = L"MainForm";
this->Text = L"Sensor Cam";
this->Load += gcnew System::EventHandler(this, &MainForm::MainForm_Load);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void MainForm_Load(System::Object^ sender, System::EventArgs^ e)
{
CVEngine cve = CVEngine::CVEngine();
}
};
}
MainForm.cpp文件:
#include "MainForm.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThread]
void main(int argc, char *argv[])
{
Application::EnableVisualStyles();
// Application::SetCompatibleTextRenderingDefault(false);
SensorCam::MainForm form;
Application::Run(%form);
}
CvEngine.cpp文件:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
class CVEngine
{
public:
CVEngine();
~CVEngine();
private:
CvCapture* capture;
};
CVEngine::CVEngine()
{
capture = cvCaptureFromCAM(-1);
if (!capture)
{
// Todo: error handling
}
}
CVEngine::~CVEngine()
{
}
要编译它,创建一个cv_engine.h文件
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
class CVEngine
{
public:
CVEngine();
~CVEngine();
private:
CvCapture* capture;
};
cv_engine.cpp
#include "cv_engine.h"
CVEngine::CVEngine()
{
capture = cvCaptureFromCAM(-1);
if (!capture)
{
// todo: error handling
}
}
CVEngine::~CVEngine()
{
}
则Mainform.h中的#include "cv_engine.h"
另外,你不应该在头文件中做这样的事情…
using namespace cv;
当你可以使用scope…
cv::CvCapture* capture;
相关文章:
- 在Qt应用程序中包含Python.h会导致对Qt函数的未定义引用
- 如何将视觉C++重新分发包含在应用程序中
- QTCreator GUI应用程序中包含窗口基源代码并在代码中打开
- Eclipse 在检查语法时看不到包含文件,但在构建或运行应用程序时会看到
- 在静态库中使用Boost会导致应用程序包含Boost
- 如何在<QtWin>应用程序中包含 #include - QtWinExtras
- 获取包含共享库的c++应用程序的调用堆栈
- 将Poco C++库包含到Mac OS X上的Qt Quick应用程序(Qt Creator)中
- 使用DLL时应用程序中包含的.lib文件
- 外部应用程序使用共享内存接收消息,但没有包含的数据
- visual 无法在控制台应用程序项目中包含头文件C++
- 将信息从 Chromium Embedded (Javascript) 发送到包含C++的应用程序
- <QNetworkAccessManager><QNetworkReply> 在 BB10 应用程序开发的 cpp 文件中包含 时出错
- 包含atlbase.h标头时应用程序崩溃
- c++应用程序使用qt,如何包含gnuplot
- 将Alien包含在便携式应用程序C++中
- 拥有一个包含MFC项目和用于单元测试的控制台应用程序的解决方案
- 如何将CodeSynthesis XSD包含到自己的应用程序中
- 如何在 qt 应用程序中包含 jxcore c++ 库"jx.h"?
- 不能在Windows服务应用程序中包含某些boost头