LNK2005和LNK 1160在vc ++中

时间:2018-04-04 03:24:16

标签: c++ visual-c++ lnk2005

我是c ++和vc ++的新手,我使用的是第三方库bioapi。我成功整合了它,但当我尝试使用bioapimisc.hmisc.cpp的示例工作程序时,我收到了错误LNK2005LNK1160

顺便说一句,我在vc ++中创建了这个CLR项目,似乎我不能使用/ FORCE或/ FORCE:MULTIPLE。

这是misc.h

/*---------------------------------------------------------------*/
/*                                                               */
/* Copyright  (C)  NEC  Corporation  2011                        */
/* NEC  CONFIDENTIAL  AND  PROPRIETARY                           */
/*                                                               */
/*  All rights reserved by NEC Corporation. This program must be */
/* used solely for the purpose for which it was furnished by NEC */
/* Corporation.  No part of this program may be reproduced or    */
/* disclosed to others, in any form, without the prior written   */
/* permission of NEC Corporation.  Use of copyright notice does  */
/* not evidence publication of this program.                     */
/*                                                               */
/* NEC Corporation accepts no responsibility for any damages     */
/* resulting from the use of this sample code.                   */
/* This sample code is provided "AS IS", and its user assume all */
/* risks when using it.                                          */
/*                                                               */
/*---------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <sys/types.h>          /* for stat()   */
#include <sys/stat.h>           /* for stat()   */
#include <direct.h>             /* for _mkdir() */

//#include "stdafx.h"
//#include "resource.h"
#include "BioAPI.h"             /* include BioAPI Framework */
#include "BioAPI_util.h"        /* include BioAPI Framework */

#include "hf-pid-bsp.h"

/*--------------------------------------------------------------------
*
*  define
*
*--------------------------------------------------------------------*/
#define MaxN           1000     /* Max Identify Num */
#define MaxEnrollNum   999      /* Max Enroll Num   */
#define MaxID          9999     /* Max Enroll ID    */
#define MinID          0        /* Min Enroll ID    */
#define Timeout        10000     /* Capture Timeout  */


#define ERRCODE_ID_INPUT_ERROR          -100
#define ERRCODE_NOT_ENROLLED            -101

#define SECTION_IDENTIFYPARAM           "IdentifyParam"
#define KEY_MAXNUMBEROFRESULTS          "MaxNumberOfResults"

#define MESS_ALLEADY_STARTED            "Application is already started."
#define MESS_USERREG                    "UserReg"
#define MESS_AP_ERROR                   "Error"
#define MESS_ID_INPUT_ERROR             TEXT("Please input a value in the range of 0001-9999")
#define MESS_NOT_ENROLLED               TEXT("The ID does not exist for")
#define MESS_BIOAPI_ERROR               TEXT("BioAPI Error")
#define MESS_BIOAPI_ERROR_CODE          TEXT("BioAPI Error Code: %ld")
#define MESS_ENROLL                     "Enrollment"
#define MESS_ENROLL_FAILED              "Enroll process is failed."
#define MESS_ENROLL_SUCCESSED           "Enroll process is successed."
#define MESS_VERIFY                     "Verification"
#define MESS_VERIFY_FAILED              "Verification failed."
#define MESS_VERIFY_OK                  "Verification process is successed."
#define MESS_VERIFY_NG                  "Verification process is failed."
#define MESS_IDENTIFY                   "Identification"
#define MESS_IDENTIFY_FAILED            "Identification failed."
#define MESS_IDENTIFY_OK                "Identification process is successed."
#define MESS_IDENTIFY_NG                "Identification process is failed."
#define MESS_CAPTION                    "Sample Application"
#define MESS_END                        "Exit"
#define MESS_MESSAGE1                   "Please choose the function."
#define MESS_CLOSE                      "Close"
#define MESS_ENROLL1                    "Enroll"
#define MESS_ENROLL2                    "CreateTemplate"
#define MESS_MESSAGE2                   "After entering ID(0001`9999), Please click [Enroll] button or [CreateTemplate] button."
#define MESS_ID                         "ID:"
#define MESS_ONETOONE                   "1:1 Verification"
#define MESS_ONETON                     "1:N Identification"
#define MESS_MESSAGE3                   "Please choose the verification method."
#define MESS_VERIFY1                    "VerifyMatch"
#define MESS_VERIFY2                    "Verify"
#define MESS_MESSAGE4                   "After entering ID(0001`9999), Please click [Verify] button or [Verification] button."
#define MESS_IDENTIFY1                  "IdentifyMatch"
#define MESS_IDENTIFY2                  "Identify"
#define MESS_MESSAGE5                   "Please click [Identify] button or [Identification] button."
#define MESS_AUTH_MESSAGE               "Identification process is successed.\r\nMaxNumberOfResults = (%d)\r\nNumberOfResults = (%d)\r\nID:"
#define MESS_INIFILE_GET_FAILED         "sample.ini get failed."

