Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux CMake:查找库结果取决于所选编译器?_Linux_Cmake - Fatal编程技术网

Linux CMake:查找库结果取决于所选编译器?

Linux CMake:查找库结果取决于所选编译器?,linux,cmake,Linux,Cmake,我对find_library应该如何工作感到困惑,我不知道这是否是一个CMake bug,或者是我的误用或配置错误。我已经安装了GCC和PGI编译器,当我尝试这个简单的CMakeLists.txt文件(2.8.11和3.5.1版本)时: 我得到以下信息: $ CC=gcc CXX=g++ cmake . -- The C compiler identification is GNU 4.8.4 -- The CXX compiler identification is GNU 4.8.4 --

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

我得到以下信息:

$ 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

省略
pgcc
pgc++
会导致找到库,因此它必须是编译器配置方式的一部分。但是仅仅从命令行编译就可以毫无怨言地找到
dl

$ pgcc -ldl hello_world.c -o hello_world
$ ./hello_world
Hello world!
因此,我认为如果pgcc能找到库,而CMake却找不到库,那么有些事情是不对的。当然,在运行
cmake
之前,我可以设置
LIB=/usr/LIB/x86_64-linux-gnu
,以强制在该目录中进行搜索,但这感觉不对

问题似乎出在
gcc
上。我将
/lib/x86\u 64-linux-gnu
包含在
CMAKE\u C\u IMPLICIT\u LINK\u目录中
,因此设置了
CMAKE\u库的体系结构
。但是使用
pgcc
时,此目录不存在,
CMAKE\u LIBRARY\u ARCHITECTURE
为空

目录中缺少
pgcc
,因为
pgcc-v
不包含
-L/lib/x86_64-linux-gnu
标志,而
gcc-v
包含。但是,
ld
在这两种情况下都会在目录中查找库


因此,CMake没有在与
ld
相同的位置搜索库。应该吗?除了手动检查
/etc/ld.so.conf.d
中的所有文件并设置
LIB
环境变量之外,是否有一种简单的方法可以改变这一点?

CMake文档说
CMake\u LIBRARY\u ARCHITECTURE
是从编译器推导出来的。我想说它做了类似于
gcc-dumpmachine
的事情,它提供了
x86_64-linux-gnu
。显然,这是pgcc的另一个特点。您可以随时使用
strace
检查和比较所有内容。为了把所有的混淆都放在一个地方,就我所知,专门为
pgcc
@Velkan编写一个工具链文件
CMAKE_LIBRARY_架构
是从
(p)gcc-v
标志中读取的“隐式链接目录”推导出来的。
$ pgcc -ldl hello_world.c -o hello_world
$ ./hello_world
Hello world!