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

时间:2016-03-13 06:27:35

标签: c++ static lnk2019

我收到此错误,但我不知道如何修复它。 我正在使用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:未解析的外部符号“public:static   __int64 __cdecl DateUtils :: str2time_t(class std :: basic_string,class   std :: allocator&gt; const&amp;,类std :: basic_string,class std :: allocator&gt; const&amp;)“   (?str_time_t @DateUtils @@ SA_JABV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@ 0 @ Z)在函数“__int64 __cdecl str2time(class)中引用   的std :: basic_string的,类   std :: allocator&gt; const&amp;,类std :: basic_string,class std :: allocator&gt; const&amp;)“   (?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

我该如何解决这个错误?请帮帮我(我不太擅长英语。谢谢)

1 个答案:

答案 0 :(得分:1)

函数定义的第一行

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

必须是

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

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