Ask Your Question
0

using opencv with c++ .net application compilation issues [closed]

asked 2016-11-27 02:23:46 -0600

Yasser Akram gravatar image

updated 2016-11-27 04:29:49 -0600

I didn't face any issues while linking opencv library with basic console application but when I moved to do the same in a .net framework template I got many LNK errors

image description

I didn't do anything strange except that I included the include and using namespace only.

I appreciate any assistance provided

PS: I managed to run it if I install the opencv package via NuGet but I don't wan't to use NuGet. (I tried to get frames from video but it is not working and I get an unhalded error while the same code is running with console without an issue)

This is a clean Form header. Whenever I place the include tags of opencv I will not be able to compile:

include "opencv2/objdetect/objdetect.hpp"
include "opencv2/highgui/highgui.hpp"
include "opencv2/imgproc/imgproc.hpp"
include opencv2/ml.hpp
include ctime

namespace VisionApp01
{
    using namespace cv;
    using namespace cv::ml;
    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 MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
    MyForm(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~MyForm()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::PictureBox^  beforeBox;
private: System::Windows::Forms::PictureBox^  afterBox;
protected:

protected:

private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container ^components;


    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
        this->beforeBox = (gcnew System::Windows::Forms::PictureBox());
        this->afterBox = (gcnew System::Windows::Forms::PictureBox());
        (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->beforeBox))->BeginInit();
        (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->afterBox))->BeginInit();
        this->SuspendLayout();
        // 
        // beforeBox
        // 
        this->beforeBox->Location = System::Drawing::Point(12, 12);
        this->beforeBox->Name = L"beforeBox";
        this->beforeBox->Size = System::Drawing::Size(300, 300);
        this->beforeBox->TabIndex = 0;
        this->beforeBox->TabStop = false;
        // 
        // afterBox
        // 
        this->afterBox->Location = System::Drawing::Point(353, 12);
        this->afterBox->Name = L"afterBox";
        this->afterBox->Size = System::Drawing::Size(300, 300);
        this->afterBox->TabIndex = 0;
        this->afterBox->TabStop = false;
        // 
        // MyForm
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(665, 330);
        this->Controls->Add(this->afterBox);
        this->Controls->Add(this->beforeBox);
        this->Name = L"MyForm";
        this->Text = L"MyForm";
        this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
        (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->beforeBox))->EndInit();
        (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->afterBox))->EndInit();
        this->ResumeLayout(false);

    }

private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e)
{

}
};

}

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2016-12-01 07:27:57.899746

Comments

I don't think there is a problem with include because it's a link error. I don't know C++ .net but when I have got an error like yours in C++ I copy lib from console application to my new application

LBerger gravatar imageLBerger ( 2016-11-27 03:13:16 -0600 )edit

can you please replace the screenshots with a text version ?

berak gravatar imageberak ( 2016-11-27 04:08:59 -0600 )edit

There is nothing special in the code but I included it. I removed the arrow brackets for 2 includes because of the formatting in the website is ignoring them.

Yasser Akram gravatar imageYasser Akram ( 2016-11-27 04:31:14 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-12-01 04:43:23 -0600

Yasser Akram gravatar image

Apart from doing the linker and include stuff I had also to: Use project build x64 instead of x86 Then I had to copy the .dlls to my project directory Then set the linker->System->SubSystem to WINDOWS. Then I had to go Advanced->Entry Point set to Main Don't forget that if you choose x64 to verify the linker and include setup is already implemented. Because I had to redo it as it seems x86 and x64 got different setup.

edit flag offensive delete link more

Comments

Then you can close question may be.

LBerger gravatar imageLBerger ( 2016-12-01 05:03:16 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-27 02:23:46 -0600

Seen: 397 times

Last updated: Dec 01 '16