2016-08-17 2 views
1

이전에 컴파일 된 libgarithm.a 라이브러리가 있고, 헤더 파일 garith.h가 있습니다. 어떻게하면 cmake 프로젝트에서 가져올 수 있습니까? include_directories ("/ home/gaurav/Desktop/garith-lib/include")의 헤더 파일을 포함했지만 라이브러리를 연결할 수 없으며 comile time 오류가 발생했습니다 ---`multi (int, int)를 '내 라이브러리 함수는cmake에 외부의 이전 빌드 .a 라이브러리를 포함 할 수 없습니다.

답변

2

당신은 당신의 라이브러리에 대한 imported target를 만든 다음 target_link_libraries 사용한다 : 전화를하지 않아도

add_library(garithm STATIC IMPORTED) 
set_property(TARGET garithm PROPERTY IMPORTED_LOCATION 
    /path/to/libgarithm.a 
) 
set_property(TARGET garithm PROPERTY INTERFACE_INCLUDE_DIRECTORIES 
    /home/gaurav/Desktop/garith-lib/include 
) 

... 

add_executable(foo main.cpp) 
target_link_libraries(foo garithm) 

이 디렉토리뿐만 아니라 수입 대상에서 선언을 포함 include_directories

편집 :target_include_directories 대신

+0

가 대단히 감사하지만 지금은 오류가 점점 오전 재산 INTERFACE_INCLUDE_DIRECTORIES을 설정, 수입 목표 작동하지 않습니다 - : 오류 : 수입 대상 "garithm"에 대한 디렉토리를 포함 지정할 수 없습니다. –

+0

내 대답을 편집했습니다. 'target_include_directories'를 사용하고 있습니까, 아니면 'INTERFACE_INCLUDE_DIRECTORIES' 속성을 설정하고 있습니까? – wasthishelpful

관련 문제