我正在尝试将一个 c++ 项目从 linux 导入到 windows (vs2010)。我的问题是使用 dirent.h 引起的。我已经从这里下载了 windows 版本的 dirent:dirent。但是,当我编译我的项目时,我收到以下错误:
1>DBreading.obj : error LNK2001: unresolved external symbol _closedir
1>DBreading.obj : error LNK2001: unresolved external symbol _readdir
1>DBreading.obj : error LNK2001: unresolved external symbol _opendir
稍作研究,我发现我正在使用一些 unix 函数。我的代码是:
#include <DBreading.h>
#include <Detection.h>
#define _POSIX_SOURCE
#include <sys/stat.h>
#include <unistd.h>
#undef _POSIX_SOURCE
DBreading::DBreading(){}
vector <string> DBreading::listFile(string path){
vector<string> directories;
DIR *pDIR;
const char * c = path.c_str();
struct dirent *entry;
if( pDIR=opendir(c) ){
while(entry = readdir(pDIR)){
if( strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0 )
//cout << entry->d_name << "\n";
directories.push_back( entry->d_name);
}
closedir(pDIR);
}
// directories stores all subfolders or sub-files of a given path directory
return directories;
}
知道windows中closedir readdir和opendir的对应函数是什么吗?
1>------ Rebuild All started: Project: myProject, Configuration: Release Win32 ------
1> DBreading.cpp
1>DBreading.cpp(46): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(52): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(53): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(90): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(97): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(116): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(122): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(123): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(159): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(166): warning C4018: '<' : signed/unsigned mismatch
1> Detection.cpp
1>c:\opencv-2.4.6.1\install\include\opencv2\flann\logger.h(66): warning C4996: 'fopen':
This function or variable may be unsafe. Consider using fopen_s instead. To disable
deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdio.h(234) :
see
declaration of 'fopen'
1> main.cpp
1>main.cpp(120): warning C4018: '<' : signed/unsigned mismatch
1>main.cpp(166): warning C4018: '<' : signed/unsigned mismatch
1>main.cpp(182): warning C4018: '<' : signed/unsigned mismatch
1>main.cpp(206): warning C4018: '<' : signed/unsigned mismatch
1>main.cpp(268): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.obj : error LNK2001: unresolved external symbol _closedir
1>DBreading.obj : error LNK2001: unresolved external symbol _readdir
1>DBreading.obj : error LNK2001: unresolved external symbol _opendir
1>C:\Documents and Settings\chrathan.ITI-THERMI\My Documents\Visual Studio
2010\Projects\myProject\Release\myProject.exe : fatal error LNK1120: 3 unresolved