5

Here is my minimal example of below: https://www.dropbox.com/s/7fwsr3sigb60rtw/leveling-test.zip?dl=0

My current project folder structure and relevant CMakeLists content:

leveling
├── CMakeLists.txt: add_subdirectory(deps) 
└── deps
    ├── CMakeLists.txt: add_subdirectory(xml-reading)
    └── xml-reading
        ├── CMakeLists.txt: add_subdirectory(deps)
        │                   add_library(xml-reading ...)
        │                   target_include_directories(xml-reading PUBLIC ${CMAKE_CURRENT_LIST_DIR}/deps/tinyxml2)
        │                   target_link_libraries(xml-reading PUBLIC tinyxml2)
        └── deps
            ├── CMakeLists.txt: add_subdirectory(tinyxml2)
            └── tinyxml2

this generates a xml-reading.dll file.

But then the leveling project linker options have /DYNAMICBASE "bin\windows-32\debug\xml-reading.lib" "bin\windows-32\debug\BOBPrimitives.lib" "bin\windows-32\debug\tinyxml2d.lib"

Which yields: 2>LINK : fatal error LNK1104: cannot open file 'bin\windows-32\debug\xml-reading.lib'

What's up?

  • I tried adding SHARED to add_library(xml-reading SHARED ...), didn't help
  • As a workaround I set STATIC at add_library(xml-reading STATIC ...) to force it to produce a .lib file - but I'd like to understand what's going on
WurmD
  • 1,231
  • 5
  • 21
  • 42
  • add_library defaults to SHARED libraries (creating a dll and a lib file) setting STATIC causes it to create an archive library (creating a lib file). If xml-reading is only header files then I would image that no library is actually created because there is no source code to compile. Did xml-reading actually build and create a file? – fdk1342 Dec 04 '18 at 00:05
  • For this question I added an empty cpp file to xml-reading so a file is indeed created, a dll file when STATIC is not specified in add_library – WurmD Dec 05 '18 at 10:37
  • added minimal example: https://www.dropbox.com/s/7fwsr3sigb60rtw/leveling-test.zip?dl=0 – WurmD Dec 05 '18 at 11:21
  • also created a CMake bug report https://gitlab.kitware.com/cmake/cmake/issues/18684 – WurmD Dec 05 '18 at 11:26
  • 1
    Should not Shared projects create both a .lib and a .dll files? (this .lib is for devs linking with your .dll) – Sandburg May 31 '19 at 16:01
  • 1
    Specific Windows thing - ```set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)``` does the trick. – drewpts Nov 01 '22 at 17:58
  • Note: `target_include_directories(xml-reading PUBLIC ${CMAKE_CURRENT_LIST_DIR}/deps/tinyxml2)` shouldn't be necessary if you `target_link_libraries(xml-reading PUBLIC tinyxml2)` and tinyxml2 is set up right. – starball Jan 22 '23 at 21:45

0 Answers0