#define PATH_ENROLLED_FILE              ".\\enroll\\*.dat"
#define PATH_ENROLLED_FILE_IN_ID        ".\\enroll\\%04d_*.dat"
#define PATH_ENROLLED_DIRECTORY         ".\\enroll"
#define PATH_ENROLLED_NAME              TEXT(".\\enroll\\%s_%03d.dat")
#define PATH_ENROLLED_DIRECTORY         ".\\enroll"
#define INIFILE_NAME                    ".\\sample.ini"

/*--------------------------------------------------------------------
*
*  global
*
*--------------------------------------------------------------------*/
static BioAPI_HANDLE                gModuleHandle;
static BioAPI_RETURN                bioReturn;
static BioAPI_BIR_HANDLE            StoredTemplate;
static BioAPI_INPUT_BIR             CapturedBIR;
static BioAPI_INPUT_BIR             ProcessedBIR;
static BioAPI_INPUT_BIR             StoredBIR;
static BioAPI_BIR_HANDLE            CapturedTemplate;
static BioAPI_BOOL                  boolie = BioAPI_FALSE;
static BioAPI_BOOL                  result;
static BioAPI_FRR                   frr = HF_PID_BSP_LEVEL_MIDDLE;    // Security Level
static BioAPI_FAR                   AchievedFAR = 1;
static uint32                       MaxNumberOfResults = 1;
static uint32                       NumberOfResults;
static BioAPI_CANDIDATE_ARRAY_PTR   Candidates;
static BioAPI_INPUT_BIR             InputBirProcessed_PopulationElem[MaxN];
static BioAPI_IDENTIFY_POPULATION   *Population;
static BioAPI_BIR_PTR               lpPopulationAryBIRData_Member;
static HANDLE                       hSearch;
static char                         fname_db[MAX_PATH + 1];
static char                         fid_db[MAX_PATH + 1];
static WIN32_FIND_DATA              fd;
static BioAPI_BIR_ARRAY_POPULATION  lPopulationAryBIRData;
static BioAPI_BIR_PTR               FullBIR;
static BioAPI_UUID                  BSPUuid = HF_PID_BSP_UUID;
typedef struct stBIR_AND_FileName {
    BioAPI_BIR* pPopulationBIRPointer;
    char        lptszUserName[_MAX_PATH];
}BIR_AND_FILENAME;
static BIR_AND_FILENAME             RetBIR_And_FileName[MaxN];
static BioAPI_CANDIDATE_ARRAY       lpWorkCandidates;
static char                         IdentificationMessage[MAX_PATH + 1];

/*--------------------------------------------------------------------
*
* function
*
*--------------------------------------------------------------------*/
void PrintErrorCode(BioAPI_RETURN bioReturn);
void LoadBSP(BioAPI_HANDLE_PTR gModuleHandle);
void ReleaseBSP(BioAPI_HANDLE_PTR gModuleHandle);
BioAPI_RETURN OutputToFile(BioAPI_HANDLE gModuleHandle, LPTSTR lptszUserName, BioAPI_BIR_HANDLE BirHandle);
BioAPI_RETURN InputFromFile(LPTSTR lptszUserName, BioAPI_INPUT_BIR * InputBir, uint32 count);

