3

我在将 Botan 编译为 Visual C++ 中的静态库方面非常不成功。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
4

3 回答 3

4

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

configure.py --disable-shared

然后生成的 makefile 构建一个静态 botan.lib 而不是 .dll。它还生成 build.h 包含

#ifndef BOTAN_DLL
  #define BOTAN_DLL 
#endif
于 2011-06-27T20:44:59.680 回答
0

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

配置类型 | 一般 | 配置类型

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

于 2009-06-15T10:06:58.123 回答
0

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

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

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=它不会给它任何关联的值。使用 this /DBOTAN_DLL,它将作为值 1 插入到您的代码中,编译器会看到错误:

class 1 Allocator { ...
于 2009-06-15T10:04:49.283 回答