- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我编写了这个简单的程序,它从 txt 文件中加载矩阵并计算距离。在 windows 上的 Visual Studio 中编译程序时,出现以下错误:
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree@cv@@YAXPAX@Z) referenced in function "public: __thiscall cv::Mat::~Mat(void)" (??1Mat@cv@@QAE@XZ)
1>system.obj : error LNK2001: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree@cv@@YAXPAX@Z)
1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" (?deallocate@Mat@cv@@QAEXXZ) referenced in function "public: void __thiscall cv::Mat::release(void)" (?release@Mat@cv@@QAEXXZ)
1>system.obj : error LNK2001: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" (?deallocate@Mat@cv@@QAEXXZ)
1>main.obj : error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@YAHPAHH@Z) referenced in function "public: void __thiscall cv::Mat::release(void)" (?release@Mat@cv@@QAEXXZ)
1>system.obj : error LNK2001: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@YAHPAHH@Z)
1>system.obj : error LNK2019: unresolved external symbol "public: __thiscall cv::Exception::Exception(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (??0Exception@cv@@QAE@HABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00H@Z) referenced in function "public: int & __thiscall cv::Mat::at<int>(int,int)" (??$at@H@Mat@cv@@QAEAAHHH@Z)
1>system.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall cv::Exception::~Exception(void)" (??1Exception@cv@@UAE@XZ) referenced in function "public: int & __thiscall cv::Mat::at<int>(int,int)" (??$at@H@Mat@cv@@QAEAAHHH@Z)
1>system.obj : error LNK2019: unresolved external symbol "void __cdecl cv::error(class cv::Exception const &)" (?error@cv@@YAXABVException@1@@Z) referenced in function "public: int & __thiscall cv::Mat::at<int>(int,int)" (??$at@H@Mat@cv@@QAEAAHHH@Z)
1>system.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::create(int,int const *,int)" (?create@Mat@cv@@QAEXHPBHH@Z) referenced in function "public: void __thiscall cv::Mat::create(int,int,int)" (?create@Mat@cv@@QAEXHHH@Z)
1>C:\Users\Ram\documents\visual studio 2012\Projects\descrip\Debug\descrip.exe : fatal error LNK1120: 7 unresolved externals
我在我的电脑上安装了 opencv 2.4.6 并将其正确链接到 Visual Studio。
main.cpp
#include "system.h"
using namespace std;
int main(int argc, char* argv[]){
if(argc != 3){
cout << "Not enough arguments" << endl;
exit(-1);
}
System s(argv[2]);
s.Parse_Centers(argv[1]);
s.Run();
return 0;
}
系统.h
#include <iostream>
#include <fstream>
#include <dirent.h>
#include <time.h>
#include "cv.h"
#include "highgui.h"
#include "opencv2/opencv.hpp"
#define NUM_CENTERS 5000
#define NUM_COL 512
using namespace cv;
class System{
public:
System(char *dir);
void Run();
void Parse_Centers(char* path);
void Compute_Histogram(const char* filename);
private:
Mat centers;
Mat centers_zero;
char *dir_path;
};
系统.cpp
#include "system.h"
using namespace std;
using namespace cv;
System::System(char *dir){
centers.create(NUM_CENTERS, NUM_COL, CV_8U);
centers_zero.create(NUM_CENTERS, NUM_COL, CV_8U);
dir_path = dir;
};
void System::Parse_Centers(char* path){
ifstream fin;
int temp, n, line = 0;
fin.open(path);
if(!fin.good()){
throw 1;
}
while(!fin.eof()){
char buf[2048];
const char* token[NUM_COL] = {};
n = 0;
fin.getline(buf, 2048);
token[0] = strtok(buf, ",");
if(token[0]){
temp = atoi(token[0]);
if(temp){
centers.at<int>(line,n) = temp;
centers_zero.at<int>(line,n) = temp * temp;
}
for(int n = 1; n < 512; n++){
token[n] = strtok(0, ",");
temp = atoi(token[n]);
if(temp){
centers.at<int>(line,n) = temp;
centers_zero.at<int>(line,n) = temp * temp;
}
}
}
line++;
}
fin.close();
};
void System::Run(){
DIR *dir;
struct dirent *entry;
time_t start_t;
time_t end_t;
dir = opendir(dir_path);
if(!dir){
cout << "Directory wasn't found" << endl;
throw 3;
}
while((entry = readdir(dir)) != NULL){
if(entry->d_name[0] != '.'){
string path = string(dir_path) + "/" + string(entry->d_name);
cout << "entry: " << path;
time(&start_t);
Compute_Histogram(path.c_str());
time(&end_t);
cout << " " << difftime(start_t,end_t) << "sec" << endl;
}
}
closedir(dir);
}
void System::Compute_Histogram(const char* filename){
int dist[NUM_CENTERS];
int desc[NUM_CENTERS] = {0};
int temp, place = 0;
ifstream fin;
fin.open(filename);
if(!fin.good()){
throw 2;
}
while(!fin.eof()){
char buf[2048];
const char* token[512] = {};
fin.getline(buf, 2048);
token[0] = strtok(buf, ",");
if(token[0]){
temp = atoi(token[0]);
if(temp){
for(int i = 0; i < NUM_CENTERS; i++){
dist[i] = (temp - centers.at<int>(i,0)) * (temp - centers.at<int>(i,0));
}
}
else{
for(int i = 0; i < NUM_CENTERS; i++){
dist[i] = centers_zero.at<int>(i,0);
}
}
for(int n = 1; n < NUM_COL; n++){
token[n] = strtok(0, ",");
temp = atoi(token[n]);
if(temp){
for(int i = 0; i < NUM_CENTERS; i++){
dist[i] += (temp - centers.at<int>(i,n)) * (temp - centers.at<int>(i,n));
if((n == 511) && (i > 0)){
if(dist[i] < dist[place]){
place = i;
}
}
}
}
else{
for(int i = 0; i < NUM_CENTERS; i++){
dist[i] += centers_zero.at<int>(i,n);
if((n == 511) && (i > 0)){
if(dist[i] < dist[place]){
place = i;
}
}
}
}
}
}
desc[place]++;
}
fin.close();
ofstream outfile;
string path;
path = string(filename) + ".csv";
outfile.open(path.c_str());
for(int i = 0; i < 4999; i++){
outfile << desc[i] << ",";
}
outfile << desc[4999];
outfile.close();
};
我做错了什么????
最佳答案
与其他人提到的一样,您需要确保正确链接到 OpenCV 库。
检查您的 项目 -> 属性 -> VC++ 目录 -> 库目录,包括 OpenCV 库所在的路径,默认为 'C:\opencv\build\x86\vc11\lib'(在运行 VS2012 的 32 位机器上,它会因其他设置而异)。
接下来,检查您的项目 -> 属性 -> 链接器 -> 输入 -> 附加依赖项中是否包含以下库:
opencv_core246d.lib
opencv_imgproc246d.lib
opencv_highgui246d.lib
opencv_ml246d.lib
opencv_video246d.lib
opencv_features2d246d.lib
opencv_calib3d246d.lib
opencv_objdetect246d.lib
opencv_contrib246d.lib
opencv_legacy246d.lib
opencv_flann246d.lib
如果以上正确,您应该不会再收到任何 OpenCV 链接错误。
关于c++ - 错误 LNK2019 : unresolved external symbol opencv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18360540/
这段代码是否正确? extern "C" extern int x; // 1 extern extern "C" int y; // 2 extern "C" extern
根据 C++ Primer ,我们可以为定义为 extern 的变量提供初始化程序,但这样做会覆盖 extern。具有初始值设定项的 extern 是一个定义: extern double pi =
使用 Cuda 5.0、VS2010 这个项目在 VS2012 中编译和链接很好,但是 VS2012 不支持 Nsight 调试所以我也在 VS2010 中开发。所以我有一个 VS2010 项目文件,
这个问题已经有答案了: How do I use extern to share variables between source files? (19 个回答) Different compilat
我正在编写供 C 程序使用的 C++ 共享库。但是,我对 extern 和 extern "C" 有疑问。 考虑以下代码 我的头文件是这样的: #ifdef __cplusplus
我对整个 header 使用 extern "C" 说明符,还是为每个函数指定 extern 有区别吗? 据我所知,没有,因为只有函数和变量可以外部链接,所以当我在每个函数原型(prototype)和
这个问题在这里已经有了答案: What is the effect of extern "C" in C++? (17 个答案) 关闭 7 年前。 我见过 C/C++ 代码使用在函数签名中声明的 e
所以我使用 svn:externals 来检查一个外部仓库。外部仓库有自己的 svn-externals 设置。 现在,当更新我的项目的工作副本时,来自外部存储库的文件正在更新,但它的外部文件没有。该
是否可以忽略 svn:externals 属性中引用的标记的外部依赖性?这听起来像是一个很奇怪的问题,但让我解释一下...... 我收集了大量独立的“可插入”代码模块,每个模块都可以作为独立项目进行独
我见过 2 种创建全局变量的方法,有什么区别,什么时候使用它们? //.h extern NSString * const MyConstant; //.m NSString * const MyCo
我在 test 模块下通过 stripe api 在 stripe 中创建了一个帐户。并与该账户绑定(bind)一个银行账户。转到 Stripe dashboard -> connect -> acc
我在下面有一个代码。它是由 qemu 程序(一个 C 程序)使用 dlopen 加载的动态共享库的一部分。 extern "C" { extern uint64_t host_virt_offset;
C++ Primer 第 5 版第 60 页讨论了如何跨文件共享 const 变量 //file_1.cc extern const int bufSize = fcn(); //file_1.h e
这个 Unresolved external 问题有什么问题?我正在尝试将其实现到我的 MFC 应用程序的 InitInstance 中。但是我从调试器中收到此行错误。 LNK2019: unreso
在 C++ 中,extern(后面不跟语言链接字符串文字)似乎对命名空间范围 (Difference between declaration of function with extern and w
假设我有 3 个文件:file1.c、file2.c 和 globals.h。 file1.c 和 file2.c 都包含 globals.h。 file1.c 包含 file2.c 需要使用的结构。
我正在为具有 16 位安装程序的旧 CD-ROM 游戏编写新的安装程序,安装程序需要在硬盘上并且能够从原始光盘复制文件。如果所有游戏文件都打包在安装程序中,我已经设置了一个可以安装游戏的脚本,这适合个
在编译我的代码时,我收到此错误。 1>MSVCRTD.lib(crtexe.obj):错误 LNK2019:函数 ___tmainCRTStartup 中引用了未解析的外部符号 _main1>C:\U
我试图将 cimg 库包装在 c++/clr 中,当我尝试构建它时,我遇到了一堆链接错误。 Error 20 error LNK2028: unresolved token (0A0002AC)
我一直遇到这两个错误,但我似乎找不到有效的解决方案。 LNK1120: 1 unresolved externals Error 1 error LNK2019: unresolved externa
我是一名优秀的程序员,十分优秀!