Exporting an imported library

后端 未结 3 920
野的像风
野的像风 2021-02-07 21:31

I have projectA, into which I\'m importing a library with:

add_library(foo STATIC IMPORTED)
set_property(TARGET foo PROPERTY IMPORTED_LOCATION /path/to/foo.a)
         


        
3条回答
  •  太阳男子
    2021-02-07 22:08

    I did not find an actual solution for the problem as stated, but am posting my own workaround for future reference.

    I realized that the foo dependency was being emitted in the export; it just didn't have a path with it. And since I still haven't figured out how to get cmake to export the path along with it, I reverted my export command to that shown in the question above (without foo).

    Then I went back to the original place where foo was being imported and removed the add_library and set_property, replacing them with this:

    set(foo /path/to/foo.a)
    

    Then changed the target_link_libraries to:

    target_link_libraries(thislib ${foo})
    

    In other words, rather than making it a real "imported library", it's just a raw library path. This does get correctly written into the export file and allows projectB to link.

提交回复
热议问题