Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MLIR] Build broken on Windows with GNU tools. #64150

Open
carlo-bramini opened this issue Jul 27, 2023 · 2 comments
Open

[MLIR] Build broken on Windows with GNU tools. #64150

carlo-bramini opened this issue Jul 27, 2023 · 2 comments

Comments

@carlo-bramini
Copy link
Contributor

carlo-bramini commented Jul 27, 2023

I tried to build mlir on Windows, but I got many errors on undefined references when linking mlir-tblgen.exe:

llvm-mlir

If you look the attached screenshot, you can see that I have highlighted lib/libMLIRTableGen.a.
This is a static library and it is the cause of the problem, because it has not its dependencies satisfied.
By looking into the generated build.ninja file, I have found this line, which provides the above libraries when linking:

LINK_LIBRARIES = lib/libLLVMCodeGenTypes.dll.a  lib/libMLIRTblgenLib.a  lib/libLLVMTableGen.dll.a  lib/libLLVMSupport.dll.a  lib/libLLVMDemangle.dll.a  lib/libMLIRTableGen.a

I just did a quick hack to this file, by changing the above line to:

LINK_LIBRARIES = lib/libMLIRTblgenLib.a  lib/libMLIRTableGen.a lib/libLLVMCodeGenTypes.dll.a  lib/libLLVMTableGen.dll.a  lib/libLLVMSupport.dll.a  lib/libLLVMDemangle.dll.a

After that, mlir-tblgen.exe has been linked successfully.
Actually, the libraries should respect some order when linking, something like:

static_lib1.a import_deps_for_lib1.dll.a   static_lib2.a import_deps_for_lib2.dll.a ...etc

or all static libraries and then all import libraries if you prefer.
It is interesting to notice that lib/libMLIRTblgenLib.a and lib/libMLIRTableGen.a cannot be swapped, lib/libMLIRTblgenLib.a must be written before lib/libMLIRTableGen.a, otherwise you will got lot of undefined references again.
Evidently, one static library is also a dependency for the other one.
MSVC does not seem to suffer about this behaviour on libraries at link time.

I configured the sources according to the guidelines, by using this command line:

cmake ../a/llvm-project/llvm -G Ninja -DCMAKE_BUILD_TYPE=Release -Wno-dev -DBUILD_SHARED_LIBS=ON -DLLVM_ENABLE_PROJECTS="lld;clang;clang-tools-extra;bolt;cross-project-tests;polly;libclc;mlir"

This effect happens with GCC for CYGWIN and MinGW-w64 cross compiler.
I'm using -DBUILD_SHARED_LIBS=ON on the command line since this is the only way to bypass issue #60659 for me.

EDIT: unfortunately, I was not able to find the right point for fixing this issue, if somebody could give me some suggestions about the fixes to do, I could test them and provide a patch at https://reviews.llvm.org/.

I'm using the development sources from head, 4f30746.

@llvmbot
Copy link
Member

llvmbot commented Jul 27, 2023

@llvm/issue-subscribers-mlir

@carlo-bramini
Copy link
Contributor Author

Actually, building mlir-pdll.exe shows the same identical problem, but when the issue on mlir-tblgen.exe will be solved, probably mlir-pdll.exe will be solved too.

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

No branches or pull requests

3 participants