在多个文件中使用函数时出现 DLL 库错误
DLL library errors when using functions in multiple files
我正在制作库,以便在多个游戏中使用,这样我就不必复制代码。在此示例中,我的主程序是main.cpp
,另外两个文件是我的库。一切都正确链接。
当我在Common Functions Library.h
中的所有函数都在前面static
时,我得到错误:static function 'std::string common::joinAll(std::vector<std::string,std::allocator<_Ty>>)' declared but not defined (Error C2129)
来自main.cpp
(即使函数在Common Functions Library.h/.cpp
中),它说行号比整个程序中的多一个,这很奇怪。
因此,为了解决此问题,我发现网上有人说我需要用inline
替换static
,所以我再次尝试并得到此错误:cannot open file 'Common Functions Library.lib' (Error LNK1104)
然后我尝试将所有函数设置回static
,然后在main.cpp
中注释掉#include "Cubes Library.h"
,这不再给我其他错误,而是与立方体库相关的东西(显然)。但是,这在第 65 行停止,之后导致错误的函数说它们没有定义。我不知道出了什么问题,但感谢您的任何帮助:)
Code:
主.cpp
#include "Common Functions Library.h"
#include "Cubes Library.h"
// Using functions from `Common Functions Library`
公共函数库.cpp(DLL 的一部分)
#include "Common Functions Library.h"
namespace common
{
// Functions
}
多维数据集库.cpp(DLL 的一部分)
#include "Cubes Library.h"
#include "Common Functions Library.h"
如果您将inline
放在所有函数的前面并在标头中定义,则不需要.cpp
文件,因此不需要.lib
。
我也在你的Common Functions Library.h
中看到namespace common
.因此,不要忘记在main.cpp
中使用类之前,将using namespace common;
放在您的main.cpp
或前缀common::
中。
- 错误:当我从"WinDbg"打开可执行文件时,找不到符号文件。默认导出 ntdll 的符号.dll
- 发生此错误:在0x0F2BFB7C(基于.dll)时引发异常 尝试更改大小是问题吗?
- 在Embarcadero C++ Builder中生成的DLL未解决的外部链接错误
- 链接库错误 c/缺少 dll/错误版本?
- Python - 从 c++ DLL 错误打印值
- C++ 动态加载 DLL 错误
- 生成 DLL 错误
- 从服务器下载DLL-不是有效的DLL(错误)
- Windows 8上的.exe文件中的MSVCR90.dll错误 - 应用程序无法正确启动(0xc000007b)
- Expat XML解析器(静态链接,DLL错误(缺少Define?)
- openCV_FFMPEG **.opencv 2.4.11中的dll错误,用于IP摄像机访问
- 如果实际导出"ordinal N not found in DLL"错误,可能导致什么原因?
- 为什么我得到的信息不可用,没有加载符号 d3d11.dll错误
- Visual Studio c++ MSVCR100.dll错误运行时
- dll错误:试图读取或写入受保护的内存
- 如何修复msvcp120 .dll错误Visual Studio 2015
- c#中无法加载64位dll错误
- Qt释放DLL错误
- 错误:无法加载dll.错误值193
- 启动 MinGW 编译的 exe 时缺少 libgcc_s_dw2-1.dll 错误