[CMake] simple project in Visual Studio 2008

Jos.van.den.Oever at panalytical.com Jos.van.den.Oever at panalytical.com
Tue Aug 19 09:35:43 EDT 2008


"Yuri V. Timenkov" <ytimenkov at parallels.com> wrote on 08/19/2008 03:26:34 
PM:

> On Tuesday 19 August 2008 17:10:56 Jos.van.den.Oever at panalytical.com 
wrote:
> > "Yuri V. Timenkov" <ytimenkov at parallels.com> wrote on 08/19/2008 
02:05:04
> >
> > PM:
> > > Are following posts solve your problem?
> > >
> > > http://www.cmake.org/pipermail/cmake/2008-July/023099.html
> > > http://www.cmake.org/pipermail/cmake/2006-September/011100.html
> > > http://www.cmake.org/pipermail/cmake/2005-February/006080.html
> >
> > Yes they do. The tricky point was having to know that the symbol
> > ${LIBRARYNAME}_EXPORTS is set when building the library.
> > Then adding something along these lines in the header file solves the
> > problem:
> >
> > #ifdef _WIN32
> > #  ifdef testc2_EXPORTS
> > #    define WHATEVER __declspec( dllexport )
> > #  else
> > #    define WHATEVER __declspec( dllimport )
> > #  endif
> > #else
> > #  define WHATEVER
> > #endif
> >
> > WHATEVER float LibC2Func();
> >
> > So now I can get a simple project with one dll and one exe to compile, 
but
> > I still do not understand which program determines whether the .exe 
should
> > link to a .lib or a .dll. Does the Microsoft Visual Studio compiler
> > determine this or does CMake inspect the header files?
> > I find it strange that the linking command depends on the contents of 
the
> > header files. Is there a reason for this?
> This is VS tricks. Studio generates 2 files: one import library (.
> lib) and one 
> - dynamic library (.dll). gcc (and mingw family) exports all symbols by 
> default, VS doesn't export anything by default. And if your dll doesn't 
> export anything, VS simply doesn't generate import library (for example, 
if 
> you generate resource-only dll). The only thing cmake knows is when you 
using 
> VS generator, library extension to link with -- is .lib. And when you 
use 
> __declspec( dllexport ), cl.exe puts special marks in objects indicating 
that 
> this symbol should be exported or imported. Also, VS can tell linker to 
add 
> some library, as it boost does with #pragma's.
> 
> Really, this is well-known issue for VS developers ("Where is my .lib 
file??? 
> >:-("), especially if you copy project and header files and forgot 
change 
> defines. But because CMake makes migration to windows very smooth, this 
> question appears near every month in this list as cmake on VS/Windows 
newbie 
> question.

Perhaps it's a idea to add an entry to http://www.cmake.org/Wiki/CMake_FAQ 
then.
Something that says: If there is no __declspec( dllexport ) in your 
header, only a dll and no lib is generated.
CMake only tells the linker about the .lib, so if __declspec( dllexport ) 
is not there linking fails even though there is a .dll file.

Thanks,
Jos 
 
  
Jos van den Oever - SW Engineering 
 
PANalytical 
Lelyweg 1 
7602 EA Almelo 
The Netherlands 
T   +31 (0)546 528
F   +31 (0)546 534598
Jos.van.den.Oever at panalytical.com
www.PANalytical.com


 PANalytical
The Analytical X-ray Company  

The information contained in this message is confidential and may be 
legally privileged. The message is intended solely for the addressee(s). 
If you are not the intended recipient, you are hereby notified that any 
use, dissemination, or reproduction is strictly prohibited and may be 
unlawful. If you are not the intended recipient, please contact the sender 
by return e-mail and destroy all copies of the original message.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080819/123ca86c/attachment.htm>


More information about the CMake mailing list