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

rust() and rust_mut() fails linking with MinGW gcc #397

Closed
qwxxx opened this issue Dec 18, 2022 · 12 comments
Closed

rust() and rust_mut() fails linking with MinGW gcc #397

qwxxx opened this issue Dec 18, 2022 · 12 comments
Labels
🪲 bug Something isn't working

Comments

@qwxxx
Copy link

qwxxx commented Dec 18, 2022

My code:

impl MyObject{
        pub fn test(& self) ->Option<()>{
            println!("Hello!");
            Some(())
        }
    }
  impl qobject::MyObject {
      #[qinvokable]
      pub fn test_base(&self){
          unsafe{
              self.rust().test();
          }
      }
}

Output:

C:/Qt/Tools/mingw900_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libvsb_terminal.a(my_object.cxx.o): in function `_ZN11QMetaObject12invokeMethodIZNK4rust9cxxqtlib111CxxQtThreadI8MyObjectE5queueIN16cxx_qt_my_object27MyObjectCxxQtThreadQueuedFnEEEvNS1_10cxxbridge12FnIFvRS4_NS9_3BoxIT_EEEEESE_EUlvE_EENSt9enable_ifIXaaaantsrN9QtPrivate15FunctionPointerISD_EE25IsPointerToMemberFunctioneqsrSL_13ArgumentCountLin1EntsrSt14is_convertibleISD_PKcE5valueEbE4typeEP7QObjectSD_N2Qt14ConnectionTypeEPDTclfL0p0_EE':
C:/Qt/6.2.4/mingw_64/include/QtCore/qobjectdefs.h:352: undefined reference to `__imp__ZN11QMetaObject16invokeMethodImplEP7QObjectPN9QtPrivate15QSlotObjectBaseEN2Qt14ConnectionTypeEPv'
collect2.exe: error: ld returned 1 exit status

It's working good with macos/clang with same code, but fails on windows/gcc.
What could be the reason?

@Be-ing
Copy link
Contributor

Be-ing commented Dec 18, 2022

Are you using CMake or building only with Cargo? GNU ld.bfd fails to link the qml-minimal-no-cmake example: #223

@Be-ing
Copy link
Contributor

Be-ing commented Dec 18, 2022

Can you try running cargo build -p qml-minimal-no-cmake in this repository?

@Be-ing
Copy link
Contributor

Be-ing commented Dec 18, 2022

We haven't been testing with MinGW, though maybe we should add that to CI...

@qwxxx
Copy link
Author

qwxxx commented Dec 18, 2022

Are you using CMake or building only with Cargo? GNU ld.bfd fails to link the qml-minimal-no-cmake example: #223

I'm using CMake 3.19 for build. All examples works, but when I add rust() or rust_mut(), this error happens.

@qwxxx
Copy link
Author

qwxxx commented Dec 18, 2022

Maybe there is another way to get access to rust object?

@ahayzen-kdab ahayzen-kdab changed the title rust() and rust_mut() fails linking with gcc rust() and rust_mut() fails linking with MinGW gcc Dec 19, 2022
@ahayzen-kdab ahayzen-kdab added the 🪲 bug Something isn't working label Dec 19, 2022
@ahayzen-kdab
Copy link
Collaborator

This seems odd how using rust/rust_mut causes the CxxQtThread queue stuff to have linker issues. We need to setup a MinGW environment to reproduce this and it would be good to have CI for that too.

For now does using MSVC work for you on Windows ? or is that not available for you ?

@qwxxx
Copy link
Author

qwxxx commented Dec 19, 2022

This seems odd how using rust/rust_mut causes the CxxQtThread queue stuff to have linker issues. We need to setup a MinGW environment to reproduce this and it would be good to have CI for that too.

For now does using MSVC work for you on Windows ? or is that not available for you ?

MSVC is not installed on my workstation yet, but I will do it soon

@qwxxx
Copy link
Author

qwxxx commented Dec 19, 2022

This seems odd how using rust/rust_mut causes the CxxQtThread queue stuff to have linker issues. We need to setup a MinGW environment to reproduce this and it would be good to have CI for that too.

For now does using MSVC work for you on Windows ? or is that not available for you ?

It looks like the problem is not in rust_mut(). the problem disappears when I remove the use of the qinvokable function in c++ code. Code with any functions compiles successfully as long as I don't use them in c++ code. With all this, using clang/macos and the same code, I can use all the functions without any problems

@Be-ing
Copy link
Contributor

Be-ing commented Dec 19, 2022

Can you link to your whole code repository?

@qwxxx
Copy link
Author

qwxxx commented Dec 19, 2022

Can you link to your whole code repository?

this is a commercial project, so I can't, unfortunately. I will try to make a minimal working project to reproduce the problem

@qwxxx
Copy link
Author

qwxxx commented Dec 19, 2022

I seem to have found the reason. It was necessary to add the line Qt::Qml to target_link_libraries, it is very strange that it depends on the platform and compiler, and i havent qml components in rust part.
target_link_libraries(${CRATE} INTERFACE Qt::Core Qt::Gui Qt::Qml#this line )

@Be-ing
Copy link
Contributor

Be-ing commented Dec 19, 2022

Yeah there can be some weird stuff with dependencies between Qt libraries. For example, on macOS, we have to link QtNetwork when QtQml is linked 🤷

.qt_modules(&["Qml", "Network"])

@Be-ing Be-ing closed this as completed Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants