我已经换成 gradle 作为我的 C++ 新构建系统(尽管我之前将它与 java 一起使用)。现在,当我尝试使用构建文件链接 CUnit 以获取测试用例时
apply plugin: 'cpp'
apply plugin: 'cunit'
model {
platforms {
x64 {
architecture "x86_64"
}
}
repositories {
libs(PrebuiltLibraries) {
cunit {}
}
}
components {
smartio(NativeLibrarySpec) {
targetPlatform "x64"
sources {
cpp {
source {
srcDir 'src/smartio/cpp'
include '**/*.cpp'
}
exportedHeaders {
srcDir 'src/smartio/headers'
}
}
}
}
}
binaries {
all {
cppCompiler.args "-std=c++1y"
}
withType(CUnitTestSuiteBinarySpec) {
lib library: "cunit", linkage: 'api'
}
}
}
我仍然从 gradle 得到以下输出:
D:\\devel\\git\\SmartIO\\build\\objs\\smartioTestCUnitExe\\smartioTestCpp\\102afk7z0mm9rbcvlxwqfb3lp\\CUnitMain.obj:CUnitMain.cpp:(.text+0x4b): undefined reference to `CU_assertImplementation'
D:\\devel\\git\\SmartIO\\build\\objs\\smartioTestCUnitExe\\smartioTestCpp\\102afk7z0mm9rbcvlxwqfb3lp\\CUnitMain.obj:CUnitMain.cpp:(.text+0x4b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `CU_assertImplementation'
// ... omitted for brevity
D:\\devel\\git\\SmartIO\\build\\objs\\smartioTestCUnitExe\\smartioTestCunitLauncher\\e5tc4yn4yrorgux3jajanhtly\\gradle_cunit_main.obj:gradle_cunit_main.c:(.text+0x22): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `CU_get_number_of_failures'
D:\\devel\\git\\SmartIO\\build\\objs\\smartioTestCUnitExe\\smartioTestCunitLauncher\\e5tc4yn4yrorgux3jajanhtly\\gradle_cunit_main.obj:gradle_cunit_main.c:(.text+0x3c): undefined reference to `CU_get_failure_list'
基本上这告诉我 gradle 似乎找不到库 cunit 但不想告诉我。但是,当我从控制台构建它时,一切正常。我的示例测试文件,没什么特别的:
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <CUnit/Console.h>
int suite_init(void) {
return 0;
}
int suite_clean(void) {
return 0;
}
void test_example(void) {
CU_ASSERT(3 == 2);
}
void gradle_cunit_register() {
CU_pSuite mySuite = CU_add_suite("operator tests", suite_init, suite_clean);
CU_add_test(mySuite, "test", test_example);
}
#ifdef OUTSIDE_GRADLE
int main() {
CU_initialize_registry();
gradle_cunit_register();
CU_console_run_tests();
}
#endif
有人可以告诉我我缺少什么以及如何使用系统上预装的 cunit 版本吗?