Small #include issue

Hello, maybe someone can explain me where am I wrong.

First, worth mentioning im running MSVC++.
2nd: i successfully added zlib to my project, as many of you know - zlib can be added both by using compiled .dll as well as by adding its source.

Now - i want to give the user choice : to use precompiled dll or to compile into the project. So, i added the following piece of code :

#ifdef _EXT_ZLIB_ON
#include <zlib.h>
#pragma comment(lib, "zdll.lib")
#else
#include "zlib.h"
#endif

The problem is it will use the zlib source included inside my proj. anyway and compile it into my exec. , only when i remove the zlib source and recompile the proj. i can make it use dll.

Ideas?

Thanks.
[773 byte] By [portnov] at [2007-11-20 0:16:37]
# 1 Re: Small #include issue
Your problem cannot be solved in code or headers only. It's a project setup problem. If you include the source of zlib in your project then it will be compiled and linked.
Guess you have to setup different project targets, one that uses the source and another that uses the dll.
What you are trying to do in the code is fine, one target defines the symbol _EXT_ZLIB_ON the other one doesn't.
Kurt
ZuK at 2007-11-9 1:06:05 >
# 2 Re: Small #include issue
Thank you,

Looks like it's small MSVC++ issue, since i compiled my proj. flawlessly using only #definces under GCC from command line.

I'm sure there is an "ignore" option for files under vc++ , i just cannot find it ;-)
portnov at 2007-11-9 1:07:07 >
# 3 Re: Small #include issue
I don't know how zlib works, but one option may be to compile the zlib project as both a DLL and as a static library. Then instead of including zlibs source code in your 'main' project you either link with zlibs DLLs import library or static library.

Something like:

#ifdef _EXT_ZLIB_ON

#include <z_dll.h>
#pragma comment(lib, "z_dll.lib")
#else
#include <z_static.h>
#pragma comment(lib, "z_static.lib");
#endif

I'm sure there is an "ignore" option for files under vc++ , i just cannot find it ;-)Right-click the file in the solution explorer and choose Properties. Then take a look at Configuration Properties - General - Exclude From Build.

- petter
wildfrog at 2007-11-9 1:08:06 >
# 4 Re: Small #include issue
.
Looks like it's small MSVC++ issue, since i compiled my proj. flawlessly using only #definces under GCC from command line.
Guess you used differend commandline options for the different builds.
That's the same as setting up different project-targets.
Kurt
ZuK at 2007-11-9 1:09:07 >
# 5 Re: Small #include issue
I don't know how zlib works, but one option may be to compile the zlib project as both a DLL and as a static library. Then instead of including zlibs source code in your 'main' project you either link with zlibs DLLs import library or static library.

Something like:

#ifdef _EXT_ZLIB_ON

#include <z_dll.h>
#pragma comment(lib, "z_dll.lib")
#else
#include <z_static.h>
#pragma comment(lib, "z_static.lib");
#endif

Right-click the file in the solution explorer and choose Properties. Then take a look at Configuration Properties - General - Exclude From Build.

- petter

Precompiling zlib source to .lib can be an option, Thank you...
portnov at 2007-11-9 1:10:06 >