cmake 链接 纯C编写的 *.a 静态库

#cmake 配置

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
	set(_lib_suffix 64)
else()
	set(_lib_suffix 32)
endif()

include_directories(${CMAKE_SOURCE_DIR}/lib)	

find_library(XXX_LIB
		    xxxx${_lib_suffix}.a 
		    ${CMAKE_SOURCE_DIR}/lib)
	
add_executable(${PROJECT_NAME}  main.cpp)
		
target_link_libraries(${PROJECT_NAME}  ${XXX_LIB})
// 头文件需要添加 extern "C" 标识,否则会出现“未定义的引用”的错误
#ifdef __cplusplus
extern "C"
{
#endif


#ifdef __cplusplus
}
#endif

猜你喜欢

转载自blog.csdn.net/sinat_31964903/article/details/84891723