CMake:find_library结果取决于所选的编译器?

时间:2017-09-12 07:25:18

标签: linux cmake

我对find_library应该如何工作感到困惑,而且我不知道这可能是一个CMake错误,还是我的误用或错误配置。我已经安装了GCC和PGI编译器,当我尝试这个简单的CMakeLists.txt文件(同时包含2.8.11和3.5.1)时:

cmake_minimum_required(VERSION 2.8.11)
find_library( LIBdl dl )
message("LIBdl ${LIBdl}")

我得到以下内容:

$ CC=gcc CXX=g++ cmake .
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
LIBdl /usr/lib/x86_64-linux-gnu/libdl.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/molcas-test/test/cmake

没关系,但是:

$ CC=pgcc CXX=pgc++ cmake .
-- The C compiler identification is PGI 17.1.0
-- The CXX compiler identification is PGI 17.1.0
-- Check for working C compiler: /opt/pgi/linux86-64/17.1/bin/pgcc
-- Check for working C compiler: /opt/pgi/linux86-64/17.1/bin/pgcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /opt/pgi/linux86-64/17.1/bin/pgc++
-- Check for working CXX compiler: /opt/pgi/linux86-64/17.1/bin/pgc++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
LIBdl LIBdl-NOTFOUND
-- Configuring done
-- Generating done
-- Build files have been written to: /home/molcas-test/test/cmake

注意找不到dl

退出pgccpgc++会导致找到库,因此必须考虑编译器的配置方式。然而,只需从命令行进行编译即可找到dl而无需抱怨:

$ pgcc -ldl hello_world.c -o hello_world
$ ./hello_world
Hello world!

所以我相信如果pgcc可以找到图书馆并且CMake无法解决问题,那就不对了。我当然可以在运行LIB=/usr/lib/x86_64-linux-gnu之前设置cmake,以强制在该目录中进行搜索,但这感觉不对。

编辑:似乎问题出在gcc/lib/x86_64-linux-gnu中包含CMAKE_C_IMPLICIT_LINK_DIRECTORIES,因此设置了CMAKE_LIBRARY_ARCHITECTURE。但是pgcc此目录不存在且CMAKE_LIBRARY_ARCHITECTURE为空。

pgcc缺少该目录,因为pgcc -v并未包含-L/lib/x86_64-linux-gnu标记,而gcc -v则包含ld标记。但是,ld在任何一种情况下都会在目录中找到库。

所以CMake不会在与/etc/ld.so.conf.d相同的地方搜索图书馆,不是吗?除了例如手动检查LIB中的所有文件并设置{{1}}环境变量之外,还有一种简单的方法可以更改吗?

0 个答案:

没有答案