{"id":999,"date":"2022-08-30T15:10:42","date_gmt":"2022-08-30T15:10:42","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/how-to-change-a-cmake-file-to-produce-a-dll-instead-of-static-lib-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:10:42","modified_gmt":"2022-08-30T15:10:42","slug":"how-to-change-a-cmake-file-to-produce-a-dll-instead-of-static-lib-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-change-a-cmake-file-to-produce-a-dll-instead-of-static-lib-collection-of-common-programming-errors\/","title":{"rendered":"How to change a CMake file to produce a dll instead of static lib?-Collection of common programming errors"},"content":{"rendered":"<p>I am working on a project where I have to use JRTP (Jori Real Time Tranfer Protocol) library. I m using the version 3.9.1 of the library. When I tried to compile that library I used the following CmakeLists.txt file. But It produces some errors like<\/p>\n<pre><code>C:\/Program Files\/CMake 2.8\/share\/cmake-2.8\/Modules\/GenerateExportHeader.cmake:339 (get_property): get_property could not find TARGET jrtplib}.  Perhaps it has not yet been created.\nerror PRJ0019: A tool returned an error code from \"Building Custom Rule C:\/projects\/jrtplib-3.9.1\/CMakeLists.txt\"\n<\/code><\/pre>\n<p>But I want it to produce dll(dynamic link library). What change I have to make in that file? And what I have to do in Visual studio after building the project?<\/p>\n<pre><code>cmake_minimum_required(VERSION 2.6)\n\nproject(jrtplib)\nset(VERSION 3.9.1)\n\nset(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} \"${PROJECT_SOURCE_DIR}\/cmake\")\n\nset (_DEFAULT_LIBRARY_INSTALL_DIR lib)\nif (EXISTS \"${CMAKE_INSTALL_PREFIX}\/lib32\/\" AND CMAKE_SIZEOF_VOID_P EQUAL 4)\n    set (_DEFAULT_LIBRARY_INSTALL_DIR lib32)\nelseif (EXISTS \"${CMAKE_INSTALL_PREFIX}\/lib64\/\" AND CMAKE_SIZEOF_VOID_P EQUAL 8)\n    set (_DEFAULT_LIBRARY_INSTALL_DIR lib64)\nendif ()\n\nset(LIBRARY_INSTALL_DIR \"${_DEFAULT_LIBRARY_INSTALL_DIR}\" CACHE PATH \"Library installation directory\")\nif(NOT IS_ABSOLUTE \"${LIBRARY_INSTALL_DIR}\")\n    set(LIBRARY_INSTALL_DIR \"${CMAKE_INSTALL_PREFIX}\/${LIBRARY_INSTALL_DIR}\")\nendif()\n\ninclude(CheckCXXCompilerFlag)\ninclude(CheckIncludeFile)\ninclude(CheckIncludeFileCXX)\ninclude(CheckCXXSourceCompiles)\ninclude(TestBigEndian)\ninclude(${PROJECT_SOURCE_DIR}\/cmake\/Macros.cmake)\n\n\nfind_package(JThread)\n\nset(JRTPLIB_LINK_LIBS \"\")\nset(JRTPLIB_INTERNAL_INCLUDES \"\")\nset(JRTPLIB_EXTERNAL_INCLUDES \"\")\n\nadd_additional_stuff(JRTPLIB_EXTERNAL_INCLUDES JRTPLIB_LINK_LIBS)\nadd_library(jrtplib ${MODULE} ${PROJECT_SOURCE_DIR}\/include)\nGENERATE_EXPORT_HEADER( jrtplib} \n         BASE_NAME jrtplib\n         EXPORT_MACRO_NAME jrtplib_EXPORT\n         EXPORT_FILE_NAME jrtplib_Export.h\n         STATIC_DEFINE jrtplib_BUILT_AS_STATIC\njrtplib_support_option(\"Support SDES PRIV items\" JRTPLIB_SUPPORT_SDESPRIV RTP_SUPPORT_SDESPRIV ON \"\/\/ No support for SDES PRIV items\")\njrtplib_support_option(\"Support the probation mechanism for a new source\" JRTPLIB_SUPPORT_PROBATION RTP_SUPPORT_PROBATION ON \"\/\/ Do not wait for a number of consecutive packets to validate source\")\njrtplib_support_option(\"Support sending RTCP APP packets\" JRTPLIB_SUPPORT_SENDAPP RTP_SUPPORT_SENDAPP ON \"\/\/ No direct support for sending RTCP APP packets\")\njrtplib_support_option(\"Support sending unknown RTCP packets\" JRTPLIB_SUPPORT_RTCPUNKNOWN RTP_SUPPORT_RTCPUNKNOWN OFF \"\/\/ No support for sending unknown RTCP packets\")\njrtplib_support_option(\"Support memory management mechanism\" JRTPLIB_SUPPORT_MEMORYMGMT RTP_SUPPORT_MEMORYMANAGEMENT ON \"\/\/ No memory management support\")\n\njrtplib_include_test(sys\/filio.h RTP_HAVE_SYS_FILIO \"\/\/ Don't have \")\njrtplib_include_test(sys\/sockio.h RTP_HAVE_SYS_SOCKIO \"\/\/ Don't have \")\njrtplib_include_test(ifaddrs.h RTP_SUPPORT_IFADDRS \"\/\/ No ifaddrs support\")\n\nif (JTHREAD_FOUND)\n    set(V \"ON\")\nelse (JTHREAD_FOUND)\n    set(V \"OFF\")\nendif (JTHREAD_FOUND)\n\noption(JTHREAD_ENABLED \"Thread support\" ${V})\nif (JTHREAD_ENABLED)\n    set (RTP_SUPPORT_THREAD \"#define RTP_SUPPORT_THREAD\")\n    if (JTHREAD_FOUND)\n        save_paths(JRTPLIB_EXTERNAL_INCLUDES \"${JTHREAD_INCLUDE_DIRS}\")\n        save_paths(JRTPLIB_LINK_LIBS \"${JTHREAD_LIBRARIES}\")\n    endif(JTHREAD_FOUND)\nelse (JTHREAD_ENABLED)\n    set (RTP_SUPPORT_THREAD \"\/\/ No support for JThread was enabled\")\nendif (JTHREAD_ENABLED)\n\nif (CMAKE_CROSSCOMPILING)\n    option (JRTPLIB_USE_BIGENDIAN \"Target platform is big endian\" ON)\n    if (JRTPLIB_USE_BIGENDIAN)\n        set(RTP_ENDIAN \"#define RTP_BIG_ENDIAN\")\n    else (JRTPLIB_USE_BIGENDIAN)\n        set(RTP_ENDIAN \"\/\/ Little endian system\")\n    endif (JRTPLIB_USE_BIGENDIAN)\nelse (CMAKE_CROSSCOMPILING)\n    test_big_endian(JRTPLIB_BIGENDIAN)\n    if (JRTPLIB_BIGENDIAN)\n        set(RTP_ENDIAN \"#define RTP_BIG_ENDIAN\")\n    else (JRTPLIB_BIGENDIAN)\n        set(RTP_ENDIAN \"\/\/ Little endian system\")\n    endif (JRTPLIB_BIGENDIAN)\nendif (CMAKE_CROSSCOMPILING)\n\njrtplib_test_feature(socklentest RTP_SOCKLENTYPE_UINT TRUE \"\/\/ socklen_t is 'int'\")\njrtplib_test_feature(ipv4mcasttest RTP_SUPPORT_IPV4MULTICAST FALSE \"\/\/ No IPv4 multicasting support\")\njrtplib_test_feature(salentest RTP_HAVE_SOCKADDR_LEN FALSE \"\/\/ No sa_len member in struct sockaddr\")\njrtplib_test_feature(getloginrtest RTP_SUPPORT_GETLOGINR FALSE \"\/\/ Not using getlogin_r\")\njrtplib_test_feature(ipv6test RTP_SUPPORT_IPV6 FALSE \"\/\/ No IPv6 support\")\njrtplib_test_feature(ipv6mcasttest RTP_SUPPORT_IPV6MULTICAST FALSE \"\/\/ No IPv6 multicasting support\")\n\ncheck_cxx_source_compiles(\"#include \\n#include \\nint main(void) { size_t a = 0 ; size_t b = a; uint32_t x = 0; uint32_t y = x; return 0; }\" JRTPLIB_STDINT)\nif (JRTPLIB_STDINT)\n    set(RTP_INTTYPE_HEADERS \"#include \\n#include \")\nelse (JRTPLIB_STDINT)\n    check_cxx_source_compiles(\"#include \\n#include \\nint main(void) { uint32_t x = 0; uint32_t y = x; return 0; }\" JRTPLIB_INTTYPES)\n    if (JRTPLIB_INTTYPES)\n        set(RTP_INTTYPE_HEADERS \"#include \\n#include \\n\")\n    else (JRTPLIB_INTTYPES)\n        if (NOT UNIX AND WIN32)\n            set(RTP_INTTYPE_HEADERS \"#include \\\"rtptypes_win.h\\\"\")\n        else (NOT UNIX AND WIN32)\n            set(RTP_INTTYPE_HEADERS \"#error Could not find header files that define types like 'uint32_t'. Please edit the file ${PROJECT_BINARY_DIR}\/src\/rtptypes_unix.h and make sure that the following types are defined: int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t\")\n            message(\"\\n\\nError: Could not find header files that define types like 'uint32_t'.\\nPlease edit the file ${PROJECT_BINARY_DIR}\/src\/rtptypes_unix.h\\nand make sure that the following types are defined: \\nint8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t\\n\\n\")\n        endif (NOT UNIX AND WIN32)\n    endif (JRTPLIB_INTTYPES)\nendif (JRTPLIB_STDINT)\n\nif (NOT UNIX AND WIN32)\n    set(RTP_WINSOCK_HEADERS \"#if defined(WIN32) || defined(_WIN32_WCE)\\n    #include    \\n  #include \\n#ifndef _WIN32_WCE\\n #include \\n#endif \/\/ _WIN32_WCE\\n#endif \/\/ WIN32 || _WIN32_WCE\\n\")\nendif (NOT UNIX AND WIN32)\n\nif (NOT UNIX)\n    set(JRTPLIB_COMPILE_STATIC ON CACHE BOOL \"Flag indicating if a static library should be built, or a dynamic one\")\n    list(APPEND JRTPLIB_LINK_LIBS \"ws2_32\")\nendif (NOT UNIX)\n\nif (UNIX OR JRTPLIB_COMPILE_STATIC)\n    set(JRTPLIB_IMPORT \"\")\n    set(JRTPLIB_EXPORT \"\")\nelse (UNIX OR JRTPLIB_COMPILE_STATIC)\n    set(JRTPLIB_IMPORT \"__declspec(dllimport)\")\n    set(JRTPLIB_EXPORT \"__declspec(dllexport)\")\nendif (UNIX OR JRTPLIB_COMPILE_STATIC)\n\nconfigure_file(\"${PROJECT_SOURCE_DIR}\/src\/rtptypes.h.in\" \"${PROJECT_BINARY_DIR}\/src\/rtptypes.h\")\nconfigure_file(\"${PROJECT_SOURCE_DIR}\/src\/rtpconfig.h.in\" \"${PROJECT_BINARY_DIR}\/src\/rtpconfig.h\")\n\nsave_paths(JRTPLIB_INTERNAL_INCLUDES \"${PROJECT_SOURCE_DIR}\/src\" \"${PROJECT_BINARY_DIR}\/src\")\n\nadd_subdirectory(src)\nadd_subdirectory(examples)\n\nif (UNIX)\n    get_target_property(JRTPLIB_LOCAL_LIBRARY_NAME jrtplib-shared LOCATION)\n    get_filename_component(JRTPLIB_LIBNAME \"${JRTPLIB_LOCAL_LIBRARY_NAME}\" NAME)\n    set(JRTPLIB_LIBS \"${LIBRARY_INSTALL_DIR}\/${JRTPLIB_LIBNAME}\")\nelse (UNIX)\n    if (JRTPLIB_COMPILE_STATIC)\n        get_target_property(JRTPLIB_LOCAL_LIBRARY_NAME jrtplib-static RELEASE_LOCATION)\n        get_filename_component(JRTPLIB_LIBNAME_RELEASE \"${JRTPLIB_LOCAL_LIBRARY_NAME}\" NAME_WE)\n        get_target_property(JRTPLIB_LOCAL_LIBRARY_NAME jrtplib-static DEBUG_LOCATION)\n        get_filename_component(JRTPLIB_LIBNAME_DEBUG \"${JRTPLIB_LOCAL_LIBRARY_NAME}\" NAME_WE)\n    else (JRTPLIB_COMPILE_STATIC)\n        get_target_property(JRTPLIB_LOCAL_LIBRARY_NAME jrtplib-shared RELEASE_LOCATION)\n        get_filename_component(JRTPLIB_LIBNAME_RELEASE \"${JRTPLIB_LOCAL_LIBRARY_NAME}\" NAME_WE)\n        get_target_property(JRTPLIB_LOCAL_LIBRARY_NAME jrtplib-shared DEBUG_LOCATION)\n        get_filename_component(JRTPLIB_LIBNAME_DEBUG \"${JRTPLIB_LOCAL_LIBRARY_NAME}\" NAME_WE)\n    endif (JRTPLIB_COMPILE_STATIC)\n    set(JRTPLIB_LIBS optimized \"${LIBRARY_INSTALL_DIR}\/${JRTPLIB_LIBNAME_RELEASE}.lib\" \n                 debug \"${LIBRARY_INSTALL_DIR}\/${JRTPLIB_LIBNAME_DEBUG}.lib\")\nendif (UNIX)\n\nset(JRTPLIB_INCDIRS ${JRTPLIB_EXTERNAL_INCLUDES} ${CMAKE_INSTALL_PREFIX}\/include)\nset(JRTPLIB_LIBS ${JRTPLIB_LIBS} ${JRTPLIB_LINK_LIBS})\nremove_empty(JRTPLIB_INCDIRS)\nlist(REMOVE_DUPLICATES JRTPLIB_INCDIRS)\nremove_empty(JRTPLIB_LIBS)\n\nforeach(ARG ${JRTPLIB_LIBS})\n    set(JRTPLIB_LIBS_CMAKECONFIG \"${JRTPLIB_LIBS_CMAKECONFIG} \\\"${ARG}\\\"\")\nendforeach()\nforeach(ARG ${JRTPLIB_INCDIRS})\n    set(JRTPLIB_INCDIRS_CMAKECONFIG \"${JRTPLIB_INCDIRS_CMAKECONFIG} \\\"${ARG}\\\"\")\nendforeach()\n\nconfigure_file(\"${PROJECT_SOURCE_DIR}\/cmake\/JRTPLIBConfig.cmake.in\" \"${PROJECT_BINARY_DIR}\/cmake\/JRTPLIBConfig.cmake\")\ninstall(FILES \"${PROJECT_BINARY_DIR}\/cmake\/JRTPLIBConfig.cmake\" DESTINATION ${LIBRARY_INSTALL_DIR}\/cmake\/JRTPLIB)\n\nif (UNIX)\n    foreach(ARG ${JRTPLIB_LIBS})\n        set(JRTPLIB_LIBS_PKGCONFIG \"${JRTPLIB_LIBS_PKGCONFIG} ${ARG}\")\n    endforeach()\n    foreach(ARG ${JRTPLIB_INCDIRS})\n        set(JRTPLIB_INCDIRS_PKGCONFIG \"${JRTPLIB_INCDIRS_PKGCONFIG} -I${ARG}\")\n    endforeach()\n\n    configure_file(${PROJECT_SOURCE_DIR}\/pkgconfig\/jrtplib.pc.in ${PROJECT_BINARY_DIR}\/pkgconfig\/jrtplib.pc)\n    install(FILES ${PROJECT_BINARY_DIR}\/pkgconfig\/jrtplib.pc DESTINATION ${LIBRARY_INSTALL_DIR}\/pkgconfig)\nendif (UNIX)\n<\/code><\/pre>\n<ol>\n<li>\n<p>You seem to have a syntax error there:<\/p>\n<pre><code>GENERATE_EXPORT_HEADER( jrtplib} \n         BASE_NAME jrtplib\n         EXPORT_MACRO_NAME jrtplib_EXPORT\n         EXPORT_FILE_NAME jrtplib_Export.h\n         STATIC_DEFINE jrtplib_BUILT_AS_STATIC\n<\/code><\/pre>\n<p>A &#8216;}&#8217; after target name and there is no &#8216;)&#8217;.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:12:05. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am working on a project where I have to use JRTP (Jori Real Time Tranfer Protocol) library. I m using the version 3.9.1 of the library. When I tried to compile that library I used the following CmakeLists.txt file. But It produces some errors like C:\/Program Files\/CMake 2.8\/share\/cmake-2.8\/Modules\/GenerateExportHeader.cmake:339 (get_property): get_property could not find TARGET [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-999","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=999"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/999\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}