semlanik / qtprotobuf

Protobuf generator and bindings for Qt framework
https://semlanik.github.io/qtprotobuf
MIT License
168 stars 38 forks source link

Cannot find QtProtobuf class after installation when using Felgo #156

Closed senlinmuvs closed 4 years ago

senlinmuvs commented 4 years ago

How to install it under the specified qt version instead of the system default, because my qt uses the Felgo framework, QT += protobuf, which can’t be referenced in the project.

sudo cmake --build . [--config <RELEASE|DEBUG>] --target install

Thanks!

semlanik commented 4 years ago

Hi, @senlinmuvs please try -DCMAKE_PREFIX_PATH="<path/to/qt/installation>/Qt<qt_version>/<qt_version>/gcc_64" -DCMAKE_INSTALL_PREFIX="<path/to/qt/installation>/Qt<qt_version>/<qt_version>/gcc_64" option, for cmake to specify special Qt install-path. @gmabey had issue #151 related to this functionality, but hopefully they was fixed.

senlinmuvs commented 4 years ago

@semlanik Thanks. The same after adding parameters.

cmake .. -DCMAKE_PREFIX_PATH="/usr/local/Felgo/Felgo/gcc_64/" -DCMAKE_INSTALL_PREFIX="/usr/local/Felgo/Felgo/gcc_64/"

sudo cmake --build . --config RELEASE --target install

It is now installed in the Felgo directory:

[sen@x Felgo]$ find . -type f -name "*protobuf*"
./gcc_64/bin/qtprotobufgen
./gcc_64/lib/cmake/QtProtobufProject/qtprotobufgenTargets-noconfig.cmake
./gcc_64/lib/cmake/QtProtobufProject/qtprotobufgenTargets.cmake
./gcc_64/include/QtProtobuf/qprotobufobject.h
./gcc_64/include/QtProtobuf/qabstractprotobufserializer_p.h
./gcc_64/include/QtProtobuf/qprotobufjsonserializer.h
./gcc_64/include/QtProtobuf/qtprotobufqttypesglobal.h
./gcc_64/include/QtProtobuf/qabstractprotobufserializer.h
./gcc_64/include/QtProtobuf/qtprotobuftypes.h
./gcc_64/include/QtProtobuf/qprotobufmetaproperty.h
./gcc_64/include/QtProtobuf/qtprotobufglobal.h
./gcc_64/include/QtProtobuf/qprotobufselfcheckiterator.h
./gcc_64/include/QtProtobuf/qtprotobuflogging.h
./gcc_64/include/QtProtobuf/qtprotobufqttypes.h
./gcc_64/include/QtProtobuf/qprotobufserializer.h
./gcc_64/include/QtProtobuf/qprotobufserializationplugininterface.h
./gcc_64/include/QtProtobuf/qprotobufmetaobject.h
./android_armv7/bin/qtprotobufgen
./android_armv7/lib/cmake/QtProtobufProject/qtprotobufgenTargets-noconfig.cmake
./android_armv7/lib/cmake/QtProtobufProject/qtprotobufgenTargets.cmake
./android_armv7/include/QtProtobuf/qprotobufobject.h
./android_armv7/include/QtProtobuf/qabstractprotobufserializer_p.h
./android_armv7/include/QtProtobuf/qprotobufjsonserializer.h
./android_armv7/include/QtProtobuf/qtprotobufqttypesglobal.h
./android_armv7/include/QtProtobuf/qabstractprotobufserializer.h
./android_armv7/include/QtProtobuf/qtprotobuftypes.h
./android_armv7/include/QtProtobuf/qprotobufmetaproperty.h
./android_armv7/include/QtProtobuf/qtprotobufglobal.h
./android_armv7/include/QtProtobuf/qprotobufselfcheckiterator.h
./android_armv7/include/QtProtobuf/qtprotobuflogging.h
./android_armv7/include/QtProtobuf/qtprotobufqttypes.h
./android_armv7/include/QtProtobuf/qprotobufserializer.h
./android_armv7/include/QtProtobuf/qprotobufserializationplugininterface.h
./android_armv7/include/QtProtobuf/qprotobufmetaobject.h

