VS10 C ++ - 致命错误LNK 1120

时间:2013-06-22 22:09:53

标签: c++

我正在尝试创建一个简单的C ++应用程序,它将在我的PC上搜索并列出所有.wav文件。我试图找出LNK 1120错误,但没有运气。任何人都能指出我正确的方向,并告诉我在这里做错了什么?

#include "stdafx.h"
#include "iostream"
#include "Shlwapi.h"
#include "windows.h"

void FindFilesRecursively(LPCTSTR lpFolder, LPCTSTR lpFilePattern);

int _tmain(int argc, _TCHAR* argv[])
{
    LPCTSTR loc = "C://";
    LPCTSTR ft = ".wav";
    FindFilesRecursively(loc, ft);
    return 0;
}

void FindFilesRecursively(LPCTSTR lpFolder, LPCTSTR lpFilePattern)
{
    TCHAR szFullPattern[MAX_PATH];
    WIN32_FIND_DATA FindFileData;
    HANDLE hFindFile;
    // first we are going to process any subdirectories
    PathCombine(szFullPattern, lpFolder, _T("*"));
    hFindFile = FindFirstFile(szFullPattern, &FindFileData);
    if(hFindFile != INVALID_HANDLE_VALUE)
    {
        do
        {
            if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                // found a subdirectory; recurse into it
                PathCombine(szFullPattern, lpFolder, FindFileData.cFileName);
                FindFilesRecursively(szFullPattern, lpFilePattern);
            }
        } while(FindNextFile(hFindFile, &FindFileData));
        FindClose(hFindFile);
    }
    // now we are going to look for the matching files
    PathCombine(szFullPattern, lpFolder, lpFilePattern);
    hFindFile = FindFirstFile(szFullPattern, &FindFileData);
    if(hFindFile != INVALID_HANDLE_VALUE)
    {
        do
        {
            if(!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
            {
                // found a file; do something with it
                PathCombine(szFullPattern, lpFolder, FindFileData.cFileName);
                std::cout << (_T("%s\n"), szFullPattern);
            }
        } while(FindNextFile(hFindFile, &FindFileData));
        FindClose(hFindFile);
    }
}

这些是我收到的错误消息

1>------ Build started: Project: SearchForFile, Configuration: Debug Win32 ------ 
1>SearchForFile.cpp 
1>SearchForFile.obj : error LNK2019: unresolved external symbol __imp__PathCombineA@12 referenced in function "void __cdecl FindFilesRecursively(char const *,char const *)" (?FindFilesRecursively@@YAXPBD0@Z)
1>c:\users\User\documents\visual studio 2010\Projects\SearchForFile\Debug\SearchForFile.exe : fatal error LNK1120: 1 unresolved externals
> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

1 个答案:

答案 0 :(得分:2)

PathCombine函数位于Shlwapi.lib库中,您需要将此库添加到项目链接器设置中。

打开项目设置并导航到“Configuration Properties-&gt; Linker-&gt; Input”并转到“Additional Dependencies”选项并在其中添加库Shlwapi.lib