/*--------------------------------------------------------------------
*
*  End of misc.h
*
*--------------------------------------------------------------------*/

misc.cpp

/*---------------------------------------------------------------*/
/*                                                               */
/* Copyright  (C)  NEC  Corporation  2011                        */
/* NEC  CONFIDENTIAL  AND  PROPRIETARY                           */
/*                                                               */
/*  All rights reserved by NEC Corporation. This program must be */
/* used solely for the purpose for which it was furnished by NEC */
/* Corporation.  No part of this program may be reproduced or    */
/* disclosed to others, in any form, without the prior written   */
/* permission of NEC Corporation.  Use of copyright notice does  */
/* not evidence publication of this program.                     */
/*                                                               */
/* NEC Corporation accepts no responsibility for any damages     */
/* resulting from the use of this sample code.                   */
/* This sample code is provided "AS IS", and its user assume all */
/* risks when using it.                                          */
/*                                                               */
/*---------------------------------------------------------------*/

//#include "stdafx.h"
#include "misc.h"

/*--------------------------------------------------------------------
*
*  PrintErrorCode
*
*--------------------------------------------------------------------*/
void PrintErrorCode(
    BioAPI_RETURN bioReturn     /* INPUT : BioAPI Error Code */
)
{
    TCHAR szMessage[_MAX_PATH];

    // ID Input Error
    if (bioReturn == ERRCODE_ID_INPUT_ERROR)
    {
        wsprintf(szMessage, MESS_ID_INPUT_ERROR);
        MessageBox(GetActiveWindow(), szMessage, MESS_BIOAPI_ERROR, MB_OK | MB_ICONSTOP);
    }
    // Not Enrolled Error
    else if (bioReturn == ERRCODE_NOT_ENROLLED)
    {
        wsprintf(szMessage, MESS_NOT_ENROLLED);
        MessageBox(GetActiveWindow(), szMessage, MESS_BIOAPI_ERROR, MB_OK | MB_ICONSTOP);
    }
    // BioAPI Error
    else
    {
        wsprintf(szMessage, MESS_BIOAPI_ERROR_CODE, bioReturn);
        MessageBox(GetActiveWindow(), szMessage, MESS_BIOAPI_ERROR, MB_OK | MB_ICONSTOP);
    }

    return;
}

/*--------------------------------------------------------------------
*
*  LoadBSP
*
*--------------------------------------------------------------------*/
void LoadBSP(
    BioAPI_HANDLE_PTR gModuleHandle     /* INPUT : BSP Module Handle */
)
{
    BioAPI_VERSION bioVersion;
    bioVersion.Major = BioAPI_MAJOR;
    bioVersion.Minor = BioAPI_MINOR;

    bioReturn = BioAPI_Init(&bioVersion, 0, NULL, 0, NULL);
    if (BioAPI_OK != bioReturn)
    {
        PrintErrorCode(bioReturn);
        return;
    }
    bioReturn = BioAPI_ModuleLoad(&BSPUuid, 0, NULL, 0);
    if (BioAPI_OK != bioReturn)
    {
        PrintErrorCode(bioReturn);
        return;
    }
    bioReturn = BioAPI_ModuleAttach(&BSPUuid, &bioVersion, &BioAPIWinMemoryFuncs, 0, 0, 0, 0, NULL, 0, NULL, gModuleHandle);
    if (BioAPI_OK != bioReturn)
    {
        PrintErrorCode(bioReturn);
        return;
    }

    return;
}

