本文介绍了在add_library的链接阶段结束时,CMake add -ldl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在github https://github.com/acgreek/ExtremeCUnit 上编写/维护了一个小型单元测试库。 a>使用cmake构建。您可以在签出后通过 cmake test签出并运行一些测试。它在Cygwin和Ubuntu(我唯一的家庭系统)上运行良好。我最近升级到ubuntu 13.10,并且该库停止了与测试二进制文件的链接,因为ExtremeUnitC库现在需要在链接阶段(通过add_library)与-ldl链接,另外-ldl需要添加到链接的末尾行(似乎对gcc进行了一些更改)。在以前的Ubuntu版本中,直到测试对象与ExtremeUnitC库链接起来,add_library目标才需要-ldl

I wrote/maintain a small unit test library on github https://github.com/acgreek/ExtremeCUnit built using cmake. You can checkout and run some tests via 'cmake test' after checking out. It was working great on Cygwin and Ubuntu (my only home systems). I recent upgrade to ubuntu 13.10 and the library stopped linking with the test binary because the ExtremeUnitC library now needs to be linked with -ldl at the link stage (via add_library) and additionally the -ldl needs to be add to the end of the link line (some change to gcc it seems). In prior version of Ubuntu, the add_library target didn't need the -ldl until the test object was linked with the ExtremeUnitC library

基本上,我需要的是进入下一阶段时,使VERBOSE = 10

Basically what I need is for the results of make VERBOSE=10, when it get to the following stage

Linking C shared library libExtremeCUnit.so
/usr/bin/cmake -E cmake_link_script CMakeFiles/ExtremeCUnit.dir/link.txt --verbose=10
/usr/bin/gcc  -fPIC -Wall -Wextra -ggdb3 -fPIC  -ldl   -shared -Wl,-    soname,libExtremeCUnit.so -o libExtremeCUnit.so CMakeFiles/ExtremeCUnit.dir/main.c.o CMakeFiles/ExtremeCUnit.dir/runner.c.o CMakeFiles/ExtremeCUnit.dir/util.c.o CMakeFiles/ExtremeCUnit.dir/findtest_names.c.o CMakeFiles/ExtremeCUnit.dir/assert_support.c.o 

我需要它,

Linking C shared library libExtremeCUnit.so
/usr/bin/cmake -E cmake_link_script CMakeFiles/ExtremeCUnit.dir/link.txt --verbose=10
/usr/bin/gcc  -fPIC -Wall -Wextra -ggdb3 -fPIC  -ldl   -shared -Wl,-    soname,libExtremeCUnit.so -o libExtremeCUnit.so CMakeFiles/ExtremeCUnit.dir/main.c.o CMakeFiles/ExtremeCUnit.dir/runner.c.o CMakeFiles/ExtremeCUnit.dir/util.c.o CMakeFiles/ExtremeCUnit.dir/findtest_names.c.o CMakeFiles/ExtremeCUnit.dir/assert_support.c.o -ldl

应该如何我可以通过干净/便携式的方式将CMakeList.txt编辑为该文件吗?

how should I edit my CMakeList.txt to that in a clean/portable way?

您还可以向我发送请求请求,这样您就可以修复它了。

You can also send me a pull request so you can get the credit of fixing it.

推荐答案

我只需要添加

target_link_libraries(ExtremeCUnit dl)

这篇关于在add_library的链接阶段结束时,CMake add -ldl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!