简体   繁体   English

尝试使用SWIG将C ++编译为Ruby时,没有这样的文件或目录“ ruby​​ / config.h”

[英]No such file or directory “ruby/config.h” when trying to compile C++ into Ruby using SWIG

I'm trying to get a basic example running using SWIG to convert a C++ file into Ruby. 我试图获得一个使用SWIG将C ++文件转换为Ruby的基本示例。 I have Ruby 2.0.0p451 (64 bit version) installed and I've also installed the 64-bit DevKit. 我安装了Ruby 2.0.0p451(64位版本),并且还安装了64位DevKit。 I'm running Windows 7 and trying to use swigwin-2.0.12. 我正在运行Windows 7,并尝试使用swigwin-2.0.12。 Finally, I am using the GCC C++ compiler supplied by Mingw-builds for the 64-bit version of Windows. 最后,我使用的是Mingw-builds提供的GCC C ++编译器,用于Windows 64位版本。

I have the basic C++ hello world program as shown below. 我有基本的C ++ hello world程序,如下所示。

#include <iostream>
#include <cstdlib>

using namespace std;

main()
{
    cout << "Hello World!";
    system("pause");
    return 0;
}

At the command prompt, I use the command: 在命令提示符处,我使用以下命令:

swig -module -c++ -ruby hello_world.cpp

This completes fine and produces a file titled hello_world_wrap.cxx . 这样就可以完成并生成一个名为hello_world_wrap.cxx的文件。 However, when I receive an error when I try to compile the .cxx file using the command: 但是,当我尝试使用以下命令编译.cxx文件时收到错误消息:

g++ -fPIC -c hello_world_wrap.cxx -IC:\Ruby200-x64\include\ruby-2.0.0

The error I am receiving is: 我收到的错误是:

命令提示符错误

All the research I've done has pointed me to an installation of the incorrect DevKit, but I don't think this is my issue. 我所做的所有研究都指出我安装了错误的DevKit,但我认为这不是我的问题。 I've made sure to download the 64-bit version of Ruby and the DevKit. 我已经确保下载Ruby和DevKit的64位版本。 I've checked the folder specified in the error, and there is no config.h file. 我已经检查了错误中指定的文件夹,并且没有config.h文件。 I'm not sure why the config.h file does not exist or why ruby.h is trying to load it. 我不确定为什么config.h文件不存在或为什么ruby.h试图加载它。

Any thoughts? 有什么想法吗?

Check that C:\\Ruby200-x64\\include\\ruby-2.0.0\\ruby\\config.h exists. 检查C:\\Ruby200-x64\\include\\ruby-2.0.0\\ruby\\config.h存在。 If not, find it and fix the path. 如果没有,找到并修复路径。

Update: 更新:

Check if there is a ruby.h in the same folder. 检查同一文件夹中是否有ruby.h。 If there is then just use -IC:\\Ruby200-x64\\include\\ruby-2.0.0\\ruby\\x64-mingw instead. 如果存在,则只需使用-IC:\\Ruby200-x64\\include\\ruby-2.0.0\\ruby\\x64-mingw Otherwise try adding a second -I, for this extra path. 否则,尝试为该额外路径添加第二个-I。 I agree with you this is a little strange (not so much the former, but definitely if you have to have two -I). 我同意您的观点,这有点奇怪(前者不是那么多,但是如果您必须有两个-I,则肯定是这样)。 The script at https://groups.google.com/forum/m/#!topic/comp.lang.ruby/RpjuvXpFI30 suggests that this might be normal, Ie you need one -I for platform-independent headers and one for platform-dependent. https://groups.google.com/forum/m/#!topic/comp.lang.ruby/RpjuvXpFI30上的脚本表明这可能是正常的,即对于平台无关的标头您需要一个-I,对于平台需要一个-I依赖性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM