Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5999461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:33:19+00:00 2026-05-23T00:33:19+00:00

To preface: I am very new to C, so I am probably missing something

  • 0

To preface: I am very new to C, so I am probably missing something obvious but have been running around for days trying to figure out what it is…

I am trying to create a Ruby C extension that will work on both Mac and PC and that uses libcurl to download files.

Basically, all the tool does is gets a list of files from Ruby, downloads the files and puts them where Ruby tells them to.

I have the extension working from within Ruby and have compiled a C extension to interface with Ruby.

Basically my code looks like this:

#include <string.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include "ruby.h"

VALUE Test = Qnil;

void Init_test();

VALUE download_file(VALUE self, VALUE from, VALUE to);

void Init_test()
{
    Test = rb_define_class("Test", rb_cObject);
    rb_define_method(Test, "download_file", download_file, 2);
}

VALUE download_file(VALUE self, VALUE from, VALUE to)
{
    CURL *curl;
    FILE *fp;
    CURLcode res;

    char *url = STR2CSTR(from);
    char outfilename[FILENAME_MAX] = STR2CSTR(to);

    curl = curl_easy_init();
    if (curl) {
        fp = fopen(outfilename,"wb");
        curl_easy_setopt(curl, CURLOPT_URL, url);
        // curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        fclose(fp);
    }
    return 0;
}

What I am having problems with is getting libcurl to actually work:

$ ruby test.rb
dyld: lazy symbol binding failed: Symbol not found: _curl_easy_init
  Referenced from: /path/to/test.bundle
  Expected in: flat namespace

dyld: Symbol not found: _curl_easy_init
  Referenced from: /path/to/test.bundle
  Expected in: flat namespace

Trace/BPT trap

I am using Ruby’s mkmf to make a Makefile for my extension:

require 'mkmf'
extension_name = 'test'
dir_config(extension_name)
create_makefile(extension_name)

I am assuming that when compiling the extension, the Makefile cannot find that Curl files but since I am new to C/Ruby extensions I cannot figure out why that would be.

When I run curl-config --cflags this is what I get:

$  curl-config --cflags
-I/usr/local/include

My libcurl include/library files are:

/usr/local/include/curl/
/usr/local/lib/libcurl.dylib

My setup:

  • Mac OSX 10.6.4
  • Ruby 1.8.6-p420
  • Curl 7.21.7-DEV (i386-apple-darwin10.7.0) libcurl/7.21.7-DEV OpenSSL/0.9.8l zlib/1.2.3

Any help would be greatly appreciated!

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:33:20+00:00Added an answer on May 23, 2026 at 12:33 am

    You need to tell mkmf to link to libcurl when building your extension. The command to use is have_library.

    In your exconf.rb, add

    have_library("curl", "curl_easy_init")
    

    before the call to create_makefile.

    Also, I don’t think you need the dir_config(extension_name) line.

    (On a Mac, you can see what libraries are linked to a binary with otool -L. Try

    otool -L test.bundle
    

    before and after adding have_library, you should see a line something like /usr/lib/libcurl.4.dylib (compatibility version 6.0.0, current version 6.1.0) added.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me preface this with the disclaimer that I am very new to multithreading
I have to preface this with the fact that I love jQuery as a
PREFACE: I'm relatively inexperienced in C++ so this very well could be a Day
I am new to this, so please bear with me... I need to very
Preface: I was thinking the other day about a new database structure for a
Let me preface this by saying that I'm a very raw iPhone developer. I'm
I will preface the question by saying that I am somewhat new to the
I will preface this by I am new to XNA and I realize what
To preface I am using Borland C++ and the VCL. I need some sort
Let me preface this question by saying I use TextMate on Mac OSX for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.