How to compile the Botan crypto library as a static lib in VC++?
-
13-09-2019 - |
Question
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
Solution
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 { ...
OTHER TIPS
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
__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.