Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Header files linked to from header file not found.

I have a problem with Nvidia's OpenCl/Cuda framework, but I think it is a gcc linking issue.

The opencl_hello_world.c example file uses following header file:

#include "../OpenCL/common/inc/CL/opencl.h"

with opencl.h using these header files:

#include <../OpenCL/common/inc/CL/cl.h>
#include <../OpenCL/common/inc/CL/cl_gl.h>
#include <../OpenCL/common/inc/CL/cl_gl_ext.h>
#include <../OpenCL/common/inc/CL/cl_ext.h>

So all the header files are in the same folder.

When I then compile with gcc opencl_hello_world.c -std=c99 -lOpenCL I get following error messages:

error: ../OpenCL/common/inc/CL/cl.h: No such file or directory
error: ../OpenCL/common/inc/CL/cl_gl.h: No such file or directory
...

Even though cl.h and the other header files are located in this folder.

Having searched SO, I then changed the includes in the opencl.h to

   #include "cl.h"
   #include "cl_gl.h"

how I have read here: gcc Can't Find a Included Header.

But messing around with the frameworks header files does not seem like the way to go? What would be the proper way to handle this problem?

like image 359
Framester Avatar asked Sep 08 '10 11:09

Framester


People also ask

Can you include header files in header files?

Yes, this will work. Note, however, that if you include a lot of headers in this file and don't need all of them in each of your source files, it will likely increase your compilation time.

How do I add a header file path in Makefile?

Including Header file from Different Directories If you have put the header files in different directories and you are running make in a different directory, then it is required to provide the path of header files. This can be done using -I option in makefile. Assuming that functions.

What happens if we include a header file twice?

If a header file happens to be included twice, the compiler will process its contents twice. This is very likely to cause an error, e.g. when the compiler sees the same structure definition twice. Even if it does not, it will certainly waste time.


1 Answers

You're using both #include "" form and #include <>, which don't search in the same paths. "" is local to your project, and the -i command line specified to gcc, <> is the 'system' path specified by -I to gcc.

You probably need to set the include path with -Ipath/to/includes in gcc's command line.

like image 109
jv42 Avatar answered Oct 10 '22 04:10

jv42