使FindLibDL CMake脚本不报告错误布尔值的失败

使FindLibDL CMake脚本不报告错误布尔值的失败,cmake,Cmake,我使用的是一个函数,除其他外,它确定了一些关于下划线的布尔值: # ... CHECK_C_SOURCE_RUNS("#include <dlfcn.h> #include <stdlib.h> void testfunc() {} int main() { testfunc(); if (dlsym(0, \"_testfunc\") != (void*)0) { return EXIT_SUCCESS; } else { return EX

我使用的是一个函数,除其他外,它确定了一些关于下划线的布尔值:

# ...
CHECK_C_SOURCE_RUNS("#include <dlfcn.h>
#include <stdlib.h>
void testfunc() {}
int main() {
  testfunc();
  if (dlsym(0, \"_testfunc\") != (void*)0) {
    return EXIT_SUCCESS;
  } else {
    return EXIT_FAILURE;
  }
}" LIBDL_NEEDS_UNDERSCORE)

mark_as_advanced(LIBDL_INCLUDE_DIRS LIBDL_LIBRARIES LIBDL_NEEDS_UNDERSCORE)
#。。。
检查源运行(“#包括
#包括
void testfunc(){}
int main(){
testfunc();
如果(dlsym(0,\“\u testfunc\”)=(void*)0){
返回退出成功;
}否则{
返回退出失败;
}
}“LIBDL_需要下划线)
标记为高级(LIBDL包含LIBDL库LIBDL需要下划线)

问题是,如果不需要下划线,CMake会报告
LIBDL\u NEEDS\u underline
的失败。我如何才能使它仍然确定相同的值,并且仍然没有报告为失败?

正如@arrowd points一样,这就是宏的工作方式:如果编译程序返回0,则报告成功,否则报告失败

如果需要其他输出,可以直接使用命令


例如,使用
try\u run
可以实现以下行为:

  • 如果需要下划线,则输出为

    Check whether 'dl' requires underscore - Yes
    
    Check whether 'dl' requires underscore - No
    
  • 如果不需要下划线,则输出为

    Check whether 'dl' requires underscore - Yes
    
    Check whether 'dl' requires underscore - No
    
  • 如果在检查过程中发生错误,则输出为

    Check whether 'dl' requires underscore - Failed
    

如果不需要下划线,则此变量包含
FALSE
。有什么问题吗?它正在按您的预期工作。@arrowd:问题是CMake的控制台输出告诉我某些东西失败了,而没有任何东西失败,它只是
FALSE
。哦,等等,
try\u run
命令接受一个源文件;但是我没有源文件,我只有模块。你是否建议我创建一个临时文件并使用它?或者有没有不涉及临时文件的技巧?创建临时源文件。就是这样。