如何在VC中将Botan加密库编译为静态库?

发布于 2024-07-23 11:46:03 字数 1544 浏览 4 评论 0原文

我在 Visual C++ 中将 Botan 编译为静态库非常不成功。 build.h 文件包含以下代码:

#ifndef BOTAN_DLL
  #define BOTAN_DLL __declspec(dllexport)
#endif

然后,该宏几乎出现在 Botan 代码库中的任何地方,如下所示:

class BOTAN_DLL AutoSeeded_RNG : public RandomNumberGenerator

我的理解来自 上一个问题是,您所需要做的就是定义不带值的 BOTAN_DLL,并且它应该编译为静态库就可以了。 然而,这样做会导致大量的构建错误,例如“缺少标签名称”。 有人知道怎么做吗?

编辑:以下是将 /D "BOTAN_DLL" 添加到 makefile 所导致的错误示例:

        cl.exe /Ibuild\include /O2  /EHsc /GR /D_CONSOLE /D "BOTAN_DLL"  /nologo
 /c src\checksum\adler32\adler32.cpp /Fobuild\lib\adler32.obj
adler32.cpp
build\include\botan/allocate.h(19) : error C2332: 'class' : missing tag name
build\include\botan/allocate.h(19) : error C2143: syntax error : missing ';' bef
ore 'constant'
build\include\botan/allocate.h(19) : error C2059: syntax error : 'constant'
build\include\botan/allocate.h(20) : error C2143: syntax error : missing ';' bef
ore '{'
build\include\botan/allocate.h(20) : error C2447: '{' : missing function header
(old-style formal list?)
build\include\botan/secmem.h(229) : error C2143: syntax error : missing ';' befo
re '*'
        build\include\botan/secmem.h(230) : see reference to class template inst
antiation 'Botan::MemoryRegion<T>' being compiled
build\include\botan/secmem.h(229) : error C4430: missing type specifier - int as
sumed. Note: C++ does not support default-int

I've been extremely unsuccessful in compiling Botan as a static library in Visual C++. The build.h file contains the following code:

#ifndef BOTAN_DLL
  #define BOTAN_DLL __declspec(dllexport)
#endif

This macro then shows up pretty much everywhere in the Botan codebase, like this:

class BOTAN_DLL AutoSeeded_RNG : public RandomNumberGenerator

My understanding from a previous question is that all you need to do is define BOTAN_DLL without a value and it should compile as a static library just fine. However, doing so causes a huge list of build errors like "missing tag name." Anyone know how to do this?

EDIT: Here is a sample of the errors that result from adding /D "BOTAN_DLL" to the makefile:

        cl.exe /Ibuild\include /O2  /EHsc /GR /D_CONSOLE /D "BOTAN_DLL"  /nologo
 /c src\checksum\adler32\adler32.cpp /Fobuild\lib\adler32.obj
adler32.cpp
build\include\botan/allocate.h(19) : error C2332: 'class' : missing tag name
build\include\botan/allocate.h(19) : error C2143: syntax error : missing ';' bef
ore 'constant'
build\include\botan/allocate.h(19) : error C2059: syntax error : 'constant'
build\include\botan/allocate.h(20) : error C2143: syntax error : missing ';' bef
ore '{'
build\include\botan/allocate.h(20) : error C2447: '{' : missing function header
(old-style formal list?)
build\include\botan/secmem.h(229) : error C2143: syntax error : missing ';' befo
re '*'
        build\include\botan/secmem.h(230) : see reference to class template inst
antiation 'Botan::MemoryRegion<T>' being compiled
build\include\botan/secmem.h(229) : error C4430: missing type specifier - int as
sumed. Note: C++ does not support default-int

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

毅然前行 2024-07-30 11:46:03

我最近需要自己构建一个静态 Botan 库,虽然这是一个相当旧的线程,但我想我会发布一个答案。 我相信“预期”的方法是使用配置选项。 如果您指定

configure.py --disable-shared

,则生成的 makefile 将构建静态 botan.lib 而不是 .dll。 它还生成包含

#ifndef BOTAN_DLL
  #define BOTAN_DLL 
#endif

I recently had the need to build a static Botan library myself, and though this is a rather old thread, I thought I would post an answer. I believe the "intended" way to do this is using a configuration option. If you specify

configure.py --disable-shared

then the generated makefile builds a static botan.lib instead of a .dll. It also generates build.h containing

#ifndef BOTAN_DLL
  #define BOTAN_DLL 
#endif
内心荒芜 2024-07-30 11:46:03

您收到的前几条错误消息是什么? 也许您忘记了头文件包含?

看来您的编译命令可能是错误的:

cl.exe /Ibuild\include /O2  /EHsc /GR /D_CONSOLE /D "BOTAN_DLL"  /nologo
 /c src\checksum\adler32\adler32.cpp /Fobuild\lib\adler32.obj

我认为您在 /D 指令 以及您定义的预处理器符号的值。 应该是这样的:

cl.exe /Ibuild\include /O2  /EHsc /GR /D_CONSOLE /DBOTAN_DLL=  /nologo
 /c src\checksum\adler32\adler32.cpp /Fobuild\lib\adler32.obj

编辑:如果你有 /DBOTAN_DLL,这相当于 /DBOTAN_DLL=1,你想使用 /DBOTAN_DLL=这不会给它带来任何关联的价值。 使用此 /DBOTAN_DLL,它将作为值 1 插入到您的代码中,并且编译器会看到错误:

class 1 Allocator { ...

What are the first few error messages you get? Maybe you have forgotten a header file include?

It looks like maybe your compilation command is wrong:

cl.exe /Ibuild\include /O2  /EHsc /GR /D_CONSOLE /D "BOTAN_DLL"  /nologo
 /c src\checksum\adler32\adler32.cpp /Fobuild\lib\adler32.obj

I think you incorrectly have a space between the /D directive and the value of the preprocessor symbol you are defining. It should be this:

cl.exe /Ibuild\include /O2  /EHsc /GR /D_CONSOLE /DBOTAN_DLL=  /nologo
 /c src\checksum\adler32\adler32.cpp /Fobuild\lib\adler32.obj

EDIT: if you have /DBOTAN_DLL, this is equivalent to /DBOTAN_DLL=1, you want to use /DBOTAN_DLL= which will give it no associated value. With this /DBOTAN_DLL, it is inserted into your code as the value 1, and the compiler sees the error:

class 1 Allocator { ...
城歌 2024-07-30 11:46:03

__declspec(dllexport) 与编译为静态库没有任何关系。 它只是向链接器发出信号以导出特定功能。 要指示链接器构建静态库,您必须在

配置类型 | 中指定静态库 (lib)。 一般| 配置类型

项目属性对话框中的 。 如果此特定配置构建为 dll,则配置类型的更改不应导致错误。

__declspec(dllexport) doesn't have anything to do with compiling as a static library. It just signals linker to export specific functionality. To instruct linker to build a static library you must specify Static Library (lib) in

Configuration Type | General | Configuration Type

in project properties dialog. If this particular configuration builds as a dll change of configuration type is not supposed to cause errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文