Hi all,
Said me please..
I have next directory, for ehample: /usr/home/iam/work. In this folder:
a2.h
abc.c
If I compile abc.c, etc. cc -o run abc.c - all ok. I know what I can be use next style, for include local modules:
- not write full path to it. But me need it. I have my private C library. And I thought, what if i write use next style:
abc.c
But if I compile it - I have:
I understand, as my (not my, C has) preprocessor use this script:
Step one: it saw 3 line [ #include loadit(a2.h) ], it search define loadit.
Step two: it rewrite line 3 to next style:
After preprocessor tries to run #include command. But It don't know file name: "/usr/home/iam/work/" "a2.h" it wants to see it as: "/usr/home/iam/work/a2.h".
I even tried to do so:
abc.c
But #include style should has double quotes.
If I use
- all ok. This works for standard libraries.
And how do you connect your own library?
Said me please..
I have next directory, for ehample: /usr/home/iam/work. In this folder:
a2.h
Code:
#ifndef _A2_H_
#define _A2_H_
int
summ(int a, int b, int c)
{
return a+b+c;
}
#endif
Code:
#include <stdio.h>
#include "/usr/home/iam/work/a2.h"
int
main(int argc, char *argv[])
{
extern int summ(int, int, int);
printf("Result: %d\n", summ(1,2,3));
return 0;
}
#include "a2.h"
- not write full path to it. But me need it. I have my private C library. And I thought, what if i write use next style:
abc.c
Code:
#define loadit(name) "/usr/home/iam/work/"#name
#include <stdio.h>
#include loadit(a2.h)
...
But if I compile it - I have:
abc.c:12:23: error: /usr/home/iam/work/: No such file or directory
I understand, as my (not my, C has) preprocessor use this script:
Step one: it saw 3 line [ #include loadit(a2.h) ], it search define loadit.
Step two: it rewrite line 3 to next style:
#include "/usr/home/iam/work/" "a2.h"
After preprocessor tries to run #include command. But It don't know file name: "/usr/home/iam/work/" "a2.h" it wants to see it as: "/usr/home/iam/work/a2.h".
I even tried to do so:
abc.c
Code:
#define loadit(name) /usr/home/iam/work/ ## name
#include <stdio.h>
#include loadit(a2.h)
...
But #include style should has double quotes.
If I use
Code:
#define loadit2(name) <std ## name>
#include loadit2(io.h)
- all ok. This works for standard libraries.
And how do you connect your own library?