Strobecast
Strobecast

Reputation: 21

Converting an absolute path in #include in C

I am trying to get some code that I acquired from a repository to work on my system.

In one of the C files, it contains an absolute path to a header:

 #include "/home/user/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-linux/ruby/config.h"

Because this file and directory does not exist on my system, compiling the source code fails.

I assume if I change this to point at my personal location of config.h, it will succeed but then fail on others' systems.

Is there a way to point at some symbolic link that the system will then use the proper location for such a file? What is the best way to approach this situation?

Upvotes: 1

Views: 337

Answers (1)

Timothy Jones
Timothy Jones

Reputation: 22135

Change it to #include "ruby/config.h", and then add -I/home/user/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-linux/ (or whatever your location is) to your compiler options. This tells the preprocessor to add that directory to the list of directories to search when looking for #includes.

To solve the portability you can then change whatever generates the makefile to take this path as an option/argument, or you can just put it in a variable at the top of the makefile and ask people to change it:

RUBY_LOCATION = /home/user/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-linux/

CFLAGS = -Wall -I${RUBY_LOCATION}

Upvotes: 4

Related Questions