我正在使用 MinGW gcc 14.2.0 和 CMake 3.30.3 在 Windows 上构建 NIfTI C 库。我注意到两件事:
1:我之前使用相同的构建工具编译了 Z 库 libz.dll.a,尽管自动找到了该库的路径并且我设置了包含
zlib.h
的包含目录,但“znz”的编译“打开 .nii
和 .nii.gz
文件所需的库失败。我可以通过将目录添加到 CMAKE_C_FLAGS
变量来实现此目的(只是为了确保也添加到 CMAKE_CXX_FLAGS
)。 BUILD_SHARED_LIBS
标志来构建DLL时,在成功构建libznz.dll
,libnifticdf.dl
,libniftiio.dll
,second_test.exe
之后, nifti_stats.exe
、nifti1_test.exe
构建 first_test.exe
失败并出现错误:ld.exe: CMakeFiles\nifti_stats.dir/objects.a(nifti_stats.c.obj):nifti_stats.c (.text.startup+0x27c): undefined reference to `nifti_intent_code'
ld.exe: CMakeFiles\nifti_stats.dir/objects.a(nifti_stats.c.obj):nifti_stats.c:(.text.startup+0x2f8): undefined reference to `nifti_stat2hzscore'
ld.exe: CMakeFiles\nifti_stats.dir/objects.a(nifti_stats.c.obj):nifti_stats.c:(.text.startup+0x34f): undefined reference to `nifti_stat2cdf'
ld.exe: CMakeFiles\nifti_stats.dir/objects.a(nifti_stats.c.obj):nifti_stats.c:(.text.startup+0x40a): undefined reference to `nifti_stat2rcdf'
ld.exe: CMakeFiles\nifti_stats.dir/objects.a(nifti_stats.c.obj):nifti_stats.c:(.text.startup+0x45a): undefined reference to `nifti_cdf2stat'
ld.exe: CMakeFiles\nifti_stats.dir/objects.a(nifti_stats.c.obj):nifti_stats.c:(.text.startup+0x508): undefined reference to `nifti_stat2zscore'
ld.exe: CMakeFiles\nifti_stats.dir/objects.a(nifti_stats.c.obj):nifti_stats.c:(.text.startup+0x5e7): undefined reference to `nifti_stat2cdf'
ld.exe: CMakeFiles\nifti_stats.dir/objects.a(nifti_stats.c.obj):nifti_stats.c:(.text.startup+0x607): undefined reference to `nifti_stat2cdf'
collect2.exe: error: ld returned 1 exit status
有谁明白吗
CMakeLists.txt
中的目录信息?将
-DBUILD_TESTING:BOOL=OFF
添加到 cmake
命令行,以便在使用 -DBUILD_SHARED_LIBS:BOOL=ON
构建时跳过构建这些测试