文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
15.3 检测所需的链接和依赖关系
现在已经生成了所有文件,让我们重新构建。我们应该能够配置和编译源代码,不过不能链接:
$ mkdir -p build $ cd build $ cmake .. $ cmake --build . ... Scanning dependencies of target vim [ 98%] Building C object src/CMakeFiles/vim.dir/main.c.o [100%] Linking C executable ../bin/vim ../lib64/libbasic_sources.a(term.c.o): In function `set_shellsize.part.12': term.c:(.text+0x2bd): undefined reference to `tputs' ../lib64/libbasic_sources.a(term.c.o): In function `getlinecol': term.c:(.text+0x902): undefined reference to `tgetent' term.c:(.text+0x915): undefined reference to `tgetent' term.c:(.text+0x935): undefined reference to `tgetnum' term.c:(.text+0x948): undefined reference to `tgetnum' ... many other undefined references ...
同样,可以从 Autotools 编译中获取日志文件,特别是链接行,通过在 src/CMakeLists.txt
中添加以下代码来解决缺少的依赖关系:
# find X11 and link to it find_package(X11 REQUIRED) if(X11_FOUND) target_link_libraries(vim PUBLIC ${X11_LIBRARIES} ) endif() # a couple of more system libraries that the code requires foreach(_library IN ITEMS Xt SM m tinfo acl gpm dl) find_library(_${_library}_found ${_library} REQUIRED) if(_${_library}_found) target_link_libraries(vim PUBLIC ${_library} ) endif() endforeach()
我们可以添加一个库的依赖目标,并且不需要构建,以及不需要将库目标放在一个列表变量中,否则将破坏 CMake 代码的自变量,特别是对于较大的项目而言。
修改之后,编译和链接:
$ cmake --build . ... Scanning dependencies of target vim [ 98%] Building C object src/CMakeFiles/vim.dir/main.c.o [100%] Linking C executable ../bin/vim [100%] Built target vim
现在,我们可以执行编译后的二进制文件,我们新编译的 Vim 就可使用了!
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论