zoukankan      html  css  js  c++  java
  • 关于cmake输出动态链接库名字的问题

    使用cmake进行项目编译管理时,我们经常使用

    add_library(foo SHARED foo.cpp)

    这样的话,输出时,如果在win下面会得到foo.dll,linux下面会得到libfoo.so,mac 下得到libfoo.dylib

    如果我们编写的是用于lua扩展的C模块,那么在进行require的时候,比如这样:

    require 'libfoo'    --默认加载libfoo.[so|dll],并且执行luaopen_libluafoo
    require 'foo'     --加载foo.so,并且执行luaopen_luafoo

    并且各个平台下各不相同,这真是太苦恼的,cmake就是方便

    ##这样就不会有lib前缀了
    set_target_properties(foo PREFIX "")

    ##由于在mac下如果加载的是dylib也是件麻烦的事,不然把后缀也改了吧反正不考虑windows
    set_target_properties(foo SUFFIX "so")

     对了,吐槽一下mac的rpath也是件麻烦的事情

    好贴留名一下https://gist.github.com/robertmaynard/5750737

    # enable @rpath in the install name for any shared library being built
    set(CMAKE_MACOSX_RPATH 1)
    
    # the install RPATH for bar to find foo in the install tree.
    # if the install RPATH is not provided, the install bar will have none
    set_target_properties(bar PROPERTIES INSTALL_RPATH "@loader_path/../lib")
  • 相关阅读:
    线程访问ui,托管
    获取当前线程id
    线程访问ui,使用委托方式
    python的reflect反射方法
    python读写Excel文件(xlrd、xlwr)
    基于python+selenium的框架思路(二)
    基于python+selenium的框架思路
    python之sys.argv
    Django ajax方法提交表单,及后端接受数据
    jenkins+checkstyle
  • 原文地址:https://www.cnblogs.com/linbc/p/5238691.html
Copyright © 2011-2022 走看看