embed ruby code in C - c

I know there's severals post about this, but i'm stack
here's my C code
#include </usr/include/ruby-1.9.1/ruby/ruby.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
ruby_init();
rb_eval_string("puts 'hello'");
ruby_finalize();
return 0;
}
i've got the following error when compile it in sublime text 2
In file included from /Users/pierrebaille/Code/Ruby/embedRuby/embedRubyFirst.c:1:
/usr/include/ruby-1.9.1/ruby/ruby.h:1481:24: error: ruby/subst.h: No such file or directory
[Finished in 0.1s with exit code 1]
thanks for your help

You should not hard-code the full path of a header file like
#include </usr/include/ruby-1.9.1/ruby/ruby.h>
proper is
#include <ruby.h>
and told your gcc to search the header file via CFLAGS and libariy via LD_FLAGS, simply command without makefile could be:
gcc -o demo.exe -I/path/to/ruby/headers rubydemo.c -L/path/to/ruby/lib -lruby-libary-name

One of you files you're including in turn includes ruby/subst.h, , but it appears that ruby is not in your path, which is why you have this in your code:
#include </usr/include/ruby-1.9.1/ruby/ruby.h>
Instead of hardcoding paths you should simply add "/some_path/" to your compiler path(s) setting, where some_path contains the folder ruby as a child. Now your own include turns into:
#include <ruby/ruby.h>

Related

fatal error: addFunc.h: No such file or directory

i have created a Makefile to run C program in shell script.but i get as error fatal error: addFunc.h: No such file or directory in mainProg.c page and addFunc.c page.i tried my best to solve this problem.but i didn't get a solution.i have mentioned my code below.
mainProg.c
#include <stdio.h>
#include "/home/name/Desktop/add/addFunc.h"
int main(){
int a,b;
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
printf("sum:%d\n",add(a,b));
return 0;
}
addFunc.h
int add(int a, int b)
addFunc.c
#include "/home/name/Desktop/add/addFunc.h"
int add(int a,int b){
return (a+b);
}
Makefile
Add: mainProg.c addFunc.c
gcc -o Add mainProg.c addFunc.c -I.
You really should be cutting and pasting, because clearly the text you've pasted here is nothing like what you're actually using (you have tons of syntax errors here).
However, the problem is that the compiler can't find your header file. This can be solved in one (or both) of two ways:
First, you should use the #include <...> form only for system headers like stdio.h etc. For your personal headers, you should use the form #include "..." instead. The difference is implementation-specific but for most compilers it is that include files using <...> are never looked for in the current directory but only in system directories and directories given with -I, while include file using "..." are looked for also in the current directory.
You could also simply ask the compiler to always look in the current directory by adding the -I. option to your compile line in your makefile.
It seems the problem you are getting is occurring because you are using #include <addFunc.h>. You would use <> when you are using a system header file. From your makefile it seems you are not.
The #include statement is a little different when you use header files of your own program because it searches in the dictionary your .c file is located.
Using #include "addFunc.h" should do the trick.
For more info on the #include directive see this page

TURBO C++: Unable to open include file stdio.h

I am trying to compile a simple C program using TUrbo C++ 3.2. But getting the following error: Unable to open include file 'STDIO.h'
I do have these files in INCLUDE library.
Cant help you if you dont post your code. Check if you use #include <cstdio> (not #include "cstdio" or #include <cstdio.h> or #include "cstdio.h".
#include <cstdio> will always work.

#include "unpipc.h" in c no such file or directory

#include "unpipc.h"
I am trying to use #include "unpipc.h" with cygwin but it gives me an error not such file or directory
I tried to write it as #include <unpipc.h> but still the error occur.
the code is in C language.
As has been noted, that is not a standard file
$ curl 'cygwin.com/cgi-bin2/package-grep.cgi?text=1&arch=x86_64&grep=unpipc.h'
Found 0 matches for unpipc.h

Undefined reference to in AVR-GCC

My main.c is as below
#include <avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>
#include <string.h>
#include "main.h"
#include "globle.h"
#include "LCD.h"
int main()
{
...
...
...
lcdInit(0xc0);
lcdScreen(0);
.
.
.
return 0;
}
The definition of lcdInit(0xc0); and lcdScreen(0); is in my lcd.c file
and I have a header file lcd.h having the following lines:
void lcdInit(char);
void lcdScreen(char);
But still I am getting:
C:\Documents and Settings\Tanv\My Documents\my_project5\default/../Main.c:95: >undefined >reference to
`lcdInit'
and
C:\Documents and Settings\Tanvr\My
Documents\my_project5\default/../Main.c:96: undefined reference to
`lcdScreen'
What is wrong here?
This is a linker error.
You are not building your program properly, you need to compile all C files together, like so:
$ gcc-avr -o program main.c lcd.c
or link them together from object files if you compile separately.
Add source and header files to your project by
1. Right click "Source Files" then "Add Existing Source File(s)"
2. Right click "Header Files" then "Add Existing Header File(s)"
Refer to Add Source to Project Step 6.
I had the same problem and I added the files to the project from the beginning and they were compiled together. But this did not solve the problem and I accidentally noticed that I made a mistake, namely the file of the implementation of the functions of the library had the extension .c, and the main extension .cpp. To solve the problem, I simply reassembled the project in c format.

Do I need to include system header file in the source if another header file already includes it?

For example, in the header file example.h, I wrote:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
And in the source file example.c, I wrote:
#include "example.h`
Do I still need to explicitly wrote these lines if I need functions of these libararies?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Thanks!
No.
Keep in mind that includes works like some kind of text substitution, as it's done by the preprocessor.
When you write, on some file:
#include "someheader.h"
It's just like that line will be replaced with the actual content of the header file.
No, you don't.
Include will, as it's named, include the whole content of your header file in your .c file.
If you are using linux, try cpp example.c or gcc -E example.c to see what #include does. You will run the c-preprocessor on your file, which is the program that interpret all # started instructions before the copilation

Resources