Ho un eseguibile e una libreria condivisa nel mio progetto. La libreria condivisa utilizza la libreria boost. l'eseguibile usa olny la libreria condivisa.Collegamento boost alla libreria condivisa con CMake su Linux
tilenet/ <-- Project
ttest/ <-- Test (executable)
CMakeLists.txt
tilenet/ <-- The shared library
CMakeLists.txt
CMakeLists.txt <-- Root CMake-file
Root cmake-File:
cmake_minimum_required(VERSION 2.6)
project(tilenet)
set(Boost_USE_STATIC_LIBS OFF) # I've already tried ON
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.49 COMPONENTS system filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
add_subdirectory(test)
add_subdirectory(tilenet)
ttest/CMakeLists.txt
add_executable(ttest test.cpp)
target_link_libraries(ttest tilenet ${BOOST_LIBRARIES})
tilenet/CMakeLists.txt
include_directories("include")
set(tilenet_src "src/tilenet.cpp" ...)
add_library(tilenet SHARED ${tilenet_src})
target_link_libraries(tilenet
${SFML_LIBRARIES}
${BOOST_LIBRARIES}
)
(ho tagliato un po 'poco importante roba)
Su Windows funziona bene (ma non io uso VisuelStudio senza CMake), ma su linux ricevo seguenti errori di collegamento:
../../lib/libtilenet.so: undefined reference to `boost::filesystem3::path_traits::convert(wchar_t const*, wchar_t const*, std::string&, std::codecvt<wchar_t, char, __mbstate_t> const&)'
../../lib/libtilenet.so: undefined reference to `boost::filesystem3::path::operator/=(boost::filesystem3::path const&)'
../../lib/libtilenet.so: undefined reference to `boost::system::system_category()'
../../lib/libtilenet.so: undefined reference to `boost::filesystem3::path::wchar_t_codecvt_facet()'
../../lib/libtilenet.so: undefined reference to `boost::system::generic_category()'
../../lib/libtilenet.so: undefined reference to `boost::filesystem3::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, __mbstate_t> const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [../bin/ttest] Error 1
make[1]: *** [test/CMakeFiles/ttest.dir/all] Error 2
make: *** [all] Error 2
che ho provato un sacco di combinazioni con determinate opzioni, ma io non era in grado di collegarlo. Sai dove ho fatto degli errori? Questa è la prima volta che uso CMake seriamente :)
ok ora posso compilare tutto (e ottenere un errore di segmentazione;) nerver mente), ma devo collegare spinta al file eseguibile TEST.T. È possibile nascondere boost all'interno della libreria condivisa? – Databyte
Non sai cosa intendi. Una volta specificate le librerie boost come dipendenza da 'tilenet', ogni volta che si specifica' tilenet' come dipendenza di un altro bersaglio, CMake identifica automaticamente le librerie boost come ulteriori dipendenze. In altre parole, non è necessario elencare esplicitamente '$ {BOOST_LIBRARIES}' in un'altra chiamata 'target_link_libraries' se contiene già' tilenet'. – Fraser
ok suona bene grazie – Databyte