Skip to content

Link error when building tests and examples under Windows with msys2 tool chain #976

@jalvesz

Description

@jalvesz
Contributor

Description

I'm trying to build and test stdlib on a Windows machine with msys2 tool chain, using gnu compilers (gcc/gfortran) 14.2.0-3 version.

I have a small python script to customize the cmake build as:

# build with cmake
subprocess.run("cmake -B build -G Ninja -DBUILD_TESTING=on"+
                   " -DCMAKE_MAXIMUM_RANK:String=4 "+
                   " -DCMAKE_BUILD_TYPE=Release"+
                   " -DCMAKE_Fortran_COMPILER=gfortran", 
                   shell=True, check=True) 
subprocess.run("cmake --build build -j 16",shell=True, check=True)
subprocess.run("ctest --test-dir build/test",shell=True, check=True)

I another machine where I use the tool chain from equation.com everything works, but here I get the following error when linking the hash_functions tests:

[376/695] Linking CXX executable test\hash_functions\test_hash_functions.exe
FAILED: test/hash_functions/test_hash_functions.exe
C:\WINDOWS\system32\cmd.exe /C "cd . && C:\msys64\ucrt64\bin\c++.exe -O3 -DNDEBUG  test/hash_functions/CMakeFiles/test_hash_functions.dir/test_hash_functions.f90.obj test/hash_functions/CMakeFiles/test_hash_functions.dir/nmhash.c.obj test/hash_functions/CMakeFiles/test_hash_functions.dir/pengyhash.c.obj test/hash_functions/CMakeFiles/test_hash_functions.dir/SpookyV2.cpp.obj test/hash_functions/CMakeFiles/test_hash_functions.dir/SpookyV2Test.cpp.obj test/hash_functions/CMakeFiles/test_hash_functions.dir/waterhash.c.obj test/hash_functions/CMakeFiles/test_hash_functions.dir/generate_hash_arrays.cpp.obj -o test\hash_functions\test_hash_functions.exe -Wl,--out-implib,test\hash_functions\libtest_hash_functions.dll.a -Wl,--major-image-version,0,--minor-image-version,0  src/libfortran_stdlib.a  _deps/test-drive-build/libtest-drive.a  -lgfortran  -lquadmath  -lm  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."       
collect2.exe: error: ld returned 116 exit status

Expected Behaviour

should link, build and run

Version of stdlib

master

Platform and Architecture

Windows (mingw-64)

Additional Information

No response

Activity

jalvesz

jalvesz commented on Apr 11, 2025

@jalvesz
ContributorAuthor

If I comment out the following tests from the CMake

#add_subdirectory(hash_functions)
#add_subdirectory(hash_functions_perf)

I managed to launch all other tests.

added
build: cmakeIssue with stdlib's CMake build files
platform: WindowsBuild issues specific to the Windows platform
and removed
bugSomething isn't working
on Apr 17, 2025
jalvesz

jalvesz commented on Apr 24, 2025

@jalvesz
ContributorAuthor

My bad, I had to specify the three compilers as:

-DCMAKE_Fortran_COMPILER=gfortran -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++

Closing this issue as there is no issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    build: cmakeIssue with stdlib's CMake build filescompiler: gfortranSpecific to GCC Fortran compilerplatform: WindowsBuild issues specific to the Windows platform

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jalvesz

        Issue actions

          Link error when building tests and examples under Windows with msys2 tool chain · Issue #976 · fortran-lang/stdlib