开发者

How to compile a simple source file with GCC in Linux

I am trying to compile a set of source files in C in Linux (Ubuntu). When I try to run the following command,开发者_Python百科 I am getting an error telling "ruby.h" is not found.

gcc custom_ext.c

This was giving me the following error message.

custom_ext.h:10: fatal error: ruby.h: No such file or directory

So I downloaded the entire Ruby source code and put it in a dummy directory /home/braga/ruby_source/ruby_1_8_7. I know that I need to include this directory in the path so that GCC will be able to identify and pick up ruby.h, but I have no idea on how to do that. Please help!!!


Did you installed "ruby-dev" package?

All you need is install packages from Ubuntu repositorie (using "apt-get", "aptitude", or any other package manager front-end). No need in downloading sources. Installing package will plcase all tour required headers and libraries in standard directories, so you will not have to deal with compiler keys.

And only if you do not have required packages in repos (or it is so old), you'll have to download sourcecode tarballs and INSTALL it (accordingly included in tarball instructions, often in file INSTALL).


-I /home/braga/ruby_source/ruby_1_8_7. Chances are that ruby.h lives in some subdirectory of that though, so you'll have to find it, and use the path to that directory though.


-I will help you. Add the path that you get using find / -name ruby.h This might be a starting point and you might need to add more paths tobe able successfully compile


Since you seem to be trying to compile a Ruby extension, this question might be useful to you. Note that it is always a bad idea to download sources or manually hack into something, there is always an official, convenient way to do it. If you found yourself putting files in random places, stop for a while and check to make sure you aren't doing something wrong.

Other than purely for convenience reasons, it is still better to install all the relevant development packages from the repository because the headers you've downloaded may not match binary libraries you are planning to link against. If they do not and if they aren't binary compatible, you find yourself in deep trouble. apt-file search and apt-cache search commands are very useful in finding out the particular package name you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