我有一个自己编写的 C++ 应用程序,它使用 cmake 作为其构建工具。它CMakeLists.txt
在 Debian 7 (Wheezy) 上运行得很好,但在 Debian 8 (Jessie) 上却不行,这让我发疯。特别是,cmake 找不到 boost 库。的相关部分CMakeLists.txt
是:
#find_package( Boost REQUIRED COMPONENTS system program_options date_time )
find_package( Boost REQUIRED )
message( "Boost include dir is ${Boost_INCLUDE_DIRS}" )
message( "Boost library dir is ${Boost_LIBRARY_DIRS}" )
message( "Boost libraries ${Boost_LIBRARIES}" )
输出是
# make rebuild_cache
Running CMake to regenerate build system...
-- Boost version: 1.55.0
Boost include dir is /usr/include
Boost library dir is /usr/lib
Boost libraries
RRDTool library found: TRUE
RRDTool include dir is: /usr/include
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/src/lm50client
正如您所看到的,第四行输出为空(“Boost 库”之后没有库)。变量${Boost_LIBRARIES}
为空。
如果我取消注释该行find_package( Boost REQUIRED COMPONENTS system program_options date_time )
,即如果我指定特定的库,则脚本会严重失败。
相同的脚本适用于带有 Boost 1.49 的 Debian Wheezy。我安装的库:
# aptitude search 'boost'
i libboost-all-dev - Boost C++ Libraries development files (ALL) (default version)
i A libboost-atomic-dev - atomic data types, operations, and memory ordering constraints (default version)
i A libboost-atomic1.55-dev - atomic data types, operations, and memory ordering constraints
i A libboost-atomic1.55.0 - atomic data types, operations, and memory ordering constraints
i A libboost-chrono-dev - C++ representation of time duration, time point, and clocks (default version)
i A libboost-chrono1.55-dev - C++ representation of time duration, time point, and clocks
i A libboost-chrono1.55.0 - C++ representation of time duration, time point, and clocks
i A libboost-context-dev - provides a sort of cooperative multitasking on a single thread (default version)
i A libboost-context1.55-dev - provides a sort of cooperative multitasking on a single thread
i A libboost-context1.55.0 - provides a sort of cooperative multitasking on a single thread
i A libboost-coroutine-dev - provides a sort of cooperative multitasking on a single thread (default version)
i A libboost-coroutine1.55-dev - provides a sort of cooperative multitasking on a single thread
i A libboost-date-time-dev - set of date-time libraries based on generic programming concepts (default version)
i A libboost-date-time1.55-dev - set of date-time libraries based on generic programming concepts
i A libboost-date-time1.55.0 - set of date-time libraries based on generic programming concepts
p libboost-dbg - Boost C++ Libraries with debug symbols (default version)
i A libboost-dev - Boost C++ Libraries development files (default version)
p libboost-doc - Boost.org libraries documentation (default version)
i A libboost-exception-dev - library to help write exceptions and handlers (default version)
i A libboost-exception1.55-dev - library to help write exceptions and handlers
i A libboost-filesystem-dev - filesystem operations (portable paths, iteration over directories, etc) in C++ (default version)
i A libboost-filesystem1.55-dev - filesystem operations (portable paths, iteration over directories, etc) in C++
i A libboost-filesystem1.55.0 - filesystem operations (portable paths, iteration over directories, etc) in C++
p libboost-geometry-utils-perl - Perl module providing bindings to the Boost Geometry library
i A libboost-graph-dev - generic graph components and algorithms in C++ (default version)
i A libboost-graph-parallel-dev - generic graph components and algorithms in C++ (default version)
i A libboost-graph-parallel1.55-dev - generic graph components and algorithms in C++
i A libboost-graph-parallel1.55.0 - generic graph components and algorithms in C++
i A libboost-graph1.55-dev - generic graph components and algorithms in C++
i A libboost-graph1.55.0 - generic graph components and algorithms in C++
i A libboost-iostreams-dev - Boost.Iostreams Library development files (default version)
i A libboost-iostreams1.55-dev - Boost.Iostreams Library development files
i A libboost-iostreams1.55.0 - Boost.Iostreams Library
i A libboost-locale-dev - C++ facilities for localization (default version)
i A libboost-locale1.55-dev - C++ facilities for localization
i A libboost-locale1.55.0 - C++ facilities for localization
i A libboost-log-dev - C++ logging library (default version)
i A libboost-log1.55-dev - C++ logging library
i A libboost-log1.55.0 - C++ logging library
i A libboost-math-dev - Boost.Math Library development files (default version)
i A libboost-math1.55-dev - Boost.Math Library development files
i A libboost-math1.55.0 - Boost.Math Library
i A libboost-mpi-dev - C++ interface to the Message Passing Interface (MPI) (default version)
i A libboost-mpi-python-dev - C++ interface to the Message Passing Interface (MPI), Python Bindings (default version)
i A libboost-mpi-python1.55-dev - C++ interface to the Message Passing Interface (MPI), Python Bindings
i A libboost-mpi-python1.55.0 - C++ interface to the Message Passing Interface (MPI), Python Bindings
i A libboost-mpi1.55-dev - C++ interface to the Message Passing Interface (MPI)
i A libboost-mpi1.55.0 - C++ interface to the Message Passing Interface (MPI)
i A libboost-program-options-dev - program options library for C++ (default version)
i A libboost-program-options1.55-dev - program options library for C++
i A libboost-program-options1.55.0 - program options library for C++
i A libboost-python-dev - Boost.Python Library development files (default version)
i A libboost-python1.55-dev - Boost.Python Library development files
i A libboost-python1.55.0 - Boost.Python Library
i A libboost-random-dev - Boost Random Number Library (default version)
i A libboost-random1.55-dev - Boost Random Number Library
i A libboost-random1.55.0 - Boost Random Number Library
i A libboost-regex-dev - regular expression library for C++ (default version)
i A libboost-regex1.55-dev - regular expression library for C++
i A libboost-regex1.55.0 - regular expression library for C++
i A libboost-serialization-dev - serialization library for C++ (default version)
i A libboost-serialization1.55-dev - serialization library for C++
i A libboost-serialization1.55.0 - serialization library for C++
i A libboost-signals-dev - managed signals and slots library for C++ (default version)
i A libboost-signals1.55-dev - managed signals and slots library for C++
i A libboost-signals1.55.0 - managed signals and slots library for C++
i A libboost-system-dev - Operating system (e.g. diagnostics support) library (default version)
i A libboost-system1.55-dev - Operating system (e.g. diagnostics support) library
i A libboost-system1.55.0 - Operating system (e.g. diagnostics support) library
i A libboost-test-dev - components for writing and executing test suites (default version)
i A libboost-test1.55-dev - components for writing and executing test suites
i A libboost-test1.55.0 - components for writing and executing test suites
i A libboost-thread-dev - portable C++ multi-threading (default version)
i A libboost-thread1.55-dev - portable C++ multi-threading
i A libboost-thread1.55.0 - portable C++ multi-threading
i A libboost-timer-dev - C++ wall clock and CPU process timers (default version)
i A libboost-timer1.55-dev - C++ wall clock and CPU process timers
i A libboost-timer1.55.0 - C++ wall clock and CPU process timers
i A libboost-tools-dev - Boost C++ Libraries development tools (default version)
i A libboost-wave-dev - C99/C++ preprocessor library (default version)
i A libboost-wave1.55-dev - C99/C++ preprocessor library
i A libboost-wave1.55.0 - C99/C++ preprocessor library
i libboost1.55-all-dev - Boost C++ Libraries development files (ALL)
p libboost1.55-dbg - Boost C++ Libraries with debug symbols
i A libboost1.55-dev - Boost C++ Libraries development files
p libboost1.55-doc - Boost.org libraries documentation
i A libboost1.55-tools-dev - Boost C++ Libraries development tools
p pianobooster - learn the piano just by playing a game
p pianobooster-dbg - learn the piano just by playing a game - debug
p shinken-mod-booster-nrpe - Shinken booster-nrpe module
我究竟做错了什么?
更新
我进一步缩小了问题范围。在 Debian 7 (Wheezy) 上我得到
# ls -lh /usr/lib/libboost_system*
-rw-r--r-- 1 root root 32K Feb 4 2013 libboost_system.a
lrwxrwxrwx 1 root root 17 Feb 4 2013 libboost_system-mt.a -> libboost_system.a
lrwxrwxrwx 1 root root 25 Feb 4 2013 libboost_system-mt.so -> libboost_system.so.1.49.0
lrwxrwxrwx 1 root root 25 Feb 4 2013 libboost_system.so -> libboost_system.so.1.49.0
-rw-r--r-- 1 root root 14K Feb 4 2013 libboost_system.so.1.49.0
如果我在 Debian 8 (Jessie) 上做同样的事情,我得到
# ls -lh /usr/lib/libboost_system*
ls: cannot access /usr/lib/libboost_system*: No such file or directory
什么?!此外,在 Debian Wheezy 上我查找了提供 lib 的软件包
# dpkg -S /usr/lib/libboost_system.so.1.49.0
libboost-system1.49.0: /usr/lib/libboost_system.so.1.49.0
# dpkg -L libboost-system1.49.0
/.
/usr
/usr/lib
/usr/lib/libboost_system.so.1.49.0
/usr/share
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/libboost-system1.49.0
/usr/share/doc
/usr/share/doc/libboost-system1.49.0
/usr/share/doc/libboost-system1.49.0/changelog.Debian.gz
/usr/share/doc/libboost-system1.49.0/NEWS.Debian.gz
/usr/share/doc/libboost-system1.49.0/README.Debian.gz
/usr/share/doc/libboost-system1.49.0/copyright
等效的,我怀疑libboost-system1.55.0
在 Debian 8 (Jessie) 上提供对应的版本,但是
# dpkg -L libboost-system1.55.0
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.55.0
/usr/share
/usr/share/doc
/usr/share/doc/libboost-system1.55.0
/usr/share/doc/libboost-system1.55.0/copyright
/usr/share/doc/libboost-system1.55.0/changelog.Debian.gz
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/libboost-system1.55.0
x86_64-linux-gnu
我们看到 Debian 8 (Jessie) 将库放入另一个cmake 找不到它的子目录中。我想这就是问题的根源。但是,即使我手动设置BOOST_LIBRARYDIR
以使 cmake 指向正确的目录,它也不起作用。而且,这不可能是正确的解决方案,因为修复所有构建脚本不可能是正确的。这一定是一些更广泛的通用问题。
答案1
我知道这是一个老问题,但是您是否尝试在 LD_LIBRARY_PATH 中设置 Boost 1.55 的路径?
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu