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

  • SEARCH
  • Home
  • 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 7936011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:05:06+00:00 2026-06-03T22:05:06+00:00

Has anyone had luck using CMake to create Ruby bindings via SWIG? I have

  • 0

Has anyone had luck using CMake to create Ruby bindings via SWIG? I have a working example for creating Python bindings via SWIG in my CMake file, but when I use the same approach to create a Ruby binding the actual Ruby file doesn’t get created. With the working Python binding, a Python file does get created.

Here’s the relevant portions of my CMakeLists.txt file:

if (${SWIG_FOUND})
  find_package( Ruby REQUIRED )

  include_directories(
    ${RUBY_INCLUDE_DIRS}
    )

  include (${SWIG_USE_FILE})

  set (CMAKE_SWIG_FLAGS "") # set the global SWIG flags to empty
  set_source_files_properties (TESTSWIG.i PROPERTIES CPLUSPLUS ON) # TESTSWIG.i is c++

  SWIG_ADD_MODULE (test-ruby ruby TESTSWIG.i src/Test.cpp)
  SWIG_LINK_LIBRARIES (test-ruby test ${RUBY_LIBRARY})

  set(swig_SOURCES
    ${CMAKE_CURRENT_BINARY_DIR}/libtest-ruby.so
    )

  install(FILES ${swig_SOURCES}
    DESTINATION lib/ruby
    )
endif(${SWIG_FOUND})

Anyone had luck creating Ruby bindings via SWIG using CMake?!

  • 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-06-03T22:05:08+00:00Added an answer on June 3, 2026 at 10:05 pm

    We use it. You can give a look to these examples:

    http://svn.opensuse.org/svn/yast/trunk/libyui-bindings/

    However, we don’t use the SWIG macros (except for finding SWIG itself), but we use ADD_CUSTOM_COMMAND:

    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
    
    EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorarchdir']" OUTPUT_VARIABLE RUBY_VENDOR_ARCH_DIR)
    
    MESSAGE(STATUS "Ruby executable: ${RUBY_EXECUTABLE}")
    MESSAGE(STATUS "Ruby vendor arch dir: ${RUBY_VENDOR_ARCH_DIR}")
    MESSAGE(STATUS "Ruby include path: ${RUBY_INCLUDE_PATH}")
    
    SET( SWIG_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/yui_ruby.cxx" )
    
    ADD_CUSTOM_COMMAND (
       OUTPUT  ${SWIG_OUTPUT}
       COMMAND ${CMAKE_COMMAND} -E echo_append "Creating wrapper code for ruby..."
       COMMAND ${SWIG_EXECUTABLE} -c++ -ruby -autorename -o ${SWIG_OUTPUT} -I${LIBYUI_INCLUDE_DIR} ${SWIG_INPUT}
       COMMAND ${CMAKE_COMMAND} -E echo "Done."
       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
       DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../*.i
    )
    
    ADD_LIBRARY( yui_ruby SHARED ${SWIG_OUTPUT} )
    INCLUDE_DIRECTORIES( ${RUBY_INCLUDE_PATH} ${LIBYUI_INCLUDE_DIR} )
    
    SET_TARGET_PROPERTIES( yui_ruby PROPERTIES PREFIX "" OUTPUT_NAME "yui")
    
    TARGET_LINK_LIBRARIES( yui_ruby ${LIBYUI_LIBRARY} )
    TARGET_LINK_LIBRARIES( yui_ruby ${RUBY_LIBRARY} )
    
    INSTALL(TARGETS yui_ruby LIBRARY DESTINATION ${RUBY_VENDOR_ARCH_DIR})
    

    I assume your version is not working because the “lib” prefix in the .so file. This is exactly the reason why we do

    SET_TARGET_PROPERTIES( yui_ruby PROPERTIES PREFIX "" OUTPUT_NAME "yui")
    

    In order to get yui.so instead of libyui.so.

    Also make sure the path where you are installing the .so file is in the ruby load path.

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

Sidebar

Related Questions

Has anyone had any luck using Blend for Visual Studio 2011 Beta to create
Has anyone had any luck using ColdFusion as a way to collect data via
Has anyone had any experience using Adobe Air to create BitTorrent application? Is there
Has anyone had any luck using a UIPicker in the 3.2 SDK? I'm in
Has anyone had luck converting and using jpeg2000 on the ios? I am writing
Has anyone had any luck model binding two or more collections using the code
Has anyone had any luck of using Oracle from .Net on a 64 bit
Has anyone had any luck with compiling 64-bit Python extension modules for Windows using
Has anyone had any luck rolling a custom GWT jar for Google Collections /
Has anyone had any experiences developing large Java applications using GNU gettext for internationalization?

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.