karthick
karthick

Reputation: 12176

C compilation problem

I am learning how to use cygwin for alchemy. I created a test library celconv.h which is there inside the folder celconv. I want to use that header file in my c code.

When i use #include <celconv/celconv.h> the compiler gives an error "No such file or directory"

i compile the code like this:

gcc -c test.c

Test.c inside a folder named test

#include <stdio.h>
#include <celconv/celconv.h>

int main()
{
    float UserInput;

    printf("Enter a temperature in celsius to convert to  fahrenheit:");
    scanf("%f",&UserInput);
    celconvert(UserInput);

    return 0;
}

celconv.h inside a folder celconv which is inside test folder:

extern void celconv(float Cel);

celconv.c:

#include<stdio.h>
#include"celconv.h"

void celconvert(float Cel)
{

    float Fah;

    Fah = Cel * 9/5 + 32;
    printf("%f",Fah);
}

Upvotes: 0

Views: 594

Answers (3)

Sergei Tachenov
Sergei Tachenov

Reputation: 24919

If the "celconv" directory is in the current directory, the best way is probably use #include "celconv/celconv.h" syntax. If it is somewhere else, then do this:

gcc -I/path/to/wherever/celconv/directory/is -c test.c

Note that it's not the path to the celconv directory itself, but to the containing directory!

As mentioned in the comment, this approach will work for the current directory too if you don't want to use "celconv/celconv.h" for whatever reason:

gcc -I. -c test.c

Upvotes: 2

Simon Richter
Simon Richter

Reputation: 29618

Include files in the local directory need to be referenced using the #include "file.h" syntax. The angle brackets do not look into the current directory.

Upvotes: 1

BlackBear
BlackBear

Reputation: 22989

Is the path you are giving correct? Be careful about using < > and " ". The first tells the compiler "search for include files in your include folder", while the second says "look into source files directory".

Upvotes: 2

Related Questions