C语言 CMake:无法从带有子项目的源项目中编译出来



我有一个带有 CMake 的项目(有 3 个子项目),当我在与顶级 CMakeList .txt 相同的目录中执行 cmake 时,它可以完美构建。但是当我尝试源代码外构建时,出现以下错误:

javsalgar@javsalgar-laptop:~/LocalWork/eclipse_workspace/mpiperf_pi$ mkdir build
javsalgar@javsalgar-laptop:~/LocalWork/eclipse_workspace/mpiperf_pi$ cd build/
javsalgar@javsalgar-laptop:~/LocalWork/eclipse_workspace/mpiperf_pi/build$ ls
javsalgar@javsalgar-laptop:~/LocalWork/eclipse_workspace/mpiperf_pi/build$ cmake ..
-- The C compiler identification is GNU 4.7.3
-- The CXX compiler identification is GNU 4.7.3
-- 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
-- Configuring done
-- Generating done
-- Build files have been written to: /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build

javsalgar@javsalgar-laptop:~/LocalWork/eclipse_workspace/mpiperf_pi/build$ make
/usr/bin/cmake -H/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi -B/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build/CMakeFiles /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build'
make -f pi_mpireduce/CMakeFiles/pi_mpireduce.dir/build.make pi_mpireduce/CMakeFiles/pi_mpireduce.dir/depend
make[2]: Entering directory `/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build'
cd /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/pi_mpireduce /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build/pi_mpireduce /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build/pi_mpireduce/CMakeFiles/pi_mpireduce.dir/DependInfo.cmake --color=
Scanning dependencies of target pi_mpireduce
make[2]: Leaving directory `/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build'
make -f pi_mpireduce/CMakeFiles/pi_mpireduce.dir/build.make pi_mpireduce/CMakeFiles/pi_mpireduce.dir/build
make[2]: Entering directory `/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build'
/usr/bin/cmake -E cmake_progress_report /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build/CMakeFiles 1
[ 20%] Building C object pi_mpireduce/CMakeFiles/pi_mpireduce.dir/src/mpi_pi_reduce.c.o
cd /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build/pi_mpireduce && mpicc   -I/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/include -I/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi -I/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build/pi_mpireduce -I/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/pi_mpireduce/include    -o CMakeFiles/pi_mpireduce.dir/src/mpi_pi_reduce.c.o   -c /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/pi_mpireduce/src/mpi_pi_reduce.c
/usr/bin/cmake -E cmake_progress_report /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build/CMakeFiles 2
[ 40%] Building C object pi_mpireduce/CMakeFiles/pi_mpireduce.dir/src/dboard.c.o
cd /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build/pi_mpireduce && mpicc   -I/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/include -I/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi -I/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build/pi_mpireduce -I/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/pi_mpireduce/include    -o CMakeFiles/pi_mpireduce.dir/src/dboard.c.o   -c /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/pi_mpireduce/src/dboard.c
Linking C executable .
cd /home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build/pi_mpireduce && /usr/bin/cmake -E cmake_link_script CMakeFiles/pi_mpireduce.dir/link.txt --verbose=1
mpicc      CMakeFiles/pi_mpireduce.dir/src/mpi_pi_reduce.c.o CMakeFiles/pi_mpireduce.dir/src/dboard.c.o  -o . -rdynamic -lmpi 
/usr/bin/ld: cannot open output file .: Is a directory
collect2: error: ld returned 1 exit status
make[2]: *** [pi_mpireduce] Error 1
make[2]: Leaving directory `/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build'
make[1]: *** [pi_mpireduce/CMakeFiles/pi_mpireduce.dir/all] Error 2
make[1]: Leaving directory `/home/javsalgar/LocalWork/eclipse_workspace/mpiperf_pi/build'
make: *** [all] Error 2

我发现了问题所在。可执行文件和子项目的目录具有相同的名称。念吟可执行文件名称可以解决问题。

mpicc CMakeFiles/pi_mpireduce.dir/src/mpi_pi_reduce.c.o CMakeFiles/pi_mpireduce.dir/src/dboard.c.o  -o . -rdynamic -lmpi

告诉链接器编译的输出名称应为 . ,这对于可执行文件或库或任何内容都不是有效的名称。这可能是因为您在配置期间从为空的变量设置目标名称,或者您不小心在那里编写了.

相关内容

  • 没有找到相关文章

最新更新