Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

358
Visualizações
How cmake judging target_link_libraries item is a library name or a target?

I have some troubles in cmake target_link_libraries function. In my case,there are three projects like this,which means A depends on B,B depends on C

A(exec) --> B(static library) --> C(static library alias C::C)

I write a CMakeLists.txt for B like this:

find_package(C REUQIRED)
add_library(B ...)
target_link_libraries(B PRIVATE C::C)

And it works well ,complie successfully. A's cmake file like this:

find_package(B REQUIRED)
add_exectuable(A ...)
target_link_libraries(A B)

It reports error when linking A,cmake set a linker flags "-lC::C",and then ld said C::C not exist. How it happend?I think C::C is a target and A should know it,but cmake think it is a library name.And I think A should not know B depends on C,it's a private library.

I don't want to write find_packge(C) in A's cmake,because C is a static library,I think B should handle all dependcies of C,that's right?

So anyone knows how to fix it ?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I solved this problem finally. In my case,B using C's funtion in template code,and B does not instantiate this template,so C::C would not link into B's static library.But A would instantiate B's template,so A need C::C,that's why B's PRIVATE flag was useless.

In order to help A found the C::C,I should use find_depecncy(C) in B's config.cmake to let A knows B's depency when use find_package(B).

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda