2016-07-06 62 views
0

我是新的cmake。 与cmake我能够在我的笔记本电脑上编译我的项目,但在树莓不起作用。CMake不能在树莓编译

这是错误我得到树莓:

-- The C compiler identification is GNU 4.9.2 
-- The CXX compiler identification is GNU 4.9.2 
-- Check for working C compiler: /usr/bin/cc 
-- Check for working C compiler: /usr/bin/cc -- works 
-- Detecting C compiler ABI info 
-- Detecting C compiler ABI info - done 
-- Check for working CXX compiler: /usr/bin/c++ 
-- Check for working CXX compiler: /usr/bin/c++ -- works 
-- Detecting CXX compiler ABI info 
-- Detecting CXX compiler ABI info - done 
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.28") 
-- checking for one of the modules 'glib-2.0' 
-- Found GLib: /usr/lib/arm-linux-gnueabihf/libglib-2.0.so (found version "2.42.1") 
-- Found mhd: /usr/include 
CMake Error at cmake/FindGLIB.cmake:39 (add_library): add_library cannot create imported target "glib-2.0" because another target with the same name already exists. 
Call Stack (most recent call first):librerie/CMakeLists.txt:2 (find_package) 

-- Found GLib: /usr/lib/arm-linux-gnueabihf/libglib-2.0.so (found version "2.42.1") 
-- Configuring incomplete, errors occurred! 
See also "/home/pi/pl1/CMakeFiles/CMakeOutput.log". 

这是我的项目结构:

src-> 
---- CMakeLists.txt 
---- main.c 
---- librerie-> 
-------------- CMakeLists.txt 
-------------- cJSON.c 
-------------- cJSON.h 
-------------- config.c 
-------------- config.h 
-------------- server_web.c 
-------------- server_web.h 
-------------- funzioni_thread.c 
-------------- funzioni_thread.h 
---- cmake-> 
-------------- FindGLIB.cmake 
-------------- FindMHD.cmake 

这是第一CMakeLists:

cmake_minimum_required (VERSION 2.6) 
project (TestPL) 

include_directories("${PROJECT_BINARY_DIR}") 
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") 

find_package(GLIB REQUIRED) 
find_package(MHD REQUIRED) 

add_subdirectory (librerie) 
set (EXTRA_LIBS ${EXTRA_LIBS} librerie) 

include_directories (${GLib_INCLUDE_DIRS} ${EXTRA_LIBS}) 

# add the executable 
add_executable(TestPL main.c) 
target_link_libraries (TestPL ${GLib_LIBRARY} ${MHD_LIBRARY} ${EXTRA_LIBS} m) 

这是librerie CMakeLists目录:

find_package(GLIB REQUIRED) 
find_package(MHD REQUIRED) 
include_directories (${GLib_INCLUDE_DIRS} ${EXTRA_LIBS}) 

add_library (librerie cJSON.c config.c generic.c server_web.c funzioni_thread.c) 
target_link_libraries (librerie ${GLib_LIBRARY} ${MHD_LIBRARY}) 

我在做什么错?

回答

1

你叫两次

find_package(GLIB REQUIRED) 

首次从顶级CMakeLists.txt打了个定义glib-2.0目标。第二次从librerie/CMakeLists.txt调用并尝试再次创建glib-2.0。这就是为什么你看到这个错误信息:目标已经在这个范围内定义了。

可能的解决方法是将步入库子目录第一,然后才打电话find_package()在顶级的CMakeLists.txt

add_subdirectory (librerie) 

find_package(GLIB REQUIRED) 
find_package(MHD REQUIRED) 

因为IMPORTED目标具有本地知名度,glib-2.0目标由find_package(GLIB)定义来自子目录librerie/的呼叫在从此子目录返回后将不可见。所以第二个来自顶级目录的调用将会成功。

+0

非常感谢!这是问题,现在它的工作!我不明白的是为什么即使在我的笔记本电脑上错误的方式运行安静 – Mex

+0

也许,您的笔记本电脑有不同的'FindGLIB.cmake'脚本,它不会定义导入的目标,而是变量。与目标不同,重新定义变量不是CMake的错误。 – Tsyvarev

+0

FindGLIB.cmake脚本与树莓和笔记本电脑相同,我复制了所有的项目文件,也许在手臂上做了不同的事情?,boh,无论如何,再次感谢! – Mex