- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在创建一个 DLL 并使用 CreateFastString
函数为 FastString
类提供入口点:
FastString.h
:
#define EXPORT __declspec(dllexport)
#define IMPORT __declspec(dllimport)
class FastString
{
const int m_length;
char* m_str;
public:
FastString(const char* str);
~FastString();
int Length()const;
int Find(const char* str)const;
};
extern "C" FastString* CreateFastString(const char* str);
FastString.cpp
:
#include "stdafx.h"
#include <string>
#include "FastString.h"
FastString* CreateFastString(const char* str)
{
return new FastString(str);
}
FastString::FastString(const char* str): m_length(strlen(str)),
m_str(new char[m_length+1])
{}
FastString::~FastString()
{
delete[] m_str;
}
int FastString::Length()const
{
return m_length;
}
int FastString::Find(const char* str)const
{
return 1;
}
main.cpp
:
#include "stdafx.h"
#include <iostream>
#include "FastString.h"
int _tmain(int argc, _TCHAR* argv[])
{
FastString* str = CreateFastString("Hello Dll");
std::cout<<"The length is "<<str->Length()<<std::endl;
return 0;
}
在编译过程中,出现以下错误:
TeatApp.obj : error LNK2019: unresolved external symbol _CreateFastString referenced in function _wmain
D:\MFC\FastString\Debug\TeatApp.exe : fatal error LNK1120: 1 unresolved externals
在 Linker -> Input -> Additional Dependencies
中,我提供了 .lib
文件的路径。
任何人都可以提出问题所在。提前致谢。
最佳答案
config.h
:
#define MY_DLL_EXPORT __declspec(dllexport)
#define MY_DLL_IMPORT __declspec(dllimport)
// Should be defined when MyDLL is built (more details below).
#ifdef MY_DLL_EXPORTS
#define MY_DLL_PUBLIC MY_DLL_EXPORT
#else
#define MY_DLL_PUBLIC MY_DLL_IMPORT
#endif
#define MY_DLL_PRIVATE
#ifdef __cplusplus
#define MY_DLL_FUNCTION extern "C"
#else
#define MY_DLL_FUNCTION extern
#endif
FastString.h
:
#include "config.h"
class MY_DLL_PUBLIC FastString
{
const int m_length;
char* m_str;
public:
FastString(const char* str);
~FastString();
int Length() const;
int Find(const char* str) const;
};
MY_DLL_FUNCTION FastString* MY_DLL_PUBLIC CreateFastString(const char* str);
FastString.cpp
:
#include "FastString.h"
#include "stdafx.h"
#include <string>
FastString* CreateFastString(const char* str)
{
return new FastString(str);
}
FastString::FastString(const char* str): m_length(strlen(str)),
m_str(new char[m_length+1])
{}
FastString::~FastString()
{
delete[] m_str;
}
int FastString::Length()const
{
return m_length;
}
int FastString::Find(const char* str)const
{
return 1;
}
注意:构建FastString.cpp
与 MY_DLL_EXPORTS
定义,所以所有标有MY_DLL_PUBLIC
的符号从生成的 DLL 中导出。 “已导出”,表示它们对 DLL 使用者(例如您的应用程序)可见。最佳做法是在编译期间提供此定义。例如,在 MSVC 上可以通过添加 /DMY_DLL_EXPORTS
来完成。编译器调用。
main.cpp
:
#include "stdafx.h"
#include "FastString.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
FastString* str = CreateFastString("Hello Dll");
std::cout<<"The length is "<<str->Length()<<std::endl;
return 0;
}
注意: main.cpp
是您的应用程序,它基本上是 DLL 使用者,因此,您应该不定义 MY_DLL_EXPORTS
在编译过程中,所有标有MY_DLL_PUBLIC
的符号从使用的 DLL 中导入。
如果您的 DLL 有一些私有(private)函数或类,这些函数或类对 DLL 使用者不可见,那么最好用 MY_DLL_PRIVATE
标记它们.最后,我没有看到任何 include guards 在你发布的代码中,我在我的例子中也省略了它们,但要注意你应该肯定有它们,所以如果你的真实代码中缺少它们,请不要忘记将它们添加到你所有的标题中.
关于c++ - 错误 LNK2019 : unresolved external symbol _CreateFastString referenced in function _wmain,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16527534/
我们的开发环境是这样配置的,当我们运行代码的调试版本时,它会在崩溃或 ^C 时进入 gdb。随着最近的一些更改,这种情况不再发生(退出程序而不是进入 gdb),我怀疑符号大小的增加导致了这个问题。 有
刚刚浏览了一个教程,想到了我看到的地方 first_name: 还有一个地方 :first_name 这样对吗?有什么区别? 最佳答案 哈希语法在 Ruby 1.9.2 中发生了变化,以更接近 jso
这里是一个相当抽象的问题,因为我不知道从哪里开始我自己的调查。 我有一个用 CMake 构建的 C 包,它生成 librpdb.so;我为同一个库设置了一个 Ruby Gem,它生成 rpdb.bun
我尝试使用 Symbol 创建对象键并用 Symbol.for 找到对应的值,但它不起作用: const sym = Symbol("x"); let obj = { [sym]: "val" }
这可能是一个愚蠢的问题,但我很高兴知道为什么我们使用带有一些标志的短形式的单符号和带有完整标志的双符号? 例子: 1) -h & --help 2) -f & --force 谁能解释一下原因? 最
我们希望能够在删除物理构建区域时删除符号服务器内容,symstore del 命令对事务 ID 起作用。这是未知的。 How to extract the transaction ID based o
我在一个我不太理解的小程序上遇到这个问题(我对节点红色有点陌生),代码是 var profile = msg.user.profile; var cart = profile.cart = pr
我正在尝试创建一种工资单以在控制台中打印,但我从代码中收到以下错误。很多时候它实际上只是一个错误,但我认为我没有足够的 java 知识来自己修复它。 import java.io.*; import
在 C# 项目中,我在 UnhandledException 中创建了小型转储。在我的 Dev 机器中,项目源和 bin 位于路径 K:\projects\*MYPROJECT* 下,如果我设法让它在
我正在尝试针对另一个使用 libcurl 共享库的共享库 (libtheirstuff.so) 交叉编译我自己的共享库 (libmystuff.so),但出现以下错误: libmystuff.so:
我试图遍历一个数组来检查它是否包含任何通过指定函数的项目。我通过向 Array 对象添加一个 .any() 原型(prototype)来做到这一点: Array.prototype.any = (co
除了这个 undefined symbol 错误外,一切正常: bash-3.2$ make g++ -Wall -g solvePlanningProblem.o Position.o AStarN
我 rsync 目录“Promotion”包含两台具有不同目录结构的机器之间的绝对符号链接(symbolic link)。因此绝对符号链接(symbolic link)在两台机器上都不起作用。为了使它
我有以下 JSX - What is your e-mail address? setStateForProperties(e)}
根据 SVG 的 symbol文档,我可以添加 refX/refY属性给它。 如果我理解正确,我可以使用这些属性来定义符号坐标系中的引用点,因此当我使用 引用它时元素,它将相对于该引用点(而不是默认
请解释以下有关“找不到符号”,“无法解析符号”或“找不到符号”错误的信息: 是什么意思? 什么原因可以导致它们? 程序员如何解决它们? 该问题旨在对Java中的这些常见编译错误进行全面的问答。 最佳答
请解释以下有关“找不到符号”,“无法解析符号”或“找不到符号”错误的信息: 是什么意思? 什么原因可以导致它们? 程序员如何解决它们? 该问题旨在对Java中的这些常见编译错误进行全面的问答。 最佳答
请解释以下有关“找不到符号”,“无法解析符号”或“找不到符号”错误的信息: 是什么意思? 什么原因可以导致它们? 程序员如何解决它们? 该问题旨在对Java中的这些常见编译错误进行全面的问答。 最佳答
请解释以下有关“找不到符号”,“无法解析符号”或“找不到符号”错误的信息: 是什么意思? 什么原因可以导致它们? 程序员如何解决它们? 该问题旨在对Java中的这些常见编译错误进行全面的问答。 最佳答
请解释以下有关“找不到符号”,“无法解析符号”或“找不到符号”错误的信息: 是什么意思? 什么原因可以导致它们? 程序员如何解决它们? 该问题旨在对Java中的这些常见编译错误进行全面的问答。 最佳答
我是一名优秀的程序员,十分优秀!