After adding QT+=protobuf:

Project ERROR: Unknown module(s) in QT: protobuf
senlinmuvs commented 4 years ago

@semlanik I feel that this path should be added to an environment variable, but don't know where to add:

/usr/local/Felgo/Felgo/gcc_64/include:/usr/local/Felgo/Felgo/android_armv7/include

I don’t know if it’s here, adding this doesn’t work: qt creator screenshot

semlanik commented 4 years ago

@senlinmuvs, at this point I have to say that crosscompilation is not supported by project yet. i see that you try to combine QtProtobuf with armv7 toolchain. But this won't work, for sure. I planned this task for upcomming release, and will try to implement ASAP.

senlinmuvs commented 4 years ago

@semlanik Thanks, that's it, is it now only supports desktop?

semlanik commented 4 years ago

@senlinmuvs formally yes, you may build for arm as well but it's tricky: You need to build x86/amd64 version first and use generator from this build directory and than build libraries for arm and use them while building and linking your project.

senlinmuvs commented 4 years ago

@semlanik Yeah, then I will wait for you to add this feature, thanks.

senlinmuvs commented 4 years ago

@semlanik Cross-compilation is always wrong and no solution is found. I feel that it should not be necessary to compile the library separately for the arm platform and then link it in. Qt itself can be cross-platform, all are implemented with the qt library, that is, the generated protocol code does not rely on other non-qt library code. Is it a good way?

I compiled and got this shit error, you see: https://stackoverflow.com/questions/63779557/make-error-when-cross-compiling-protobuf-for-arm-libs-libprotoc-so-error-un

semlanik commented 4 years ago

@senlinmuvs you already have crosscompiled qt for your platform. So "cross-platform" feature for C++ projects only mean that project might be compiled and run on platforms that it was compiled for.

QtProtobuf depends on Qt only at runtime, but for compilation it has also dependency on libprotoc that needs to be compiled for host platform (x86/amd64).

Probably the best option for you is to wait until I will complete cross-compilation procedure

senlinmuvs commented 4 years ago

@semlanik Okay, That's great. What I meant before was to do all byte padding and format conversion in the generated code, but it should be troublesome without relying on other libraries. I have now obtained several .so files of protobuf, and I am using them in pure c++. The generated protocol codes are .h and .cc, which seem to be normal, but there are many errors during compilation. These errors seem to have nothing to do with protobuf. Like:

/usr/local/lib/android/sdk/ndk/21.1.6352462/sources/cxx-stl/llvm-libc++/include/cmath:325: error: no member named 'isless' in the global namespace
using ::isless;
      ~~^
/usr/local/lib/android/sdk/ndk/21.1.6352462/sources/cxx-stl/llvm-libc++/include/cmath:317: error: no member named 'signbit' in the global namespace; did you mean '__signbit'?
using ::signbit;
      ~~^
...

The following is the library file I added:

android {
    QT += androidextras
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
    OTHER_FILES += android/AndroidManifest.xml android/build.gradle
    ANDROID_EXTRA_LIBS += \
        /home/sen/github/c/openssl-1.1.1g/libcrypto_1_1.so \
        /home/sen/github/c/openssl-1.1.1g/libssl_1_1.so \
        /home/sen/github/c++/protobuf/src/.libs/libprotobuf-lite.so \
        /home/sen/github/c++/protobuf/src/.libs/libprotobuf.so \
        /home/sen/github/c++/protobuf/src/.libs/libprotoc.so
}
INCLUDEPATH += /home/sen/github/c/openssl-1.1.1g/include
INCLUDEPATH += /usr/include #This is also very strange, the generated protocol code will not find the header file without this.