# Extending ruby: ruby\_init() instacloses process

**URL:** <https://www.ruby-forum.com/t/extending-ruby-ruby-init-instacloses-process/181976>\
**Category:** Ruby\
**Created:** [January 21, 2010, 2:06am UTC](https://www.ruby-forum.com/t/extending-ruby-ruby-init-instacloses-process/181976 "2010-01-21T02:06:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nilbert\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bbe5ce/32.png) [@Nilbert\_N](https://www.ruby-forum.com/u/Nilbert_N)\
**Post date:** [January 21, 2010, 2:06am UTC](https://www.ruby-forum.com/t/extending-ruby-ruby-init-instacloses-process/181976/1 "2010-01-21T02:06:16Z")

</div>

Hey guys, I am extending ruby in a C++ program. I have all the headers  
set up and stuff so it compiles without error, but I do get one  
warning (MSVC Express 2008):

c:\visual studio 2008\projects\remoteexec\remoteexec\rubyheaders\ruby/  
missing.h(154) : warning C4273: ‘vsnprintf’ : inconsistent dll linkage  
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdio.h(350) :  
see previous definition of ‘vsnprintf’

Because it doesn’t keep it from compiling, I don’t think this is the  
source of my problem. The problem is, when I call ruby\_init() to start  
the interpreter, the program instantly terminates. Run by the command  
line, it looks like this:

C:\Visual Studio 2008\Projects\remoteExec\Release\>project.exe

C:\Visual Studio 2008\Projects\remoteExec\Release\>

As you can see, it does nothing. There are no errors, even though my  
code is wrapped in a try/catch thing. Here is the C++ Code:

#define WIN32\_LEAN\_AND\_MEAN

#include \<windows.h\>  
#include   
#include   
#include   
#include “ruby.h”

using namespace std;

int main() {  
//copied from teh internetz  
/_HWND hWnd = GetConsoleWindow();  
ShowWindow(hWnd, SW\_HIDE);_/

try {  
ruby\_init();  
} catch (char\* e) {  
cout \<\< e;  
}

system(“PAUSE”);

return 0;  
}

This code isn’t supposed to do anything, it’s just confining the error  
to that one line. No error is outputted and the program does not pause  
after executing the try/catch, like it should with system(“PAUSE”).  
Does anyone know why it is just stopping the program when ruby\_init()  
is called? I am using the ruby 1.9 libs and headers and stuff.

---

<div class="post-metadata">

**Author:** ![Nilbert\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bbe5ce/32.png) [@Nilbert\_N](https://www.ruby-forum.com/u/Nilbert_N)\
**Post date:** [January 21, 2010, 2:06am UTC](https://www.ruby-forum.com/t/extending-ruby-ruby-init-instacloses-process/181976/2 "2010-01-21T02:06:51Z")

</div>

Also as you can see, I have commented out the code that would have  
stopped the console window from displaying, as I thought it may have  
been the source of the problem. However, as evidenced by the command  
line and the fact that no process that belongs to the program is  
running, the program is indeed ceasing to exist upon reaching the  
ruby\_init(); line.

---

<div class="post-metadata">

**Author:** ![Nilbert\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bbe5ce/32.png) [@Nilbert\_N](https://www.ruby-forum.com/u/Nilbert_N)\
**Post date:** [January 21, 2010, 2:15am UTC](https://www.ruby-forum.com/t/extending-ruby-ruby-init-instacloses-process/181976/3 "2010-01-21T02:15:37Z")

</div>

Actually, placing ruby\_init() anywhere in the file closes the program  
instantly. Replacing the try/catch block above with this one:

try {  
printf(“ARGGGGGGGGGGGGGGGGGG”);

printf(“asdf”);

ruby\_init();  
} catch (char\* e) {  
printf("%s", e);  
}

and running the program via command line does not print anything.  
What the heck. Anyone have any idea why the bloody blazes this is  
happening?

---

<div class="post-metadata">

**Author:** ![Nilbert\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bbe5ce/32.png) [@Nilbert\_N](https://www.ruby-forum.com/u/Nilbert_N)\
**Post date:** [January 21, 2010, 3:01am UTC](https://www.ruby-forum.com/t/extending-ruby-ruby-init-instacloses-process/181976/4 "2010-01-21T03:01:51Z")

</div>

Well, I may just have to learn how to use MinGW if no one can figure  
out why VC++ is messing it up.

---

<div class="post-metadata">

**Author:** ![Nilbert\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bbe5ce/32.png) [@Nilbert\_N](https://www.ruby-forum.com/u/Nilbert_N)\
**Post date:** [January 21, 2010, 3:29am UTC](https://www.ruby-forum.com/t/extending-ruby-ruby-init-instacloses-process/181976/5 "2010-01-21T03:29:21Z")

</div>

On Wed, Jan 20, 2010 at 8:00 PM, Nilbert N.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Well, I may just have to learn how to use MinGW if no one can figure  
> out why VC++ is messing it up.

Back to that vsnprintf warning, what happens if you remove #include  
?

---

<div class="post-metadata">

**Author:** ![Nilbert\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bbe5ce/32.png) [@Nilbert\_N](https://www.ruby-forum.com/u/Nilbert_N)\
**Post date:** [January 21, 2010, 4:24am UTC](https://www.ruby-forum.com/t/extending-ruby-ruby-init-instacloses-process/181976/6 "2010-01-21T04:24:56Z")

</div>

On Jan 20, 6:27 pm, Eric C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On Wed, Jan 20, 2010 at 8:00 PM, Nilbert N.
> 
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Well, I may just have to learn how to use MinGW if no one can figure  
> > out why VC++ is messing it up.
> 
> Back to that vsnprintf warning, what happens if you remove #include ?

Nothing happens to the error.

---

<div class="post-metadata">

**Author:** ![Nilbert\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bbe5ce/32.png) [@Nilbert\_N](https://www.ruby-forum.com/u/Nilbert_N)\
**Post date:** [January 21, 2010, 2:40am UTC](https://www.ruby-forum.com/t/extending-ruby-ruby-init-instacloses-process/181976/7 "2010-01-21T02:40:12Z")

</div>

On Wed, Jan 20, 2010 at 7:15 PM, Nilbert N.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> printf("%s", e);
> 
> ```
> 
> }
> 
> and running the program via command line does not print anything.  
> What the heck. Anyone have any idea why the bloody blazes this is  
> happening?

No idea, but I got it to run smoothly when compiled with MinGW (for  
what little it’s worth).
