views:

606

answers:

2

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
+1  A: 

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
Sure, please see the newly added edit in my original post.
oskar
What is on line 19 of allocate.h here? build\include\botan/allocate.h(19) : error C2332: 'class' : missing tag name
1800 INFORMATION
It's simply the class definition, like in the original post:class BOTAN_DLL Allocator
oskar
It doesn't appear to make a difference whether I put /D "BOTAN_DLL" or /DBOTAN_DLL, the same list of errors comes up.
oskar
Sorry yes I made a mistake - you need to have /DBOTAN_DLL= (note the "=" symbol)
1800 INFORMATION
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.
oskar
For example, I get a lot of warnings about such and such "needs to have dll-interface".
oskar
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
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 '('.
oskar
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 };
oskar
Sometimes the error is caused by an error flowing over from the previous line, what is on the previous line?
1800 INFORMATION
Sorry for the late reply, here is the file: http://files.randombit.net/botan/doxygen/html/dl__group_8h-source.html
oskar
I can't see anything obvious wrong with that file. Is the line 51 the first error in the output?
1800 INFORMATION
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
oskar
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
A: 

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