alle_meije
alle_meije

Reputation: 2480

Buidling NIfTI C library in Windows: undefined references?

I'm building the NIfTI C libraries on Windows using MinGW gcc 14.2.0 and CMake 3.30.3. I have noticed two things:

1: I had previously compiled the Z library, libz.dll.a with the same build tools, and although the path to the library was found automatically and I had set the include directory that holds zlib.h, compilation of the "znz" library required to open both .nii and .nii.gz files fails. I can make that work by also adding the directory to the CMAKE_C_FLAGS variable (and just to make sure, also to CMAKE_CXX_FLAGS).
2: Now I can compile the static libraries, including the executables etc., but when I check the BUILD_SHARED_LIBS flag to build DLLs, after successfully building libznz.dll, libnifticdf.dl, libniftiio.dll, second_test.exe, nifti_stats.exe, nifti1_test.exe building first_test.exe fails with the errors:

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

Does anyone understand

Upvotes: 0

Views: 45

Answers (1)

Brecht Sanders
Brecht Sanders

Reputation: 7305

Add -DBUILD_TESTING:BOOL=OFF to your cmake command line to skip building those tests when building with -DBUILD_SHARED_LIBS:BOOL=ON

Upvotes: 0

Related Questions