I have a problem with VSC. I started to use it recently and well I have 1 issue with it. My project has multiple folders, those folder just contain .h and .c files, but sometimes I need that .c file from one folder would read functions from .h file from another folder, and well when I include .h file, compiler can't find it. example bellow:
the only thing that works is by including full path to that file:
#include "C:/Users/Name/Desktop/Project/Project_dir/components/configurations/I2C_master.h"
Is this normal for VSC or I don't know how to use linker?
I think your problem here is that you're writing the file path as if the two were located in the same directory.
If you are referencing a file from another directory you should write the relative path like this:
#include "../configurations/I2C_master.h"
Related
I'm pretty new to coding in c, but I have sample code that I imported into the eclipse console. However, when I go to build the project I run into various errors. All of these errors are because a code that I have in one folder is not able to access code in another folder. For example my main function is located in project>src>main.c but is not able to access the project.h file located in project>headers>project.h. I am also no able to access code directly above in the hierarchy either. For example, my project>src>compiler>comp.h is not able to access project>src>calc.h file. Is there a way I can instruct the code to find it? I have tried using #include "../src/calc.h" in my comp.h file but I still get the error message "No such file or directory." Any suggestions would be very helpful.
Header files can be tricky to include, it depends where you are compiling.
Try to compile like this :
gcc -o myBinary <your .c files> -I./your/path/to.h (it will link your .h files at the compilation state)
The best idea would be to create a Makefile and configure it to make your header files works in every files of your project, have a look at How to create a Makefile.
I am trying to import a static library based on Hierarchical Matrices (H2Lib). The folder contains a make file which compiles the library files, examples and tests into a single .a file. I have referred to tutorials on creating and using static libraries in C using archiver command line in Linux but this does not create a header file, which I had to create manually while working out the tutorial. The H2Lib has multiple files and it would be difficult and time consuming to create a header file manually for this. I am not sure if I am missing something here or doing something wrong; I am new to the concept of libraries in C. Can some one please help me on how to use this library in C?
P.S: git repository link for H2Lib: https://github.com/H2Lib/H2Lib/tree/master
You are not supposed to write the header files yourself. Somewhere on the folder where the library is defined there should be a directory with multiple .h files (the headers) (it's usually named include).
What you need to do is include them into your project. You do this by appending -I to the path of each folder containing the headers and then writing #include "headername.h" in your source code.
So if the headers are in dir/include, you'd do:
gcc yourfiles.c <flags> output.o -I dir/include
I have a large C project, with multiple directories and subdirectories, that I'm trying to document with Doxygen version 1.7.6.1-2ubuntu1.
My problem is that the project has a file (string.h) which Doxygen is confusing with the system library include file of the same name. In the project code, the project file is included with #include "lib/string.h" and the system file is included with #include <string.h>.
However Doxygen always references the project include file, regardless of which of the two #include forms is used. (And since the project string.h happens to include the system string.h, Doxygen actually shows a self-referential dependency in the dependency graph!)
How can I configure Doxygen to take notice of whether #include "..." or #include <...> has been used, and not match the project file in the latter case? It's not a practical proposition to rename the project file and change all of the other files that use it.
I have done the following:
Added the path to my include folder under Paths and Symbols->includes tab
The header file now appear in my project folder under includes
The #include files no longer give errors as the project can see the .h files that it needs
After build I get the following error:
fatal error: services.h: No such file or directory
make:*[filename]Error 1
My .c source file now complains that it cant see the include file. How do I fix this?
In Eclipse import a new make file project. Then link the appropriate libraries.
i want to recompile my include files of my project,which includes some header files and .c source files which are files for my Ethetnet driver. Now i want some change in one of my included source file. but when i change and build or rebuild my project, the change in the include .c source file does occur in the final output binary. that means my project taking previously compiled included .o files. So how can i recompile my all include files of the project so that change occur in final output binary.
Thanks in advance.
CMIIW but AFAIK it depends on your compiler (which I guess is gcc), dependency analysis against included files may be done or not, and in gcc case it does NOT do it. It only compares .c against its corresponding .o, so you have to force rebuilding when you change the include file. There perhaps certain compiler options you can use, but I don't know for it.
EDIT:
Just found a similar question: How can I have a Makefile automatically rebuild source files that include a modified header file? (In C/C++)
If you are indeed including the right file (the ones that you have modified, not some with same name from some other directory) then cleaning a project and rebuilding it should help. Just select a project in project explorer, right click, do "clean project", then build it...