错误 LNK2019:未解析的外部符号 VS2013

error LNK2019: unresolved external symbol vs2013

本文关键字:外部 符号 VS2013 LNK2019 错误      更新时间:2023-10-16

我收到此错误,但我不知道如何解决。我正在使用Visual Studio 2013。

法典

-----DateUtils.h
#pragma once
#include <string>
class DateUtils
{
public:
    DateUtils();
    ~DateUtils();
    static time_t str2time_t(const std::string&, const std::string&);
};

-----ForexUtils32.h
#include <string>
// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the FOREXUTILS32_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// FOREXUTILS32_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef FOREXUTILS32_EXPORTS
#define FOREXUTILS32_API __declspec(dllexport)
#else
#define FOREXUTILS32_API __declspec(dllimport)
#endif
// This class is exported from the ForexUtils32.dll
class FOREXUTILS32_API CForexUtils32 {
public:
    CForexUtils32(void);
    // TODO: add your methods here.
};
extern FOREXUTILS32_API int nForexUtils32;
FOREXUTILS32_API int fnForexUtils32(void);
/********************   Add Begin   *************************/
FOREXUTILS32_API time_t str2time(const std::string&, const std::string&);


/********************   Add End     *************************/

-------DateUtils.cpp
#include "stdafx.h"
#include "DateUtils.h"
#include <sstream>
#include <iomanip>
using namespace std;
DateUtils::DateUtils()
{
}

DateUtils::~DateUtils()
{
}
time_t str2time_t(const string& datetimeIn, const string& formatIn) {
    struct tm tm_time;
    // For C++11
    istringstream iss(datetimeIn);
    iss >> get_time(&tm_time, formatIn.c_str());
    time_t time = mktime(&tm_time);
    return time;
}
------ForexUtils32.cpp
// ForexUtils32.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "ForexUtils32.h"
#include "DateUtils.h"

// This is an example of an exported variable
FOREXUTILS32_API int nForexUtils32=0;
// This is an example of an exported function.
FOREXUTILS32_API int fnForexUtils32(void)
{
    return 42;
}
// This is the constructor of a class that has been exported.
// see ForexUtils32.h for the class definition
CForexUtils32::CForexUtils32()
{
    return;
}

/********************   Add Begin   *************************/
FOREXUTILS32_API time_t str2time(const std::string& datetime, const std::string& format)
{
    time_t t = DateUtils::str2time_t(datetime, format);
    return t;
}

/********************   Add End     *************************/

错误信息:

错误

1 错误 LNK2019:未解析的外部符号"公共:静态" __int64 __cdecl DateUtils::str2time_t(class std::basic_string,class std::分配器> 常量 &,类标准::basic_string,类标准::分配器> 常量 &)" (?str2time_t@DateUtils@@SA_JABV?$basic_string@DU?$char_traits@D@D@std@@V?$allocator@D@2@@std@@0@Z) 在函数"__int64 __cdecl str2time(class 标准::basic_string,类 std::分配器> 常量 &,类标准::basic_string,类标准::分配器> 常量 &)" (?str2time@@YA_JABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) D:\visual 演播室 2013\Projects\32bit\ForexUtils32\ForexUtils32\ForexUtils32.obj ForexUtils32

如何修复此错误?请帮帮我(我不太擅长英语。谢谢)

函数定义的第一行

time_t str2time_t(const string& datetimeIn, const string& formatIn) {

必须

time_t DateUtils::str2time_t(const string& datetimeIn, const string& formatIn) {

(添加成员函数所属的类名)