CMake没有制定目标的规则'使用外部库

时间:2015-07-08 10:54:22

标签: c++ cmake makefile libevent

我正在尝试将我的一个程序链接到libevent。我使用CMake作为构建系统。我的项目结构如下:

my_project
├── CMakeLists.txt
├── README.md
├── build
│   └── Build stuff
└── software
    ├── README.md
    ├── CMakeLists.txt
    ├── include
    ├── libraries
    │   ├── libevent
    │   │   └── CMakeLists.txt
    │   └── anotherlibrary
    │       └── CMakeLists.txt
    ├── prog1
    │   ├── CMakeLists.txt
    ├── prog2
    │   ├── CMakeLists.txt
    └── prog3
        └── CMakeLists.txt

prog1的CMakeList.txt(需要链接到libevent的那个)

cmake_minimum_required(VERSION 2.6)
project (prog1)

file(GLOB prog1
    "*.h"
    "*.cpp"
)

include_directories("${PROJECT_INCLUDE_DIR}/libevent/include")

add_executable(${PROJECT_NAME} ${prog1})
target_link_libraries(${PROJECT_NAME} event_core)

但是当我构建项目时,make无法通过libevent找到库构建。它搜索了:libraries/libevent/lib/libevent_core.a这是错误的路径,因为libevent在其中构建libs:my_project/build/software/libraries/libevent/lib/libevent_core.a

如何告诉CMake在那里搜索图书馆?我已经将以下行添加到我的Cmake文件中,但这不起作用

    link_directories(/my_project/build/software/libraries/libevent/lib/)

    SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/lib)
    SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build/bin)

有人提出建议吗?

1 个答案:

答案 0 :(得分:1)

我通过从cmake ..目录中删除内容并在build目录中重新运行<dom-module id="dom-element"> <template> <custom-element bindingTest="{{found}}"></custom-element> </template> <script> Polymer({ is: "dom-element", properties: { found: { type:String, value:"4" } }, ready: function() { this.addEventListener("found-changed", this.foundChanged); }, foundChanged:function(e){ console.log("found changed"); } }); </script> </dom-module> 来自行解决问题。

我认为CMake不知道我做了哪些改变,通过重建项目,问题得到解决。