/*--------------------------------------------------------------------
*
*  ReleaseBSP
*
*--------------------------------------------------------------------*/
void ReleaseBSP(
    BioAPI_HANDLE_PTR gModuleHandle     /* INPUT : BSP Module Handle */
)
{
    if (gModuleHandle != 0)
    {
        bioReturn = BioAPI_ModuleDetach(*gModuleHandle);
        if (BioAPI_OK != bioReturn)
        {
            PrintErrorCode(bioReturn);
            return;
        }
        gModuleHandle = 0;
    }
    bioReturn = BioAPI_ModuleUnload(&BSPUuid, NULL, 0);
    if (BioAPI_OK != bioReturn)
    {
        PrintErrorCode(bioReturn);
        return;
    }
    bioReturn = BioAPI_Terminate();
    if (BioAPI_OK != bioReturn)
    {
        PrintErrorCode(bioReturn);
        return;
    }

    return;
}

/*--------------------------------------------------------------------
*
*  OutputToFile
*
*--------------------------------------------------------------------*/
BioAPI_RETURN OutputToFile(
    BioAPI_HANDLE gModuleHandle,    /* INPUT : BSP Module Handle */
    LPTSTR lptszUserName,           /* INPUT : Save File Neme    */
    BioAPI_BIR_HANDLE BirHandle     /* INPUT : Save BIR Data     */
)
{
    TCHAR           szFileName[_MAX_PATH];
    HANDLE          hFile;
    DWORD           dwBytesToWrite, dwBytesWritten;
    BioAPI_BIR_PTR  birData = NULL;
    BioAPI_RETURN   bioReturn;
    uint32          count = 0;
    struct stat     buff;

    // Retrieve the BIR from the BSP
    bioReturn = BioAPI_GetBIRFromHandle(gModuleHandle, BirHandle, &birData);
    if (bioReturn != BioAPI_OK)
    {
        return bioReturn;
    }

    // Search Save FileName
    _mkdir(PATH_ENROLLED_DIRECTORY);
    while (1)
    {
        if (++count > MaxEnrollNum)
        {
            return -1; // Can't make file
        }
        wsprintf(szFileName, PATH_ENROLLED_NAME, lptszUserName, count);
        if ((stat(szFileName, &buff) != 0))
        {
            break;
        }
    }

    // Open the file 
    hFile = CreateFile(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile == INVALID_HANDLE_VALUE)
    {
        return 0; // this return value is ignored anyway
    }

    // Write the header
    WriteFile(hFile, &(birData->Header), sizeof(BioAPI_BIR_HEADER), &dwBytesWritten, NULL);

    // Write the biometric data
    dwBytesToWrite = LocalEndian4(birData->Header.Length) - sizeof(BioAPI_BIR_HEADER);
    WriteFile(hFile, birData->BiometricData, dwBytesToWrite, &dwBytesWritten, NULL);

    // Write the signature if present
    if (birData->Signature)
    {
        WriteFile(hFile, &(birData->Signature->Length), 4, &dwBytesWritten, NULL);
        dwBytesToWrite = LocalEndian4(birData->Signature->Length);
        WriteFile(hFile, birData->Signature->Data, dwBytesToWrite, &dwBytesWritten, NULL);
    }

    // Close the file
    CloseHandle(hFile);

    // Free all the memory allocated for the BIR
    if (birData != NULL) {
        GlobalFree(birData->BiometricData);
        if (birData->Signature)
        {
            GlobalFree(birData->Signature->Data);
            GlobalFree(birData->Signature);
        }
        GlobalFree(birData);
    }
    return BioAPI_OK;
}

