Converting an absolute path in #include in C

2019-08-01 12:24发布

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?

标签: c ruby include
1条回答
ゆ 、 Hurt°
2楼-- · 2019-08-01 13:15

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}
查看更多
登录 后发表回答