Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Compiling C extensions with MSVC

1 view
Skip to first unread message

Eric Hofreiter

unread,
Nov 3, 2005, 10:39:07 PM11/3/05
to
Hello,
I would very much like to be able to compile a C extension for Ruby using MSVC, but I am coming across many problems. First of all, I am using extconf.rb with nothing but a create_makefile() statement. When it creates the makefile and I try to run it, it complains about not being able to find header files and libraries. So I went into the makefile and manually changed things so that it would include everything that it asked for. However, I am now getting an error that says:

c_lib-i386-mswin32.def : error LNK2001: unresolved external symbol Init_c_lib
c_lib.lib : fatal error LNK1120: 1 unresolved externals
LINK : fatal error LNK1141: failure during build of exports file
NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code '0x2'
Stop.

"c_lib" is the name of the extension and .c file. I believe this may have something to do with it asking me to link a library called msvcrt.lib, which was located in a directed called amd64 or ia64. I'm not sure what these two things mean, but I know that they do not work with my system. I believe the one that works for me is x86. However, those two directories were the only one that had msvcrt.lib.


---------------------------------
Yahoo! FareChase - Search multiple travel sites in one click.

David Koontz

unread,
Nov 4, 2005, 2:28:50 AM11/4/05
to
Hey Eric, I just went through all this myself. I did a write up that
should hopefully guide you through the process.
http://www.koontzfamily.org/david/blog/?p=230

HTH,
David Koontz

Lyndon Samson

unread,
Nov 4, 2005, 3:32:38 AM11/4/05
to
On 11/4/05, David Koontz <da...@koontzfamily.org> wrote:
> Hey Eric, I just went through all this myself. I did a write up that
> should hopefully guide you through the process.
> http://www.koontzfamily.org/david/blog/?p=230
>

Off topic but the koontzfamily doesnt include the famous author Dean does it?

I can think of some mean programmer as protagonist based horror stories :-)


Curt Hibbs

unread,
Nov 4, 2005, 9:19:01 AM11/4/05
to

Continuing this OT thread, I am currently "reading" (actually, I
listen to audiobooks as I commute) Snow Crash by Neal Stephenson. It
is a very, very good and the protagonist is a hacker named "Hiro
Protagonist". Its sci-fi, not horror, but its one of the best books
I've read in a while.

Curt


Tanner Burson

unread,
Nov 4, 2005, 10:11:31 AM11/4/05
to


And for one last addition to the OT'ness. If you like Snow Crash make sure
to check out a couple of his other books, especially Diamond Age and
Cryptonomicon.

Curt
>
>


--
===Tanner Burson===
tanner...@gmail.com
http://tannerburson.com <---Might even work one day...

David Koontz

unread,
Nov 4, 2005, 10:56:29 AM11/4/05
to
On 11/4/2005 7:19:01 AM, Curt Hibbs (curt....@gmail.com) wrote:
> On 11/4/05, Lyndon Samson wrote:

> > On 11/4/05, David Koontz wrote:
> > > Hey Eric, I just went through all this myself. I did a write up that
> > > should hopefully guide you through the process.
> > > http://www.koontzfamily.org/david/blog/?p=230
> > >
> >
> > Off topic but the koontzfamily doesnt include the famous author Dean
> does it?
> >
> > I can think of some mean programmer as protagonist based horror
stories
> :-)
>
> Continuing this OT thread, I am currently "reading" (actually, I
> listen to audiobooks as I commute) Snow Crash by Neal Stephenson. It
> is a very, very good and the protagonist is a hacker named
> "Hiro
> Protagonist". Its sci-fi, not horror, but its one of the best
> books
> I've read in a while.
>
> Curt

This koontzfamily is but a very distant relation some umpteen times
removed (or so the geneologist in the family tells me). Audible rocks,
it will save your sanity and actually make the time you spend in your
car commuting enjoyable! If you sign up make sure to go with the 1 or 2
books a month subscription, it's typically 50% - 80% cheaper than buying
the audiobooks directly.

David Koontz

Curt Hibbs

unread,
Nov 4, 2005, 11:04:45 AM11/4/05
to
On 11/4/05, David Koontz <da...@koontzfamily.org> wrote:

I keep a list of books I want to listen to. I first check my local
library, and if they on't have it I get it from Audible (subscription
is definitely the way to go, brings the cost per book to about
$11.00).

Curt


nobu....@softhome.net

unread,
Nov 4, 2005, 7:14:44 PM11/4/05
to
Hi,

At Fri, 4 Nov 2005 12:39:07 +0900,
Eric Hofreiter wrote in [ruby-talk:164084]:


> c_lib-i386-mswin32.def : error LNK2001: unresolved external symbol Init_c_lib

It is the function what *you* have to write to initialize the
extension.

--
Nobu Nakada


Eric Hofreiter

unread,
Nov 5, 2005, 4:54:41 PM11/5/05
to
I don't understand exactly what you mean. The class that I am loading into ruby is called "Lib." When I was getting that error the only thing that was named c_lib was the .c file itself. I have no idea where else it could have gotten that name.

This might be a bit nit-picky but the Init doesn't need to be named the
same as
the .c file necissarily. It needs to be named the same as the class or
Module
that Ruby will be loading from your .so. I haven't tried this but I
would
assume if you had multiple modules defined in one c file you'd need an
Init_<module_name> for each one the link step would fail if any were
absent. I
doubt you'll ever run into, it's just something to file away.

David

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

nobu....@softhome.net

unread,
Nov 5, 2005, 8:43:12 PM11/5/05
to
Hi,

At Sun, 6 Nov 2005 06:54:41 +0900,
Eric Hofreiter wrote in [ruby-talk:164395]:


> This might be a bit nit-picky but the Init doesn't need to be named the same as
> the .c file necissarily. It needs to be named the same as the class or Module
> that Ruby will be loading from your .so. I haven't tried this but I would
> assume if you had multiple modules defined in one c file you'd need an
> Init_<module_name> for each one the link step would fail if any were absent. I
> doubt you'll ever run into, it's just something to file away.

Ruby doesn't know what class or module (even nothing) will be
defined in an extension. Just its filename.

--
Nobu Nakada


0 new messages