Quantcast

Including a header file fails

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Including a header file fails

Enrique Izaguirre
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?

Best Regards

Enrique

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Including a header file fails

Andreas Pakulat-2
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Including a header file fails

Enrique Izaguirre
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 <[hidden email]> 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


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Including a header file fails

John Drescher-2
> 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?
>

You do not link header files. You link source files. Why are you not
specifying your source files on the target_link_libararies() line?

John
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Including a header file fails

John Drescher-2
On Tue, Mar 1, 2011 at 2:15 PM, Enrique Izaguirre
<[hidden email]> wrote:

> Sorry, I didn't explain correctly.
>
> All the source files are in variable ${hostFiles}
> and I generated and executable using add_executable (myprj ${hostFiles})
> now I need to add the w32api folder from Windows, which has header files
> called from one of the source files contained in ${hostFiles} and are
> located in
>
> ${MYPRJ_SOURCE_DIR}/../../../usr/include/w32api
>
> How can I do this?
>

You add the appropriate

include_directories()

command in CMake. If that header requires linking to a Microsoft
library then you do add the Microsoft library to the
target_link_libraries not the header file.

John
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Including a header file fails

Enrique Izaguirre
Hello again,

I tried several ways but I cannot make it work. The only thing I need to do is to add a folder which contains a windows header file, in order that it be included in the build.
There must be a simple way to do it. Could you help?
Maybe if you have an example or something similar.

Thanks

Enrique



On Tue, Mar 1, 2011 at 1:20 PM, Enrique Izaguirre <[hidden email]> wrote:
Thank you very much. I'll try that.

Best Regards

Enrique


On Tue, Mar 1, 2011 at 1:18 PM, John Drescher <[hidden email]> wrote:
On Tue, Mar 1, 2011 at 2:15 PM, Enrique Izaguirre
<[hidden email]> wrote:
> Sorry, I didn't explain correctly.
>
> All the source files are in variable ${hostFiles}
> and I generated and executable using add_executable (myprj ${hostFiles})
> now I need to add the w32api folder from Windows, which has header files
> called from one of the source files contained in ${hostFiles} and are
> located in
>
> ${MYPRJ_SOURCE_DIR}/../../../usr/include/w32api
>
> How can I do this?
>

You add the appropriate

include_directories()

command in CMake. If that header requires linking to a Microsoft
library then you do add the Microsoft library to the
target_link_libraries not the header file.

John



_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Including a header file fails

Andreas Pakulat-2
On 01.03.11 14:58:15, Enrique Izaguirre wrote:
> I tried several ways but I cannot make it work. The only thing I need to do
> is to add a folder which contains a windows header file, in order that it be
> included in the build.
> There must be a simple way to do it. Could you help?

Header files are not included into the build, they are included in a cpp
source file and that cpp file is then added to the build into an
add_executable call. Once you have that and if it gives you errors, post
the complete error messages here.

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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Including a header file fails

Enrique Izaguirre
Hello,

I have a program called fastboot.c which #includes util_windows.h which #includes windows.h which finally #includes winbase.h where all the constants are defined. The errors I get are because the Makefile I got from CMake, doesn't find the constants, as shown:

