简体   繁体   中英

cmake, swig and python: How to override conflicting symbols

I am using cmake to create a python wrapper with swig. The problem is, that there are conflicting symbols in lapack and python. I have a simple script to undefine the conflicting symbols before compilation and I can write a makefile that works. I am wondering, what would be the best approach to take when using cmake.

This makefile works:

tools_wrap.cc toolspy: tools.i ../libtools.a
    swig -I../ -c++ -python $(PYFLAGS) -shadow -o tools_wrap_tmp.cc tools.i 
    # A terrible hack to override conflicting function names in python and lapack
    python ./fix_undefs.py < tools_wrap_tmp.cc > tools_wrap.cc

_tools.so: tools_wrap.cc ../libtools.a
     $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(PYTHONINC) $(INCLUDES) -I../ tools_wrap.cc $(LIBS) -o _tools.so

Thanks for any help!

Vesa

After poking around the cmake swig-generator, I arrived at the following solution:

add_custom_target(TmpCWrap mv ${swig_generated_file_fullname} tmp.cxx 
    DEPENDS "${swig_generated_file_fullname}")

add_custom_target(FixDefs python ${CMAKE_CURRENT_SOURCE_DIR}/add_undefs.py < tmp.cxx > ${swig_generated_file_fullname}
    DEPENDS TmpCWrap
    COMMENT "Fixing defs for conflicting symbols in lapack and python")

add_dependencies(${SWIG_MODULE_PPToolbox_REAL_NAME} FixDefs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM