SoftwareNetwork / sw

Software Manager. Build System, Build System Generator and Package Manager. C/C++ and other languages. Tools and libraries for Software Management.
https://software-network.org
Other
115 stars 23 forks source link

How can make a lib available with find_package() #84

Closed z-pc closed 2 years ago

z-pc commented 2 years ago

Hi Egor, My project name is "MyProject", and third-ty project is "ExternProject". In "MyProject",

set(SW_BUILD_SHARED_LIBS 0)

find_package(SW REQUIRED)
sw_add_package(org.sw.demo.danbloomberg.leptonica) #------------>leptonica using jpeg
sw_execute()

add_subdirectory(ExternProject)

##### do somethings

add_executable(MyProject test.cpp)
target_link_libraries(MyProject PUBLIC org.sw.demo.jpeg ExternProject)

In "ExternProject",

find_package(JPEG REQUIRED)
if (JPEG_FOUND) #------------>jpeg will not found
       include_directories(${JPEG_INCLUDE_DIR})
else()
      set(source_files libjpeg/jaricom.c ... ) #------------>so, it's add a source files of jpeg to themselves 

ExternProject include directly source files of JPEG because JPEG_found = false ,but JPEG linked to MyProject through leptonica, in my local, it's make a conflict about already defined symbol:

2>Generating code
2>Finished generating code
2>org.sw.demo.jpeg-9.4.0.lib(jcomapi.c.9c2fe279.obj) : error LNK2005: jpeg_abort already defined in externproject.lib(jcomapi.obj)
2>org.sw.demo.jpeg-9.4.0.lib(jcomapi.c.9c2fe279.obj) : error LNK2005: jpeg_alloc_huff_table already defined in externproject.lib(jcomapi.obj)
2>org.sw.demo.jpeg-9.4.0.lib(jcomapi.c.9c2fe279.obj) : error LNK2005: jpeg_alloc_quant_table already defined in externproject.lib(jcomapi.obj)
2>org.sw.demo.jpeg-9.4.0.lib(jcomapi.c.9c2fe279.obj) : error LNK2005: jpeg_destroy already defined in externproject.lib(jcomapi.obj)
2>D:\dev\myproject.cp37-win_amd64.pyd : fatal error LNK1169: one or more multiply defined symbols found

How can I avoid a conflict or make org.sw.demo.jpeg available with find_package() Thanks

egorpugin commented 2 years ago

Hi,

  1. You can try to build deps (leptonica) as .so and this won't touch your jpeg. Of course, .so brings another burden. set(SW_BUILD_SHARED_LIBS 1)

  2. You can try to add a prefix to your jpeg symbols somehow, then projects will link ok. There were some plans of adding package prefixes through sw itself, but it's not implemented yet.

  3. Another solution I see is to package YOUR jpeg into sw and include as dependency. But the issue with renaming symbols is still here.

Also note that cmake integration is buggy currently. Sometimes it brings wrong config files (debug instead of release or similar).

z-pc commented 2 years ago

Temporarily, I separate them into parts to avoid conflicts, create an interface for ExternProject as shared libs project.

Thanks for supporting.