/host/fastboot.h:101: warning: ISO C does not allow extra `;' outside of a functi
/host/fastboot.c:93: error: `NOPARITY' undeclared here (not in a function)
/host/fastboot.c:112: error: `NOPARITY' undeclared here (not in a function)
/host/fastboot.c:112: error: initializer element is not constant
/host/fastboot.c:112: error: (near initialization for `parity_names[0].value')
/host/fastboot.c:112: error: initializer element is not constant
/host/fastboot.c:112: error: (near initialization for `parity_names[0]')
/host/fastboot.c:113: error: `ODDPARITY' undeclared here (not in a function)
/host/fastboot.c:113: error: initializer element is not constant
/host/fastboot.c:113: error: (near initialization for `parity_names[1].value')
/host/fastboot.c:113: error: initializer element is not constant
/host/fastboot.c:113: error: (near initialization for `parity_names[1]')
/host/fastboot.c:114: error: `EVENPARITY' undeclared here (not in a function)
/host/fastboot.c:114: error: initializer element is not constant
/host/fastboot.c:114: error: (near initialization for `parity_names[2].value')
/host/fastboot.c:114: error: initializer element is not constant
/host/fastboot.c:114: error: (near initialization for `parity_names[2]')
/host/fastboot.c:115: error: `MARKPARITY' undeclared here (not in a function)
/host/fastboot.c:115: error: initializer element is not constant
/host/fastboot.c:115: error: (near initialization for `parity_names[3].value')
/host/fastboot.c:115: error: initializer element is not constant
/host/fastboot.c:115: error: (near initialization for `parity_names[3]')
/host/fastboot.c:116: error: `SPACEPARITY' undeclared here (not in a function)
/host/fastboot.c:116: error: initializer element is not constant
/host/fastboot.c:116: error: (near initialization for `parity_names[4].value')
/host/fastboot.c:116: error: initializer element is not constant
/host/fastboot.c:116: error: (near initialization for `parity_names[4]')
/host/fastboot.c:118: warning: missing braces around initializer
/host/fastboot.c:118: warning: (near initialization for `parity_names[5]')
/host/fastboot.c:118: error: initializer element is not constant
/host/fastboot.c:118: error: (near initialization for `parity_names[5]')
/host/fastboot.c: In function `find_named_value':
/host/fastboot.c:125: warning: implicit declaration of function `stricmp'
/host/fastboot.c: In function `open_device_callback':
/host/fastboot.c:302: warning: implicit declaration of function `sleepms'
/host/fastboot.c: In function `open_device':
/host/fastboot.c:313: warning: unused variable `timeremaining'
/host/fastboot.c: In function `usage':
/host/fastboot.c:382: warning: string length `2787' is greater than the length `5
upport
/host/fastboot.c: In function `offset_and_chip_name':
/host/fastboot.c:729: warning: unused variable `addr'
/host/fastboot.c: In function `arg':
/host/fastboot.c:845: error: `EVENPARITY' undeclared (first use in this function)
/host/fastboot.c:845: error: (Each undeclared identifier is reported only once
/host/fastboot.c:845: error: for each function it appears in.)
/host/fastboot.c:848: error: `NOPARITY' undeclared (first use in this function)


All those constants as mentioned are in winbase.h

how can I say CMake where to look? I used include_directories ( ) and it didn't work.
Also:  util_windows.h is in the same directory as fastboot.c
windows.h and winbase.h are in
    ${MYPRJ_SOURCE_DIR}/../../../usr/include/w32api

which is the one I tried to include inside include_directories ( )

Thanks a lot

Enrique

On Tue, Mar 1, 2011 at 5:03 PM, Andreas Pakulat <[hidden email]> wrote:
On 01.03.11 14:58:15, Enrique Izaguirre wrote:
> I tried several ways but I cannot make it work. The only thing I need to do
> is to add a folder which contains a windows header file, in order that it be
> included in the build.
> There must be a simple way to do it. Could you help?

Header files are not included into the build, they are included in a cpp
source file and that cpp file is then added to the build into an
add_executable call. Once you have that and if it gives you errors, post
the complete error messages here.

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


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Including a header file fails

Michael Jackson
Note that your error does not say the compiler could NOT find winbase.h, it is saying that it does not have a definition for those constants. Do you have #define WIN_LEAN_AND_MEAN or something like that somewhere in your code or is there another define that is causing the compiler to skip over those definitions?
___________________________________________________________
Mike Jackson                      www.bluequartz.net


On Mar 1, 2011, at 3:34 PM, Enrique Izaguirre wrote:

> Hello,
>
> I have a program called fastboot.c which #includes util_windows.h which #includes windows.h which finally #includes winbase.h where all the constants are defined. The errors I get are because the Makefile I got from CMake, doesn't find the constants, as shown:
>
> /host/fastboot.h:101: warning: ISO C does not allow extra `;' outside of a functi
> /host/fastboot.c:93: error: `NOPARITY' undeclared here (not in a function)
> /host/fastboot.c:112: error: `NOPARITY' undeclared here (not in a function)
> /host/fastboot.c:112: error: initializer element is not constant
> /host/fastboot.c:112: error: (near initialization for `parity_names[0].value')
> /host/fastboot.c:112: error: initializer element is not constant
> /host/fastboot.c:112: error: (near initialization for `parity_names[0]')
> /host/fastboot.c:113: error: `ODDPARITY' undeclared here (not in a function)
> /host/fastboot.c:113: error: initializer element is not constant
> /host/fastboot.c:113: error: (near initialization for `parity_names[1].value')
> /host/fastboot.c:113: error: initializer element is not constant
> /host/fastboot.c:113: error: (near initialization for `parity_names[1]')
> /host/fastboot.c:114: error: `EVENPARITY' undeclared here (not in a function)
> /host/fastboot.c:114: error: initializer element is not constant
> /host/fastboot.c:114: error: (near initialization for `parity_names[2].value')
> /host/fastboot.c:114: error: initializer element is not constant
> /host/fastboot.c:114: error: (near initialization for `parity_names[2]')
> /host/fastboot.c:115: error: `MARKPARITY' undeclared here (not in a function)
> /host/fastboot.c:115: error: initializer element is not constant
> /host/fastboot.c:115: error: (near initialization for `parity_names[3].value')
> /host/fastboot.c:115: error: initializer element is not constant
> /host/fastboot.c:115: error: (near initialization for `parity_names[3]')
> /host/fastboot.c:116: error: `SPACEPARITY' undeclared here (not in a function)
> /host/fastboot.c:116: error: initializer element is not constant
> /host/fastboot.c:116: error: (near initialization for `parity_names[4].value')
> /host/fastboot.c:116: error: initializer element is not constant
> /host/fastboot.c:116: error: (near initialization for `parity_names[4]')
> /host/fastboot.c:118: warning: missing braces around initializer
> /host/fastboot.c:118: warning: (near initialization for `parity_names[5]')
> /host/fastboot.c:118: error: initializer element is not constant
> /host/fastboot.c:118: error: (near initialization for `parity_names[5]')
> /host/fastboot.c: In function `find_named_value':
> /host/fastboot.c:125: warning: implicit declaration of function `stricmp'
> /host/fastboot.c: In function `open_device_callback':
> /host/fastboot.c:302: warning: implicit declaration of function `sleepms'
> /host/fastboot.c: In function `open_device':
> /host/fastboot.c:313: warning: unused variable `timeremaining'
> /host/fastboot.c: In function `usage':
> /host/fastboot.c:382: warning: string length `2787' is greater than the length `5
> upport
> /host/fastboot.c: In function `offset_and_chip_name':
> /host/fastboot.c:729: warning: unused variable `addr'
> /host/fastboot.c: In function `arg':
> /host/fastboot.c:845: error: `EVENPARITY' undeclared (first use in this function)
> /host/fastboot.c:845: error: (Each undeclared identifier is reported only once
> /host/fastboot.c:845: error: for each function it appears in.)
> /host/fastboot.c:848: error: `NOPARITY' undeclared (first use in this function)
>
>
> All those constants as mentioned are in winbase.h
>
> how can I say CMake where to look? I used include_directories ( ) and it didn't work.
> Also:  util_windows.h is in the same directory as fastboot.c
> windows.h and winbase.h are in
>     ${MYPRJ_SOURCE_DIR}/../../../usr/include/w32api
>
> which is the one I tried to include inside include_directories ( )
>
> Thanks a lot
>
> Enrique
>
> On Tue, Mar 1, 2011 at 5:03 PM, Andreas Pakulat <[hidden email]> wrote:
> On 01.03.11 14:58:15, Enrique Izaguirre wrote:
> > I tried several ways but I cannot make it work. The only thing I need to do
> > is to add a folder which contains a windows header file, in order that it be
> > included in the build.
> > There must be a simple way to do it. Could you help?
>
> Header files are not included into the build, they are included in a cpp
> source file and that cpp file is then added to the build into an
> add_executable call. Once you have that and if it gives you errors, post
> the complete error messages here.
>
> 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
>
> _______________________________________________
> 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

_______________________________________________
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
Loading...