C++ の新しいビルド システムとして gradle に切り替えました (以前は 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 を使用する方法を誰か教えてもらえますか?