对我来说,C++,MSVC/Visual Studio 2017中的一个奇怪的链接器错误; DLL隐式链接
问题描述:
下面的代码自行编译。 它生成“libtea.dll”和.lib用于链接libtea.dll与另一个对象(可执行文件或另一个DLL)对我来说,C++,MSVC/Visual Studio 2017中的一个奇怪的链接器错误; DLL隐式链接
作为一个U */Linux旧g ++用户,我真的不能在MSVC(Windows)为什么在tstring.cc文件中实现的tstring :: word :: operator()()无法在“client”项目的链接时共享(解析),而tstring类成员的其余部分所有无障碍... ??
P.S .:请不要判断太常见的名字lib“茶”......因为我喜欢喝很多茶! :)
//...
[libtea.h]
#pragma once
#ifdef TEA_EXPORTS // Well defined
#define TEA_API __declspec(dllexport) // <-- Compiling the lib
#else
#define TEA_API __declspec(dllimport) // <-- Compiling the client project
#endif
[EOF libtea.h]
// ...
[tstring.h]
#pragma once
#include <libtea.h>
#include ...
//...
class TEA_API tstring{
//...
struct word { // x64: 48 bytes;
string::iterator begin;
string::iterator end;
string operator()(); // ---> LNKC2019 ...external unresolved...
using array_t = std::vector<word>;
};
struct cword { // x64: 16 bytes;
const char* begin;
const char* end;
string operator()(); // -----> LNKC2019 ...external unresolved...
using array_t = std::vector<cword>;
};
//...
[EOF tstring.h]
Client(-test) program main:
#include <tstring.h>
//...
using namespace std;
auto main() -> int { // c++ 14 : why not ? :-)
tstring str;
str << "libtea.dll: size of tstring::word=[%d] <> std::string:[%d] <> tstring::cword[%d]\n";
str.arg(sizeof(tstring::word)).arg(sizeof(string)).arg(sizeof(tstring::cword));
cout << str();
tstring::cword::array_t words;
size_t sz = str.cwords(words, "", true);
cout << "words: " << sz << ":\n";
for (auto& w : words) {
cout << "[" << w() << "]\n"; // tstring::cword::operator()(void): cannot be resolved....LNKC2019 ...external unresolved...
}
Sleep(2000);
return 0;
}
我希望代码清楚我面对着MSVC显示... 非常感谢您对我们的关注:)
答
哦!没有! 我不知道我必须将“TEA_API”属性应用于内部结构! 客户端项目正在编译和链接。
对不起。 我学习 ....
class TEA_API tstring{
//...
struct TEA_API word{
string::iterator begin;
string::iterator end;
string operator()();
using array_t = std::vector<word>;
};
struct TEA_API cword {
const char* begin;
const char* end;
string operator()();
using array_t = std::vector<cword>;
};
//...
输出:
libtea.dll: size of tstring::word=[48] <> std::string:[40] <> tstring::cword[16]
tstring::words : token_separators:"\"'();,%<>=+-*/:.":
words: 26:
[tstring]
[.]
[dll]
[:]
[size]
[of]
[tstring]
[:]
[:]
[word]
[=]
[[48]]
[<]
[>]
[std]
[:]
[:]
[string]
[:]
[[40]]
[<]
[>]
[tstring]
[:]
[:]
[cword[16]]
你没有说明你做了什么错误? –
'#define TEA_API __declspec(dllexport) user0042
匿名邮件:LNKC2019。这是“嵌入”作为代码中的评论... :) – Bretzelus