Make / Build with geany - c

I have problem on build.
My error is something like that: "test.c" error: test.h error"
I have on source code:
#include <test.h>
How to add this on build?
To be spesific How to link this library? Can i link it through Geany?
Operating System ubuntu + Geany as compile

Follow these simple steps:
Create a directory and place your test.c and test.h in the same directory.
In C source file you should write:
#include "test.h" which will search for the header file in current directory as well as the include library path, instead of, the #include <test.h> which will search for test.h in include libraries path only.
Build as usual, using geany.

Related

C and MinGW: How do I fix my "No such file or directory" error?

I have made a python "compiler" that helps me compile my C code with gcc, for example it fetches all my header files and source files. So my cmd commmand is gcc {headers} {source} -o {build_dir}/build.exe -lgdi32 -w where {headers} is a string like -Ipath/to/headers/foo.h -Ipath/to/other/headers.foo2.h and where {source} is the same but with .c files. It seems that the compiler finds the header files, but when compiling my code it fails.
(btw I am trying to make a portable programming environment on my flash drive so python and mingw are both portable)
This is the error: fatal error: test.h: No such file or directory #include "test.h"
My project tree
I have put the third party library files into the mingw directory instead of making a custom one and then linking it in the gcc command.
The -I option takes the path to the directory containing the header files or more specifically with an argument -Ipath and a directive #include<a/b.h>, the compiler will try to look for the header file at path/a/b.h.
So you should not give it paths to header files, only to the directory or directories relative to which you use include directives.

Windows Command line c file compile error

I work with C codes using gcc compiler and Clion IDE
So, I have a src folder for .c codes and include folder of .h files which contains a bunch of #define
I include some of the .h files in my main.c programe
when I run it in my Clion project, everything work fine
but when I try to run with command line (cuz I need command arguments), it says
Fatal Error: MyFunction.h, no such file or directory MyFunction.h IS MY FILE, NOT DEFAULT library file
What I typed in the command line is $gcc C:\Users\Admin\CLionProjects\project\src\main.c
What I get is "C:\Users\Admin\CLionProjects\project\src\main.c 10: Fatal Error: MyFunction.h No such file or directory.
Then I try to change the #include <MyFunction.h> to #include "MyFunction.h", hoping it will solve the problem, but no.
Then I did a test, I call a function of another .c file in the same src folder, and use command line to run main.c, but it tells me the function is not even defined.
cmd can recognized all the default library files like stdio.h, but none of those created by me. Any idea how to solve this problem? I know it must be some kind of path error
You have to tell gcc preprocessor where to find files you want to include.
You have two kinds of header:
System headers: included with #include <header>.
Local headers: included with #include "header".
Preprocessor searchs in header search path to find system headers.
Preprocessor searchs in current directory, then in header path to find local headers.
You can add folders in header search path using -I option in gcc invocation.
So in your case, you can compile with these commands:
$gcc -I C:\Users\Admin\CLionProjects\project\include C:\Users\Admin\CLionProjects\project\src\main.c
or
$cd C:\Users\Admin\CLionProjects\project\src
$gcc -I ..\include main.c

#include "existing file" fails: no such file (C)

Compiling C with gcc.
While
#include "/absolute/path/to/my/file"
works OK,
#include "../../relative/path/to/my/file"
fails with "no such file or directory". This only happens when the file is placed outside the project directory. file has read permissions. What could be the reason?
When using the format
#include "some_file.h"
the preprocessor by default looks in the same directory as the source file, if the file is not found there, it looks in the header-file search paths.
If the header file is not in the same directory as the source file, and not in one of the directories of the preprocessors search-path, then it will not be found.
You can write relative or full paths though:
#include "../some_directory/some_file.h"
Yes, you need GCC Options for Directory Search
When using gcc and local header files you need to add an include path to your build command.
mysource.c:
#include "localfile.h"
build command:
gcc -o program mysource.c
This works as long as the header file is in the same directory as your source (where you're running the command). If your header file is in a different directory you can include with the -I option:
gcc -I../headerdir -o hello.exe hello.c
or an absoulte path:
gcc -I/home/user/myprogra/headerdir -o hello.exe hello.c

Search Path for C Code Project

I have a third party Curl project, inside there is a lib folder containing the source file,
and also a include folder, inside include folder there is a curl folder which a bunch of .h files
/lib/***.c and /lib/***.h files
/include/curl/curl.h
Inside the sources files of the /lib there are many calls to
#include <curl/curl.h>
I copy the /lib and /curl folder into my new projects. Now When I compiled there's an error on
Lexical or preprocessor error on #include <curl/curl.h>
I added the Header search path and User search path
"$(SRCROOT)/curl"
which points to /curl folder containing curl.h file.
but the project still has compile issue on
ANd I don't want to change that to just because there are too many occurrences. ANy ideas?
Use -I compilation flag to specify the include path.
e.g.
gcc -I/var/lib curl.c
If the #include is #include <curl/curl.h> then the header file will be found in directory /var/lib/curl.
Try This
gcc curl.c -I/(PATH TO HEADER FILE)
if you have any shared libraries to link then try this
gcc curl.c -I/(PATH TO HEADER FILE) -L/(path to lib)

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?
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.

Resources