前提#1:我已经解决了错误,但我没有深入理解编译错误的原因.
前提#2:该程序的目标是通过多线程进程将图像复制到另一个图像中.也许存在更好的方法,但这不是问题的焦点话题(见前提#1).
我用OpenCV 3.1库编写了一个简单的程序,将图像复制到另一个图像中.它利用了更多线程的CPU的所有核心.
代码是:
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <thread>
using namespace cv;
using namespace std;
#define IMG_PATH "..\\img\\50a.png"
void copy_image(const Mat& input, Mat& output, int row_offset, int skip_row)
{
cout << row_offset;
Size size = input.size();
for (int r = row_offset; r < size.height; r += skip_row)
{
for (int c = 0; c < size.width; c++)
{
output.at<Vec3b>(r, c) = input.at<Vec3b>(r, c);
}
}
}
int main()
{
Mat input_img = …Run Code Online (Sandbox Code Playgroud) 我尝试将一个非常简单的动态库项目编译为.dll文件.项目名称为"Library".我正在使用Visual Studio 2015,项目属性如下:
在项目中只有两个文件:ClassA.h和ClassA.cpp.
ClassA.h中的代码是:
#ifndef CLASSA_H
#define CLASSA_H
using namespace std;
#ifdef LIBRARY_EXPORTS
#define CLASSA_API __declspec(dllexport)
#else
#define CLASSA_API __declspec(dllimport)
#endif
class ClassA
{
public:
static CLASSA_API void func();
};
#endif
Run Code Online (Sandbox Code Playgroud)
ClassA.cpp中的代码是:
#include "ClassA.h"
#include <iostream>
void ClassA::func()
{
cout << "SUCCESS!" << endl;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译此项目时,我收到此错误:
严重性代码说明项目文件行错误必须定义LNK1561入口点库C:\ Users\UX303\Documents\Visual Studio 2015\DLLTest\Library\LINK 1
我希望打印由C++ 11编写的多线程程序设置的{0,1,2,3}的排列.
源代码是这样的:
#include <iostream>
#include <stdio.h>
#include <thread>
#include <vector>
#include <chrono>
using namespace std;
void func(int index);
int main()
{
vector<thread> threads;
for (int i = 0; i < 4; i++)
{
auto var = [&]()
{
return func(i);
};
threads.push_back(thread(var));
}
for (auto& thread : threads)
thread.join();
}
void func(int index)
{
cout << index;
for (int i = 0; i < 10000; i++);
}
Run Code Online (Sandbox Code Playgroud)
我期望在输出中输入0123,但我收到奇怪的结果,如下:
0223
0133
0124
我不明白这种奇怪的行为,特别是我无法解释4号的存在.
可能这是初学者的错误,我感谢大家都会帮助我.