3

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
Community
  • 1
  • 1

3 Answers3

4

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
g3isme
  • 41
  • 2
0

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 { ...
1800 INFORMATION
  • 131,367
  • 29
  • 160
  • 239
  • What is on line 19 of allocate.h here? build\include\botan/allocate.h(19) : error C2332: 'class' : missing tag name – 1800 INFORMATION Jun 15 '09 at 10:27
  • It's simply the class definition, like in the original post: class BOTAN_DLL Allocator –  Jun 15 '09 at 10:30
  • It doesn't appear to make a difference whether I put /D "BOTAN_DLL" or /DBOTAN_DLL, the same list of errors comes up. –  Jun 15 '09 at 10:39
  • Sorry yes I made a mistake - you need to have /DBOTAN_DLL= (note the "=" symbol) – 1800 INFORMATION Jun 15 '09 at 10:40
  • Thanks, it compiled this time but do I need to add this preprocessor definition to the project in VC++ that is using the library? Simply adding "#define BOTAN_DLL" in that project doesn't seem to work. –  Jun 15 '09 at 10:50
  • For example, I get a lot of warnings about such and such "needs to have dll-interface". –  Jun 15 '09 at 11:30
  • Roughly speaking, if you are wanting to use the library static linked, then the "dllexport" and "dllimport" directives should not be used at all - so you really need to make sure that symbol is defined correctly so that the directive is not applied – 1800 INFORMATION Jun 15 '09 at 20:48
  • Right, I fixed that problem by adding /DBOTAN_DLL= to my VC++ project as well. Those warnings no longer appear, but the compile still fails with 62 errors, mainly syntax errors in the botan header files, such as: dl_group.h(51): error C2143: syntax error : missing '}' before '('. –  Jun 15 '09 at 21:40
  • Line 51 in that file, by the way, is simply a line in the following enumeration: enum Format { ANSI_X9_42, ANSI_X9_57, PKCS_3, DSA_PARAMETERS = ANSI_X9_57, DH_PARAMETERS = ANSI_X9_42, X942_DH_PARAMETERS = ANSI_X9_42, PKCS3_DH_PARAMETERS = PKCS_3 }; –  Jun 15 '09 at 21:42
  • Sometimes the error is caused by an error flowing over from the previous line, what is on the previous line? – 1800 INFORMATION Jun 15 '09 at 22:12
  • Sorry for the late reply, here is the file: http://files.randombit.net/botan/doxygen/html/dl__group_8h-source.html –  Jun 16 '09 at 00:59
  • I can't see anything obvious wrong with that file. Is the line 51 the first error in the output? – 1800 INFORMATION Jun 16 '09 at 01:09
  • That's the thing, I don't think there is actually is a syntax error, as this library is widely used. I think something else is causing it to show up. Here is all of my output: http://pastebin.com/m52ec634 –  Jun 16 '09 at 01:29
  • My guess is you have some other preprocessor symbols which are interfering with the build. I would add the /P (http://msdn.microsoft.com/en-us/library/8z9z0bx6(VS.80).aspx) command line option to your build - this means that the compiler will output the full preprocessed output to a file with the same name but ending in ".i" - you can then open that file and see what the file looks like around the bit that is causing the error – 1800 INFORMATION Jun 16 '09 at 01:49
0

__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.

Oleg Zhylin
  • 1,290
  • 12
  • 18
  • I'm not actually building the library in VC++; it's build process is too complex for that. I am building it with nmake using the makefile generated by Botan's configure.pl, then attempting to link my VC++ project to it. –  Jun 15 '09 at 10:19