{"id":2255,"date":"2019-10-01T09:10:57","date_gmt":"2019-10-01T06:10:57","guid":{"rendered":"http:\/\/demensdeum.com\/blog\/?p=2255"},"modified":"2024-12-16T22:32:34","modified_gmt":"2024-12-16T19:32:34","slug":"shared-library-cmake-c","status":"publish","type":"post","link":"https:\/\/demensdeum.com\/blog\/pt\/2019\/10\/01\/shared-library-cmake-c\/","title":{"rendered":"Biblioteca Compartilhada CMake C++"},"content":{"rendered":"<p>Recentemente, decidi separar todas as partes do FlameSteelFramework em bibliotecas compartilhadas. Depois, mostrarei um exemplo de um arquivo CMakeLists.txt para <a href=\"https:\/\/gitlab.com\/demensdeum\/FlameSteelCore\" target=\" _blank\" rel=\"noopener noreferrer\"> FlameSteelCore<\/a>:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>cmake_minimum_required(VERSION 3.5)\n\nproject (FlameSteelCore)\nset(CMAKE_BUILD_TYPE Release)\n\ninclude_directories(${CMAKE_CURRENT_SOURCE_DIR}\/src)\n\nfile(GLOB_RECURSE SOURCE_FILES\n    \"src\/FlameSteelCore\/*.cpp\"\n)\n\nadd_library(FlameSteelCore SHARED ${SOURCE_FILES})\n\ninstall(DIRECTORY \"${CMAKE_SOURCE_DIR}\/src\/FlameSteelCore\"\n        DESTINATION include\/FlameSteelFramework\n        FILES_MATCHING\n        PATTERN \"*.h\"\n)\n\ninstall(TARGETS FlameSteelCore DESTINATION lib)\n<\/code><\/pre>\n<\/div>\n<p>Comandos que o CMake executa: coleta todos os arquivos com extens\u00e3o *.cpp do diret\u00f3rio src\/FlameSteelCore\/ em uma biblioteca compartilhada, copia todos os cabe\u00e7alhos com extens\u00e3o *.h de src\/FlameSteelCore para include\/FlameSteelFramework (no meu caso este \u00e9 \/usr\/local\/include\/FlameSteelFramework), copia a lib compartilhada para o diret\u00f3rio lib (\/usr\/local\/lib)<br \/>Ap\u00f3s a instala\u00e7\u00e3o, pode ser necess\u00e1rio atualizar o cache LD &#8211; sudoldconfig.<br \/>Para compilar e instalar no Ubuntu (se voc\u00ea tiver o conjunto de ferramentas de compila\u00e7\u00e3o correto), basta executar os seguintes comandos:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>cmake . && make && sudo make install\n<\/code><\/pre>\n<\/div>\n<p>Para testar o processo de instala\u00e7\u00e3o, passo make prefix para a pasta local makeInstallTestPlayground:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>cmake -DCMAKE_INSTALL_PREFIX:PATH=\/home\/demensdeum\/makeInstallTestPlayground . && make && make install\n<\/code><\/pre>\n<\/div>\n<h3>Refer\u00eancias<\/h3>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/17511496\/how-to-create-a-shared-library-with-cmake\" target=\"_blank\" rel=\"noopener noreferrer\">https: \/\/stackoverflow.com\/questions\/17511496\/how-to-create-a-shared-library-with-cmake<\/a><br \/><a href=\"https:\/\/stackoverflow.com\/questions\/6003374\/what-is-cmake-equivalent-of-configure-prefix-dir-make-all-install\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/stackoverflow.com\/questions\/6003374\/what-is-cmake-equivalent-of-configure-prefix-dir-make-all-install<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recentemente, decidi separar todas as partes do FlameSteelFramework em bibliotecas compartilhadas. Depois, mostrarei um exemplo de um arquivo CMakeLists.txt para FlameSteelCore: cmake_minimum_required(VERSION 3.5) project (FlameSteelCore) set(CMAKE_BUILD_TYPE Release) include_directories(${CMAKE_CURRENT_SOURCE_DIR}\/src) file(GLOB_RECURSE SOURCE_FILES &#8220;src\/FlameSteelCore\/*.cpp&#8221; ) add_library(FlameSteelCore SHARED ${SOURCE_FILES}) install(DIRECTORY &#8220;${CMAKE_SOURCE_DIR}\/src\/FlameSteelCore&#8221; DESTINATION include\/FlameSteelFramework FILES_MATCHING PATTERN &#8220;*.h&#8221; ) install(TARGETS FlameSteelCore DESTINATION lib) Comandos que o CMake executa: coleta todos os<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/pt\/2019\/10\/01\/shared-library-cmake-c\/\">Continue reading <span class=\"screen-reader-text\">&#8220;Biblioteca Compartilhada CMake C++&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[61,52],"tags":[124,122,123],"class_list":["post-2255","post","type-post","status-publish","format-standard","hentry","category-techie","category-tutorials","tag-c","tag-cmake","tag-shared-lib","entry"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"pt","enabled_languages":["en","ru","zh","de","fr","ja","pt","hi"],"languages":{"en":{"title":true,"content":true,"excerpt":false},"ru":{"title":true,"content":true,"excerpt":false},"zh":{"title":true,"content":true,"excerpt":false},"de":{"title":true,"content":true,"excerpt":false},"fr":{"title":true,"content":true,"excerpt":false},"ja":{"title":true,"content":true,"excerpt":false},"pt":{"title":true,"content":true,"excerpt":false},"hi":{"title":false,"content":false,"excerpt":false}}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/demensdeum.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/2255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demensdeum.com\/blog\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demensdeum.com\/blog\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/pt\/wp-json\/wp\/v2\/comments?post=2255"}],"version-history":[{"count":12,"href":"https:\/\/demensdeum.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/2255\/revisions"}],"predecessor-version":[{"id":3940,"href":"https:\/\/demensdeum.com\/blog\/pt\/wp-json\/wp\/v2\/posts\/2255\/revisions\/3940"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/pt\/wp-json\/wp\/v2\/media?parent=2255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/pt\/wp-json\/wp\/v2\/categories?post=2255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/pt\/wp-json\/wp\/v2\/tags?post=2255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}