Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

cmake - pistache jako biblioteka (submodule)

Ostatnio zmodyfikowano 2019-09-06 07:28
Autor Wiadomość
nicraM
Temat założony przez niniejszego użytkownika
cmake - pistache jako biblioteka (submodule)
» 2019-09-05 20:08:56
Witam.
Chcę wdrożyć się trochę w bibliotekę pistache (http://pistache.io/).

Stworzyłem sobie nowy projekt git w którym będzie kilka zewnętrznych bibliotek i chcę je trzymać w strukturze projektu.
zrobiłem katalog lib do którego wrzuciłem repo gita

git submodule add https://github.com/oktal/pistache.git pistache
cd pistache
git submodule update --init --recursive


do CmakeList.txt dodałem

add_subdirectory(lib/pistache)
find_library(PISTACHE_LIBRARY lpistache)

niestety CLion nie podpowiada mi jak chcę coś zaimportować
#include "pistache/....."

jak powinienem w cmake prawidłowo dodać takie zewnętrzne biblioteki?

dla zobrazowania wrzuciłem na git to co do tej pory zrobiłem
https://github.com/nicraMarcin/sandbox

z góry dziękuję za pomoc

Pozdrawiam

--edit--

w cmake zrobiłem tak:
add_subdirectory(lib/pistache)


add_executable(sandbox src/main.cpp)
target_link_libraries(sandbox pistache)

teraz Clion podpowiada ale próba kompilacji kończy się błędem

====================[ Build | sandbox | Debug ]=================================
/home/marcin/Programs/clion-2019.1.3/bin/cmake/linux/bin/cmake --build /home/marcin/CLionProjects/sandbox/cmake-build-debug --target sandbox -- -j 8
Scanning dependencies of target pistache
[  4%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/cookie.cc.o
[ 14%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/description.cc.o
[ 14%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/http.cc.o
[ 19%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/http_defs.cc.o
[ 23%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/http_header.cc.o
[ 28%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/http_headers.cc.o
[ 33%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/mime.cc.o
[ 38%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/net.cc.o
[ 42%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/os.cc.o
[ 47%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/peer.cc.o
[ 52%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/reactor.cc.o
[ 57%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/stream.cc.o
[ 61%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/tcp.cc.o
[ 66%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/timer_pool.cc.o
[ 71%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/common/transport.cc.o
[ 76%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/server/endpoint.cc.o
[ 80%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/server/listener.cc.o
[ 85%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/server/router.cc.o
[ 90%] Building CXX object lib/pistache/src/CMakeFiles/pistache.dir/client/client.cc.o
[ 90%] Built target pistache
Scanning dependencies of target sandbox
[ 95%] Building CXX object CMakeFiles/sandbox.dir/src/main.cpp.o
[100%] Linking CXX executable sandbox
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/cookie.cc.o: in function `_GLOBAL__sub_I_00100_0_cookie.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/cookie.cc:286: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/cookie.cc.o: in function `_GLOBAL__sub_D_00100_1_cookie.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/cookie.cc:286: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/cookie.cc.o:(.data.rel+0x20): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/description.cc.o: in function `_GLOBAL__sub_I_00100_0_description.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/description.cc:489: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/description.cc.o: in function `_GLOBAL__sub_D_00100_1_description.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/description.cc:489: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/description.cc.o:(.data.rel+0x40): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/http.cc.o: in function `_GLOBAL__sub_I_00100_0_http.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/http.cc:864: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/http.cc.o: in function `_GLOBAL__sub_D_00100_1_http.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/http.cc:864: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/http.cc.o:(.data.rel+0x40): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/http_defs.cc.o: in function `_GLOBAL__sub_I_00100_0_http_defs.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/http_defs.cc:192: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/http_defs.cc.o: in function `_GLOBAL__sub_D_00100_1_http_defs.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/http_defs.cc:192: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/http_defs.cc.o:(.data.rel+0x20): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/http_header.cc.o: in function `_GLOBAL__sub_I_00100_0_http_header.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/http_header.cc:541: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/http_header.cc.o: in function `_GLOBAL__sub_D_00100_1_http_header.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/http_header.cc:541: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/http_header.cc.o:(.data.rel+0x20): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/http_headers.cc.o: in function `_GLOBAL__sub_I_00100_0_http_headers.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/http_headers.cc:211: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/http_headers.cc.o: in function `_GLOBAL__sub_D_00100_1_http_headers.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/http_headers.cc:211: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/http_headers.cc.o:(.data.rel+0x40): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/mime.cc.o: in function `_GLOBAL__sub_I_00100_0_mime.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/mime.cc:333: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/mime.cc.o: in function `_GLOBAL__sub_D_00100_1_mime.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/mime.cc:333: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/mime.cc.o:(.data.rel+0x20): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/net.cc.o: in function `_GLOBAL__sub_I_00100_0_net.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/net.cc:429: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/net.cc.o: in function `_GLOBAL__sub_D_00100_1_net.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/net.cc:429: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/net.cc.o:(.data.rel+0x20): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/os.cc.o: in function `_GLOBAL__sub_I_00100_0_os.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/os.cc:299: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/os.cc.o: in function `_GLOBAL__sub_D_00100_1_os.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/os.cc:299: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/os.cc.o:(.data.rel+0x20): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/peer.cc.o: in function `_GLOBAL__sub_I_00100_0_peer.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/peer.cc:149: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/peer.cc.o: in function `_GLOBAL__sub_D_00100_1_peer.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/peer.cc:149: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/peer.cc.o:(.data.rel+0x40): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/reactor.cc.o: in function `_GLOBAL__sub_I_00100_0_reactor.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/reactor.cc:614: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/reactor.cc.o: in function `_GLOBAL__sub_D_00100_1_reactor.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/reactor.cc:614: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/reactor.cc.o:(.data.rel+0x40): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/reactor.cc.o: in function `Pistache::Aio::AsyncImpl::Worker::run()::{lambda()#1}::operator()() const':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/reactor.cc:470: undefined reference to `pthread_setname_np'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/reactor.cc.o: in function `std::thread::thread<Pistache::Aio::AsyncImpl::Worker::run()::{lambda()#1}, , void>(Pistache::Aio::AsyncImpl::Worker::run()::{lambda()#1}&&)':
/usr/include/c++/8/thread:127: undefined reference to `pthread_create'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/stream.cc.o: in function `_GLOBAL__sub_I_00100_0_stream.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/stream.cc:303: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/stream.cc.o: in function `_GLOBAL__sub_D_00100_1_stream.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/stream.cc:303: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/stream.cc.o:(.data.rel+0x20): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/tcp.cc.o: in function `_GLOBAL__sub_I_00100_0_tcp.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/tcp.cc:37: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/tcp.cc.o: in function `_GLOBAL__sub_D_00100_1_tcp.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/tcp.cc:37: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/tcp.cc.o:(.data.rel+0x20): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/timer_pool.cc.o: in function `_GLOBAL__sub_I_00100_0_timer_pool.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/timer_pool.cc:111: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/timer_pool.cc.o: in function `_GLOBAL__sub_D_00100_1_timer_pool.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/timer_pool.cc:111: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/timer_pool.cc.o:(.data.rel+0x40): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/transport.cc.o: in function `_GLOBAL__sub_I_00100_0_transport.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/transport.cc:479: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/transport.cc.o: in function `_GLOBAL__sub_D_00100_1_transport.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/common/transport.cc:479: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/common/transport.cc.o:(.data.rel+0x40): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/server/endpoint.cc.o: in function `_GLOBAL__sub_I_00100_0_endpoint.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/server/endpoint.cc:149: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/server/endpoint.cc.o: in function `_GLOBAL__sub_D_00100_1_endpoint.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/server/endpoint.cc:149: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/server/endpoint.cc.o:(.data.rel+0x40): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/server/listener.cc.o: in function `std::thread::thread<Pistache::Tcp::Listener::runThreaded()::{lambda()#1}, , void>(Pistache::Tcp::Listener::runThreaded()::{lambda()#1}&&)':
/usr/include/c++/8/thread:127: undefined reference to `pthread_create'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/server/listener.cc.o: in function `_GLOBAL__sub_I_00100_0_listener.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/server/listener.cc:499: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/server/listener.cc.o: in function `_GLOBAL__sub_D_00100_1_listener.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/server/listener.cc:499: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/server/listener.cc.o:(.data.rel+0x40): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/server/router.cc.o: in function `_GLOBAL__sub_I_00100_0_router.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/server/router.cc:522: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/server/router.cc.o: in function `_GLOBAL__sub_D_00100_1_router.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/server/router.cc:522: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/server/router.cc.o:(.data.rel+0x40): undefined reference to `__gcov_merge_add'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/client/client.cc.o: in function `_GLOBAL__sub_I_00100_0_client.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/client/client.cc:941: undefined reference to `__gcov_init'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/client/client.cc.o: in function `_GLOBAL__sub_D_00100_1_client.cc':
/home/marcin/CLionProjects/sandbox/lib/pistache/src/client/client.cc:941: undefined reference to `__gcov_exit'
/usr/bin/ld: lib/pistache/src/CMakeFiles/pistache.dir/client/client.cc.o:(.data.rel+0x40): undefined reference to `__gcov_merge_add'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/sandbox.dir/build.make:122: sandbox] Błąd 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/sandbox.dir/all] Błąd 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/sandbox.dir/rule] Błąd 2
make: *** [Makefile:186: sandbox] Błąd 2



samo pistache na tym systamie kompiluje się bez problemu.


P-175165
pekfos
» 2019-09-05 22:21:17
Wygląda jakbyś miał włączone coverage testy dla Pistache. Jeśli to naprawdę jest twoją intencją, to musisz jeszcze dodać opcję linkera -lgcov.
P-175167
nicraM
Temat założony przez niniejszego użytkownika
» 2019-09-06 07:28:40
Dzięki za podpowiedź. Dodanie właśnie coverage do kompilatora rozwiązało problem

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")

Mam jeszcze jeden dylemat. Mianowicie oprócz Pistache chcę użyć ORMa ODB (https://www.codesynthesis.com/products/odb/), chyba że ktoś poleci coś lepszego, też jako submoduły (https://git.codesynthesis.com/cgit/odb/). Problem polega na tym, że one nie mają CmakeLists.txt i trzeba je kompilować ręcznie. Nie jest to wielki problem ale skoro już założyłem ten wątek to zapytam. Czy da się jakoś wygenerować CmakeLists.txt dla tych submodułów by się kompilowały podczas uruchamiania głównego projektu?

Do repo na git dodałem skompilowane biblioteki libodb, libodb-pgsql. Jak je "wskazać" w CmakeLists.txt by były widziane w projekcie?
P-175168
« 1 »
  Strona 1 z 1