/*--------------------------------------------------------------------
*
*  InputFromFile
*
*--------------------------------------------------------------------*/
BioAPI_RETURN InputFromFile(
    LPTSTR lptszUserName,           /* INPUT  : Load File Name      */
    BioAPI_INPUT_BIR * InputBir,    /* OUTPUT : Load BIR Data       */
    uint32 count                    /* INPUT  : User Enroll Number  */
)
{
    TCHAR       szFileName[_MAX_PATH];
    HANDLE      hFile;
    DWORD       dwBytesToRead, dwBytesRead;
    BioAPI_BIR  *bir;

    // Open the file 
    wsprintf(szFileName, PATH_ENROLLED_NAME, lptszUserName, count);
    hFile = CreateFile(szFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile == INVALID_HANDLE_VALUE)
    {
        return BioAPIERR_BSP_RECORD_NOT_FOUND; // Return this BSP error if the file isn't present
    }

    // Read the header in, to determine the size
    dwBytesToRead = sizeof(BioAPI_BIR_HEADER);
    bir = (BioAPI_BIR*)GlobalAlloc(GPTR, sizeof(BioAPI_BIR));
    if (!bir)
    {
        return !BioAPI_OK;
    }
    ReadFile(hFile, &(bir->Header), dwBytesToRead, &dwBytesRead, NULL);

    // Read the biometric data
    dwBytesToRead = LocalEndian4(bir->Header.Length) - sizeof(BioAPI_BIR_HEADER);
    bir->BiometricData = (BioAPI_BIR_BIOMETRIC_DATA_PTR)GlobalAlloc(GPTR, dwBytesToRead);
    if (!bir->BiometricData)
    {
        return !BioAPI_OK;
    }
    ReadFile(hFile, bir->BiometricData, dwBytesToRead, &dwBytesRead, NULL);

    // Read the signature if present
    dwBytesToRead = 0;
    if (ReadFile(hFile, &dwBytesToRead, 4, &dwBytesRead, NULL) != 0 && dwBytesToRead != 0)
    {
        bir->Signature = (BioAPI_DATA_PTR)GlobalAlloc(GPTR, sizeof(BioAPI_DATA));
        if (!bir->Signature)
        {
            return !BioAPI_OK;
        }
        bir->Signature->Length = dwBytesToRead;
        dwBytesToRead = LocalEndian4(dwBytesToRead);
        bir->Signature->Data = (uint8 *)GlobalAlloc(GPTR, dwBytesToRead);
        if (!bir->Signature->Data)
        {
            return !BioAPI_OK;
        }
        ReadFile(hFile, bir->Signature->Data, dwBytesToRead, &dwBytesRead, NULL);
    }

    // Close the file
    CloseHandle(hFile);

    // Set up the return values
    InputBir->InputBIR.BIR = bir;
    InputBir->Form = BioAPI_FULLBIR_INPUT;

    return BioAPI_OK;
}
/*--------------------------------------------------------------------
*
*  End of misc.cpp
*
*--------------------------------------------------------------------*/

错误:

1>libucrt.lib(exit.obj) : error LNK2005: _cexit already defined in ucrtd.lib(ucrtbased.dll)
1>libucrt.lib(onexit.obj) : error LNK2005: _crt_at_quick_exit already defined in ucrtd.lib(ucrtbased.dll)
1>libucrt.lib(onexit.obj) : error LNK2005: _crt_atexit already defined in ucrtd.lib(ucrtbased.dll)
1>libucrt.lib(onexit.obj) : error LNK2005: _execute_onexit_table already defined in ucrtd.lib(ucrtbased.dll)
1>libucrt.lib(onexit.obj) : error LNK2005: _initialize_onexit_table already defined in ucrtd.lib(ucrtbased.dll)
1>libucrt.lib(onexit.obj) : error LNK2005: _register_onexit_function already defined in ucrtd.lib(ucrtbased.dll)
1>libucrt.lib(environment_initialization.obj) : error LNK2005: _initialize_narrow_environment already defined in ucrtd.lib(ucrtbased.dll)
1>libucrt.lib(exception_filter.obj) : error LNK2005: _seh_filter_dll already defined in ucrtd.lib(ucrtbased.dll)
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'ucrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>C:\Users\Laptop-attendance\source\repos\Bioapitest\x64\Debug\Bioapitest.exe : fatal error LNK1169: one or more multiply defined symbols found

0 个答案:

没有答案