views:

414

answers:

3

It's pretty easy to use a library in VC++ 2008 if you create a project for it and build it alongside the other projects in your solution, but what if the library has too complex of a build process and must be compiled separately via makefile?

My library is like that, and while I've had no problem compiling it on the command line, I have no clue what to do with the resulting header files and .lib file. I've put them all in one directory and added its path to my main project's Additional Include Directories, so it finds the header files just fine. I've also added the relevant info to Additional Library Directories and Additional Dependencies.

Perhaps there's another setting I'm forgetting to set besides these three? I'd appreciate all the help I can get. Thanks.

EDIT Here are the syntax errors I'm getting:

http://pastebin.com/m72ece684

+1  A: 

Okay, based on those errors, it has nothing to do with finding your .lib files, it's choking on the header files.

Edit:

It looks like somewhere in windows.h, there is a macro definition for X942_DH_PARAMETERS which is breaking your dl_group.h.

Instead of putting your botan headers at top, but windows.h at top, and then right before you #include the botan headers add this line:

#undef X942_DH_PARAMETERS

Or as I just discovered, that macro is defined in wincrypt.h, and if you add NOCRYPT to your preprocessor definitions it won't include that file. Since you're using a third party crypto library you probably don't need wincrypt.

Gerald
Sorry I forgot to mention I did that as well. I will modify the original post with the errors I'm receiving. Do you mean a missing preprocessor definition in my main project, or in the library I built?
oskar
I updated my answer based on your errors. If it is a preprocessor definition issue it will be with your main project.
Gerald
Is it as simple as copying over whatever preprocessor definitions I find in the makefile? The only one I see in it is /D_CONSOLE. This is the makefile botan generates in full: http://pastebin.com/m210064f3
oskar
BTW I added /DBOTAN_DLL= to the makefile in order to build it as a static library. Not sure if that makes a difference.
oskar
Hmm, actually that could be. Add BOTAN_DLL to your preprocessor definitions. If it uses that as a modifier in the class definition that could very well break it if it's not set as an empty macro.
Gerald
I actually already added it to my project's preprocessor definitions as well, the errors are still there. In C/C++ -> Command Line -> Additional Options I put in /DBOTAN_DLL=
oskar
Alright. I had a quick look at Botan, but it's obviously a different version. It's choking on dl_group.h so if you paste the contents of dl_group.h in pastebin I'll have a quick look to see if anything sticks out.
Gerald
I'm using the latest version, 1.8.2. Here's dl_group.h: http://pastebin.com/m13d73e17
oskar
BTW, it may be worth noting that if I compile it without the /DBOTAN_DLL=, it still generates a .lib file, but it's about 2 times larger and creates even more syntax errors when I try to include it in my project.
oskar
Well it seems to be breaking in the Format enumeration (line 51), but I don't see anything wrong there. The only thing I can think of that would break it there is if there is a macro conflicting with the enum names. Make sure when you're #including your botan headers in your main project that they're at the top before any other headers are included. That's about all I can think of without seeing the project itself.
Gerald
Actually I just did a little test, and that's almost certainly what it is. I made a class with that same enumeration, and if I #include <windows.h> ahead of that class it gives me the same errors, and if I remove windows.h it doesn't. So there's a macro in the windows headers that's breaking it.
Gerald
I appreciate your effort to help. I moved some includes around but even if it's at the very top, I actually get a bit more errors. If you can't think of anything else, that's fine, but here are the newest errors just in case: http://pastebin.com/m11270862
oskar
Okay, now it looks like it might be the other way around. Your Botan headers are breaking the windows headers. There's one other thing you can try. I'll add it to my answer up top.
Gerald
I'm not sure if I'm even using windows.h, it's certainly not in my code but it might be used implicitly by vc++. Should I remove that from somewhere?
oskar
Which headers are you referring to? I'm not sure I can remove any #includes without breaking botan.
oskar
Might be included in stdafx.h if you are using one. The other thing you can do is add that #undef X942_DH_PARAMETERS at the top of the dl_group.h file
Gerald
Or not at the top, but right before the namespace.
Gerald
Actually I think that definitely helped, as the only errors left seem to be about byte being defined in multiple places: http://pastebin.com/m207ff617
oskar
Actually I may have found a better solution for that. That macro is defined in wincrypt.h, which is an optional windows header. If you add NOCRYPT to your preprocessor definitions, it won't include that header.
Gerald
Are you talking about something else? byte it defined in rpcndr.h, not wincrypt.h, and it's conflicting with the byte defined in botan's types.h.
oskar
I was talking about the X942_DH_PARAMETERS issue. Since you're using a third party crypto library you probably don't need wincrypt. The byte issue is something else.
Gerald
Thank you again for your help, I'll see if I can figure out why the byte issue is suddenly coming up (since it clearly wasnt showing up in the first error log above).
oskar
It may have stopped trying to build before it got there. It always annoys me when third party libraries typedef common names like that, you can probably add a #ifndef _MSC_VER around that typedef in types.h to fix that.
Gerald
Actually I moved windows.h to the top of my main file and that error no longer appears, it actually seems to compile fine (though with many warnings), so now I'm just trying to deal with unresolved external symbol errors from the linker.
oskar
A: 

While I can't exactly say what your problem is I can offer some advice as to how to find a solution. I suggest creating a simple library that contains a single method and a single class, build it, and then try to successfully link it to your project. Once you get that done on a smaller scale, try repeating the steps with your original library.

kitchen
A: 

For msvc compiler you can add

#pragma comment(lib, "MYLIBNAME.lib")

in your header. This will automatically make the linker look for "MYLIBNAME.lib" in the "Additional Library Directories".

If no longer an error occures

  • Can't find header ...
  • Can't find MYLIBNAME.lib

the problem is probably related to some other stuff like wrong C runtime, debug release mismatch, ...

P.S.: If the lib is in the solution tree just setting the dependency on the lib, will cause VS to add the targetpath to the libfolder and the libname to the libraries.

Totonga