在CMake中链接共享库时发生错误

时间:2015-01-09 10:30:21

标签: c cmake

我在学习CMake。我做了一个简单的测试,如下所示:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(MAIN) 
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) 
LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_LIB}/lib) 
TARGET_LINK_LIBRARIES(main hello)
ADD_EXECUTABLE(main main.c)

CMakeLists.txt的代码。我运行它但报告错误:

CMake Error at CMakeLists.txt:9 (TARGET_LINK_LIBRARIES): 
Cannot specify link libraries for target "main" which is not built by this 
project

main.c中:

#include "stdio.h"
#include "hello.h"

int main() 
{ 
  HelloFunc(); 
  return 0;
}

0 个答案:

没有答案