I have a working swig wrapper for C++ library(mylib.so). And now I want to link mylib.so to the wrapper library(mylib_wrapper.so) statically. Currently I build my wrapper with cmake.
- Should a wrapped library be a static library(not a dynamic) if I want have a static linking in my swig wrapper?
- What modifications I should do in my interface/cmake files?
Currently I have following cmake file:
cmake_minimum_required(VERSION 2.8)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(Ruby)
include_directories(${RUBY_INCLUDE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_SWIG_FLAGS "")
set(MODULE_NAME ruby_module)
set(CMAKE_SWIG_OUTDIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set_source_files_properties(${MODULE_NAME}.i PROPERTIES CPLUSPLUS ON)
swig_add_module(${MODULE_NAME} ruby ${MODULE_NAME}.i ruby_wrapper.cpp)
swig_link_libraries(${MODULE_NAME} ${MAIN_LIBRARY_NAME})
swig_link_libraries(${MODULE_NAME} ${RUBY_LIBRARIES})
And .i file:
%module ruby_module
%{
#include "ruby_wrapper.h"
%}
%import std_string.i
%include "ruby_module.h"
And headers file: ruby_module.h and ruby_wrapper.h are have the same content.
#include <string>
class MyClass
{
public:
MyClass();
~MyClass();
public:
std::string myfunc(const std::string& path);
};
In the ruby_wrapper.cpp file is overwrited functions of mylib.so .