0

As a result for my build it is expected to upload on the Artifactory repository both .dll and .lib file. Currently I am getting just .lib.

Can I add something additional to have .dll generated as well as repo expects that?

project(SystemUtils)


find_package(LogMsg REQUIRED)

set(SOURCES
  Eventlog.cpp
  OSObjects.cpp
)

set(HEADERS
  Eventlog.h
  OSObjects.h
  StdAfx.h
)

set(SOURCES
  ${SOURCES}
  ${MAIN_SOURCES}
)

set(HEADERS
  ${HEADERS}
  ${MAIN_HEADERS}
)

if(WIN32)

  set(CMAKE_CXX_FLAGS 
    "${CMAKE_CXX_FLAGS} -EHa -Fd$(OutDir)$(TargetName).pdb"
  )
endif()    

add_library(${PROJECT_NAME} HEADERS SOURCES)


target_include_directories(${PROJECT_NAME}
  PUBLIC .
  PUBLIC ${FALogMsg_INCLUDE_DIRS}
)

target_link_libraries(${PROJECT_NAME})
vel
  • 1,000
  • 1
  • 13
  • 35
  • I assume you mean the import library needed to use the library at build-time? Have you looked at the commands and options used by e.g. Visual Studio when building a DLL and its export library? Compare them to the commands and options used by your `CMakeLists.txt` created project. – Some programmer dude May 26 '23 at 06:26
  • 1
    I'm doubtful that you are not also getting the .lib file that gets built with/for your .dll file. Try doing a file search for files ending with .lib. – starball May 26 '23 at 06:27
  • 2
    My guess would be you're not exporting anything so no lib is generated – Alan Birtles May 26 '23 at 06:27
  • 2
    `add_library(${PROJECT_NAME} HEADERS SOURCES)` you probably meant to write `add_library(${PROJECT_NAME} ${HEADERS} ${SOURCES})`. Note that `${HEADERS}` is only necessary to show those files in the Visual Studio solution explorer for the generated solution. Also, if you mean for the library to always be shared, you should write `add_library(${PROJECT_NAME} SHARED ${HEADERS} ${SOURCES})` – starball May 26 '23 at 06:29
  • 1
    related to @AlanBirtles' comment about not exporting anything: https://stackoverflow.com/a/3950597/11107541 (Does this answer your question?) – starball May 26 '23 at 06:31
  • 2
    MSVC just doesn't create a import library, if nothing is exported from the dll. Have you added the `__declspec(dllexport)` in the right places? (Usually to be able to use the dll in the same project theres a preprocessor define in the public headers of the lib that's replaced with `__declspec(dllimport)` unless some preporcessor macro is defined, but I don't see any `target_compile_definitions(... PRIVATE ...)` here... – fabian May 26 '23 at 06:32
  • @user - please sorry for confusion - I am getting .lib but not getting .dll. I've permuted these two. Please sorry for this confusion!!! Can you please revise my question (I have updated it) and give me an answer in accordance? – vel May 26 '23 at 08:59
  • try `add_library(${PROJECT_NAME} SHARED ${HEADERS} ${SOURCES})`. See https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html#variable:BUILD_SHARED_LIBS. I assume you're getting a static library because you didn't specify SHARED and didn't set BUILD_SHARED_LIBS to a truthy value. – starball May 26 '23 at 09:10
  • @user ok just to modify current add_library definition. We need both static and dynamic library to be produced – vel May 26 '23 at 09:13
  • @user unfortunately error is thrown in this case: `CMake Error: CMake can not determine linker language for target: SystemUtils -- Generating done (1.7s) CMake Generate step failed. Build files cannot be regenerated correctly.` – vel May 26 '23 at 09:24

1 Answers1

0

You can use this CMake command in windows platform:

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

then the import library(.lib file) for your dll will be generated.

Tom
  • 177
  • 7
  • 1
    possibly a bit of a sledgehammer approach, it's unlikely that all symbols need to be exported – Alan Birtles May 26 '23 at 07:05
  • @Tom at what point this command needs to be set on? – vel May 26 '23 at 08:25
  • @AlanBirtles do you have any other proposal if you think this is not suitable? – vel May 26 '23 at 08:25
  • @vel In windows platform, when the `add_library` command did not explicitly state to generate a static library. – Tom May 26 '23 at 08:51
  • sorry I have switched the use case - I am getting .lib but not getting .dll please sorry for mistake. Can you revise your answer? I will update the question..please sorry for this confusion – vel May 26 '23 at 08:56
  • @vel so you want to get both the shared lib(.dll) and static lib(.lib) at the same time? – Tom May 26 '23 at 08:59
  • yes - that is what the development team is expecting from us – vel May 26 '23 at 09:00
  • @vel you can refer to this answer: [Is it possible to get CMake to build both a static and shared library at the same time?](https://stackoverflow.com/questions/2152077/is-it-possible-to-get-cmake-to-build-both-a-static-and-shared-library-at-the-sam) – Tom May 26 '23 at 09:02