[CMake] Including a header file fails

Enrique Izaguirre enrique.izaguirre at gmail.com
Tue Mar 1 13:54:50 EST 2011


Thank you very much for your help.

The header file is already #included in one of the source files. What I
don't know is how to link it.
Can I do it only with target_link_libraries ( ) or how?

Thanks

Enrique

On Mon, Feb 28, 2011 at 5:26 PM, Andreas Pakulat <apaku at gmx.de> wrote:

> On 28.02.11 16:55:12, Enrique Izaguirre wrote:
> > Hello,
> >
> > I am trying to include a windows header file in my build.
> > The simplest way I found is to add the following in the main
> CMakeLists.txt
> > file:
> >
> > include_directories ("${MYPRJ_SOURCE_DIR}/../../../usr/include/w32api")
> > add_library (w32api w32api/winbase.h)
> >
> > add_executable (myprj ${hostFiles})
> > target_link_libraries (myprj w32api)
> >
> >
> > I am working in Cygwin, and my project is in /home/<my-user>/myprj,
> that's
> > why I am using
> >
> >  ${MYPRJ_SOURCE_DIR}/../../../usr/include/w32api
> >
> > since "/" is the root in my cygwin system and the file I want is in
> > /usr/include/w32api
> >
> > but when running cmake I get the following error:
> >
> > CMake Error in CMakeLists.txt:
> >   Cannot find source file "winbase.h".  Tried extensions .c .C .c++ .cc
> .cpp
> >   .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx
> >
> > I have not been able to find out what is going on. Could you help please?
>
> There are several errors here:
>
> 1. you already added the w32api directory to the include-dirs, so you
> don't need it in the add_library line
> 2. you're trying to build a library from a header file
> 3. you're adding files that are not part of your source code to your
> targets
> 4. you're trying to link an executable against that header file, what
> you really want is #include the header file in your sources and link to
> whatever library provides the implementation for winbase.h
>
> If you fix 4. you won't need to fix 1-3.
>
> Andreas
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110301/feedddfc/attachment.htm>


More information about the CMake mailing list