目前,我正在使用Raspberry Pi:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 8.0 (jessie)
Release: 8.0
Codename: jessie
我有一些看起来像下面的图书馆(C language)
:
my_app\-my_app.c
\ - CMakeLists.txt
\-lib
\-lib1\- CMakeLists.txt
\- src
\- lib1.c
\- CMakeLists.txt
\- include
\- lib1.h
\- cmake
\- modules
\- FindGLIB2.cmake
\- MacroOutOfSourceBuild.cmake
....................
lib1
取决于glib
#include <glib.h>
这是我的CMakeLists.txt
my_app
cmake_minimum_required(VERSION 2.8)
project(my_app)
set(CMAKE_MODULE_PATH ${my_app_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
# Enable C11 or at least C99
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-std=c11" COMPILER_SUPPORTS_C11)
CHECK_C_COMPILER_FLAG("-std=c99" COMPILER_SUPPORTS_C99)
if(COMPILER_SUPPORTS_C11)
message(STATUS "Using C11.")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
elseif(COMPILER_SUPPORTS_C99)
message(STATUS "The compiler ${CMAKE_C_COMPILER} has no C11 support. Using C99 instead.")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
else()
message(STATUS "The compiler ${CMAKE_C_COMPILER} has no C11 nor C99 support. Please update your C compiler.")
endif()
SET (CMAKE_C_FLAGS "-lm")
include(MacroOutOfSourceBuild)
include(TargetDistclean)
macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build.")
add_subdirectory(lib/lib2)
add_subdirectory(lib/lib1)
include_directories(${lib2_SOURCE_DIR}/include)
include_directories(${lib1_SOURCE_DIR}/include)
# Add sources
set(my_app_SOURCES my_app.c)
add_executable(my_app ${my_app_SOURCES})
target_link_libraries(my_app
lib2
lib1
)
install(TARGETS my_app
RUNTIME DESTINATION bin
)
这是我的CMakeLists.txt
my_app/lib1
cmake_minimum_required(VERSION 2.8)
project(lib1)
set(CMAKE_MODULE_PATH ${lib1_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
SET (CMAKE_C_FLAGS "")
include(MacroOutOfSourceBuild)
macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build.")
add_subdirectory(src)
install(DIRECTORY include/lib1 DESTINATION include)
这是我的CMakeLists.txt
my_app/lib1/src
# Include the directory itself as a path to include directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include(FindGLIB2)
include_directories(
${lib1_SOURCE_DIR}/include
${GLIB2_INCLUDE_DIRS}
)
set(lib1_SOURCES
lib1.c
)
add_library(lib1 ${lib1_SOURCES})
target_link_libraries(lib1
${GLIB2_LIBRARIES}
)
install(TARGETS lib1
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
这是日志文件:
pi@raspberrypi ~/my_app/build $ cmake ..
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.28")
-- checking for one of the modules 'glib-2.0'
-- Found GLib2: glib-2.0 /usr/include/glib-2.0;/usr/lib/arm-linux-gnueabihf/glib-2.0/include
-- Looking for include file glib/gregex.h
-- Looking for include file glib/gregex.h - not found
-- Looking for include file glib/gchecksum.h
-- Looking for include file glib/gchecksum.h - not found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/my_app/build
这意味着我的系统上已经有glib
。
现在,我有这个问题:
如果我仅将#include <glib.h>
用于lib1.c
。一切都很好。
如果我仅将#include <glib.h>
用于lib1.h
。我在lib1.h
看到了这个问题:
lib1.h:2:18: fatal error: glib.h: No such file or directory
#include <glib.h>
^
compilation terminated.
EDITED
错误来自my_app.c
,其中包括lib1.h
以下是VERBOSE=yes
与lib1.h
pi@raspberrypi ~/my_app/build $ make VERBOSE=1
/usr/bin/cmake -H/home/pi/my_app -B/home/pi/my_app/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/pi/my_app/build/CMakeFiles /home/pi/my_app/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/pi/my_app/build'
make -f lib/bzle/src/CMakeFiles/bzle.dir/build.make lib/bzle/src/CMakeFiles/bzle.dir/depend
make[2]: Entering directory '/home/pi/my_app/build'
cd /home/pi/my_app/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/my_app /home/pi/my_app/lib/bzle/src /home/pi/my_app/build /home/pi/my_app/build/lib/bzle/src /home/pi/my_app/build/lib/bzle/src/CMakeFiles/bzle.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/pi/my_app/build'
make -f lib/bzle/src/CMakeFiles/bzle.dir/build.make lib/bzle/src/CMakeFiles/bzle.dir/build
make[2]: Entering directory '/home/pi/my_app/build'
make[2]: Nothing to be done for 'lib/bzle/src/CMakeFiles/bzle.dir/build'.
make[2]: Leaving directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 3 4 5 6 7 8 9 10 11 12 13 14
[ 60%] Built target bzle
make -f lib/lib1/src/CMakeFiles/lib1.dir/build.make lib/lib1/src/CMakeFiles/lib1.dir/depend
make[2]: Entering directory '/home/pi/my_app/build'
cd /home/pi/my_app/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/my_app /home/pi/my_app/lib/lib1/src /home/pi/my_app/build /home/pi/my_app/build/lib/lib1/src /home/pi/my_app/build/lib/lib1/src/CMakeFiles/lib1.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/pi/my_app/build'
make -f lib/lib1/src/CMakeFiles/lib1.dir/build.make lib/lib1/src/CMakeFiles/lib1.dir/build
make[2]: Entering directory '/home/pi/my_app/build'
make[2]: Nothing to be done for 'lib/lib1/src/CMakeFiles/lib1.dir/build'.
make[2]: Leaving directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 1 2
[ 70%] Built target lib1
make -f lib/lib2/src/CMakeFiles/lib2.dir/build.make lib/lib2/src/CMakeFiles/lib2.dir/depend
make[2]: Entering directory '/home/pi/my_app/build'
cd /home/pi/my_app/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/my_app /home/pi/my_app/lib/lib2/src /home/pi/my_app/build /home/pi/my_app/build/lib/lib2/src /home/pi/my_app/build/lib/lib2/src/CMakeFiles/lib2.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/pi/my_app/build'
make -f lib/lib2/src/CMakeFiles/lib2.dir/build.make lib/lib2/src/CMakeFiles/lib2.dir/build
make[2]: Entering directory '/home/pi/my_app/build'
make[2]: Nothing to be done for 'lib/lib2/src/CMakeFiles/lib2.dir/build'.
make[2]: Leaving directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 20
[ 75%] Built target lib2
make -f lib/ini/src/CMakeFiles/ini.dir/build.make lib/ini/src/CMakeFiles/ini.dir/depend
make[2]: Entering directory '/home/pi/my_app/build'
cd /home/pi/my_app/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/my_app /home/pi/my_app/lib/ini/src /home/pi/my_app/build /home/pi/my_app/build/lib/ini/src /home/pi/my_app/build/lib/ini/src/CMakeFiles/ini.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/pi/my_app/build'
make -f lib/ini/src/CMakeFiles/ini.dir/build.make lib/ini/src/CMakeFiles/ini.dir/build
make[2]: Entering directory '/home/pi/my_app/build'
make[2]: Nothing to be done for 'lib/ini/src/CMakeFiles/ini.dir/build'.
make[2]: Leaving directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 18
[ 80%] Built target ini
make -f CMakeFiles/my_app.dir/build.make CMakeFiles/my_app.dir/depend
make[2]: Entering directory '/home/pi/my_app/build'
cd /home/pi/my_app/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/my_app /home/pi/my_app /home/pi/my_app/build /home/pi/my_app/build /home/pi/my_app/build/CMakeFiles/my_app.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/pi/my_app/build'
make -f CMakeFiles/my_app.dir/build.make CMakeFiles/my_app.dir/build
make[2]: Entering directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 19
[ 85%] Building C object CMakeFiles/my_app.dir/my_app.c.o
/usr/bin/cc -lm -I/home/pi/my_app/lib/bzle/include -I/home/pi/my_app/lib/ini/include -I/home/pi/my_app/lib/lib2/include -I/home/pi/my_app/lib/lib1/include -o CMakeFiles/my_app.dir/my_app.c.o -c /home/pi/my_app/my_app.c
In file included from /home/pi/my_app/my_app.c:53:0:
/home/pi/my_app/lib/lib1/include/lib1/lib1.h:2:18: fatal error: glib.h: No such file or directory
#include <glib.h>
^
compilation terminated.
CMakeFiles/my_app.dir/build.make:54: recipe for target 'CMakeFiles/my_app.dir/my_app.c.o' failed
make[2]: *** [CMakeFiles/my_app.dir/my_app.c.o] Error 1
make[2]: Leaving directory '/home/pi/my_app/build'
CMakeFiles/Makefile2:94: recipe for target 'CMakeFiles/my_app.dir/all' failed
make[1]: *** [CMakeFiles/my_app.dir/all] Error 2
make[1]: Leaving directory '/home/pi/my_app/build'
Makefile:117: recipe for target 'all' failed
make: *** [all] Error 2
使用lib1.c
pi@raspberrypi ~/my_app/build $ make VERBOSE=1
/usr/bin/cmake -H/home/pi/my_app -B/home/pi/my_app/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/pi/my_app/build/CMakeFiles /home/pi/my_app/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/pi/my_app/build'
make -f lib/bzle/src/CMakeFiles/bzle.dir/build.make lib/bzle/src/CMakeFiles/bzle.dir/depend
make[2]: Entering directory '/home/pi/my_app/build'
cd /home/pi/my_app/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/my_app /home/pi/my_app/lib/bzle/src /home/pi/my_app/build /home/pi/my_app/build/lib/bzle/src /home/pi/my_app/build/lib/bzle/src/CMakeFiles/bzle.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/pi/my_app/build'
make -f lib/bzle/src/CMakeFiles/bzle.dir/build.make lib/bzle/src/CMakeFiles/bzle.dir/build
make[2]: Entering directory '/home/pi/my_app/build'
make[2]: Nothing to be done for 'lib/bzle/src/CMakeFiles/bzle.dir/build'.
make[2]: Leaving directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 3 4 5 6 7 8 9 10 11 12 13 14
[ 60%] Built target bzle
make -f lib/lib1/src/CMakeFiles/lib1.dir/build.make lib/lib1/src/CMakeFiles/lib1.dir/depend
make[2]: Entering directory '/home/pi/my_app/build'
cd /home/pi/my_app/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/my_app /home/pi/my_app/lib/lib1/src /home/pi/my_app/build /home/pi/my_app/build/lib/lib1/src /home/pi/my_app/build/lib/lib1/src/CMakeFiles/lib1.dir/DependInfo.cmake --color=
Dependee "../lib/lib1/include/lib1/other_beacon.h" is newer than depender "lib/lib1/src/CMakeFiles/lib1.dir/other_beacon.c.o".
Dependee "/home/pi/my_app/lib/lib1/src/other_beacon.c" is newer than depends file "/home/pi/my_app/build/lib/lib1/src/CMakeFiles/lib1.dir/depend.internal".
Clearing dependencies in "/home/pi/my_app/build/lib/lib1/src/CMakeFiles/lib1.dir/depend.make".
Scanning dependencies of target lib1
make[2]: Leaving directory '/home/pi/my_app/build'
make -f lib/lib1/src/CMakeFiles/lib1.dir/build.make lib/lib1/src/CMakeFiles/lib1.dir/build
make[2]: Entering directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 1
[ 65%] Building C object lib/lib1/src/CMakeFiles/lib1.dir/other_beacon.c.o
cd /home/pi/my_app/build/lib/lib1/src && /usr/bin/cc -I/home/pi/my_app/build/lib/lib1/src -I/home/pi/my_app/lib/lib1/src -I/home/pi/my_app/lib/lib1/include -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/home/pi/my_app/lib/bzle/include -o CMakeFiles/lib1.dir/other_beacon.c.o -c /home/pi/my_app/lib/lib1/src/other_beacon.c
Linking C static library liblib1.a
cd /home/pi/my_app/build/lib/lib1/src && /usr/bin/cmake -P CMakeFiles/lib1.dir/cmake_clean_target.cmake
cd /home/pi/my_app/build/lib/lib1/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/lib1.dir/link.txt --verbose=1
/usr/bin/ar cr liblib1.a CMakeFiles/lib1.dir/other_beacon.c.o CMakeFiles/lib1.dir/ibeacon.c.o
/usr/bin/ranlib liblib1.a
make[2]: Leaving directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 1 2
[ 70%] Built target lib1
make -f lib/lib2/src/CMakeFiles/lib2.dir/build.make lib/lib2/src/CMakeFiles/lib2.dir/depend
make[2]: Entering directory '/home/pi/my_app/build'
cd /home/pi/my_app/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/my_app /home/pi/my_app/lib/lib2/src /home/pi/my_app/build /home/pi/my_app/build/lib/lib2/src /home/pi/my_app/build/lib/lib2/src/CMakeFiles/lib2.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/pi/my_app/build'
make -f lib/lib2/src/CMakeFiles/lib2.dir/build.make lib/lib2/src/CMakeFiles/lib2.dir/build
make[2]: Entering directory '/home/pi/my_app/build'
make[2]: Nothing to be done for 'lib/lib2/src/CMakeFiles/lib2.dir/build'.
make[2]: Leaving directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 20
[ 75%] Built target lib2
make -f lib/ini/src/CMakeFiles/ini.dir/build.make lib/ini/src/CMakeFiles/ini.dir/depend
make[2]: Entering directory '/home/pi/my_app/build'
cd /home/pi/my_app/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/my_app /home/pi/my_app/lib/ini/src /home/pi/my_app/build /home/pi/my_app/build/lib/ini/src /home/pi/my_app/build/lib/ini/src/CMakeFiles/ini.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/pi/my_app/build'
make -f lib/ini/src/CMakeFiles/ini.dir/build.make lib/ini/src/CMakeFiles/ini.dir/build
make[2]: Entering directory '/home/pi/my_app/build'
make[2]: Nothing to be done for 'lib/ini/src/CMakeFiles/ini.dir/build'.
make[2]: Leaving directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 18
[ 80%] Built target ini
make -f CMakeFiles/my_app.dir/build.make CMakeFiles/my_app.dir/depend
make[2]: Entering directory '/home/pi/my_app/build'
cd /home/pi/my_app/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/my_app /home/pi/my_app /home/pi/my_app/build /home/pi/my_app/build /home/pi/my_app/build/CMakeFiles/my_app.dir/DependInfo.cmake --color=
Dependee "../lib/lib1/include/lib1/other_beacon.h" is newer than depends file "/home/pi/my_app/build/CMakeFiles/my_app.dir/depend.internal".
Clearing dependencies in "/home/pi/my_app/build/CMakeFiles/my_app.dir/depend.make".
Scanning dependencies of target my_app
make[2]: Leaving directory '/home/pi/my_app/build'
make -f CMakeFiles/my_app.dir/build.make CMakeFiles/my_app.dir/build
make[2]: Entering directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 19
[ 85%] Building C object CMakeFiles/my_app.dir/my_app.c.o
/usr/bin/cc -lm -I/home/pi/my_app/lib/bzle/include -I/home/pi/my_app/lib/ini/include -I/home/pi/my_app/lib/lib2/include -I/home/pi/my_app/lib/lib1/include -o CMakeFiles/my_app.dir/my_app.c.o -c /home/pi/my_app/my_app.c
Linking C executable my_app
/usr/bin/cmake -E cmake_link_script CMakeFiles/my_app.dir/link.txt --verbose=1
/usr/bin/cc -lm CMakeFiles/my_app.dir/my_app.c.o -o my_app -rdynamic lib/bzle/src/libbzle.a lib/ini/src/libini.a lib/lib2/src/liblib2.a lib/lib1/src/liblib1.a lib/bzle/src/libbzle.a -lglib-2.0
make[2]: Leaving directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 19
[ 85%] Built target my_app
make -f lib/bzle/tools/CMakeFiles/hciconfig.dir/build.make lib/bzle/tools/CMakeFiles/hciconfig.dir/depend
make[2]: Entering directory '/home/pi/my_app/build'
cd /home/pi/my_app/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/my_app /home/pi/my_app/lib/bzle/tools /home/pi/my_app/build /home/pi/my_app/build/lib/bzle/tools /home/pi/my_app/build/lib/bzle/tools/CMakeFiles/hciconfig.dir/DependInfo.cmake --color=
Dependee "/home/pi/my_app/build/lib/bzle/tools/CMakeFiles/hciconfig.dir/DependInfo.cmake" is newer than depender "/home/pi/my_app/build/lib/bzle/tools/CMakeFiles/hciconfig.dir/depend.internal".
Dependee "/home/pi/my_app/build/lib/bzle/tools/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/pi/my_app/build/lib/bzle/tools/CMakeFiles/hciconfig.dir/depend.internal".
Scanning dependencies of target hciconfig
make[2]: Leaving directory '/home/pi/my_app/build'
make -f lib/bzle/tools/CMakeFiles/hciconfig.dir/build.make lib/bzle/tools/CMakeFiles/hciconfig.dir/build
make[2]: Entering directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 15
[ 90%] Building C object lib/bzle/tools/CMakeFiles/hciconfig.dir/csr.c.o
cd /home/pi/my_app/build/lib/bzle/tools && /usr/bin/cc -Wall -I/home/pi/my_app/build/lib/bzle/tools -I/home/pi/my_app/lib/bzle/tools -I/home/pi/my_app/lib/bzle/include -o CMakeFiles/hciconfig.dir/csr.c.o -c /home/pi/my_app/lib/bzle/tools/csr.c
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 16
[ 95%] Building C object lib/bzle/tools/CMakeFiles/hciconfig.dir/hciconfig.c.o
cd /home/pi/my_app/build/lib/bzle/tools && /usr/bin/cc -Wall -I/home/pi/my_app/build/lib/bzle/tools -I/home/pi/my_app/lib/bzle/tools -I/home/pi/my_app/lib/bzle/include -o CMakeFiles/hciconfig.dir/hciconfig.c.o -c /home/pi/my_app/lib/bzle/tools/hciconfig.c
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 17
[100%] Building C object lib/bzle/tools/CMakeFiles/hciconfig.dir/textfile.c.o
cd /home/pi/my_app/build/lib/bzle/tools && /usr/bin/cc -Wall -I/home/pi/my_app/build/lib/bzle/tools -I/home/pi/my_app/lib/bzle/tools -I/home/pi/my_app/lib/bzle/include -o CMakeFiles/hciconfig.dir/textfile.c.o -c /home/pi/my_app/lib/bzle/tools/textfile.c
Linking C executable hciconfig
cd /home/pi/my_app/build/lib/bzle/tools && /usr/bin/cmake -E cmake_link_script CMakeFiles/hciconfig.dir/link.txt --verbose=1
/usr/bin/cc -Wall CMakeFiles/hciconfig.dir/csr.c.o CMakeFiles/hciconfig.dir/hciconfig.c.o CMakeFiles/hciconfig.dir/textfile.c.o -o hciconfig -rdynamic ../src/libbzle.a -lglib-2.0
make[2]: Leaving directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_report /home/pi/my_app/build/CMakeFiles 15 16 17
[100%] Built target hciconfig
make[1]: Leaving directory '/home/pi/my_app/build'
/usr/bin/cmake -E cmake_progress_start /home/pi/my_app/build/CMakeFiles 0
我对此有所了解。 你能给我一些建议吗?