Creating Linux Static Lib with Qt Project

Sysprogs forums Forums VisualGDB Creating Linux Static Lib with Qt Project

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #20619
    nahumb
    Participant

    Hi,

    I was trying to follow the tutorial “Creating Linux Libraries with Visual Studio” on https://visualgdb.com/tutorials/linux/libraries/

    Unlike in the tutorial, my project (not the lib) is a Qt project (“Use Qt”) and not an MS project (“Use MSBuild”), as in the tutorial.

    The lib was created as an MS project, as demonstrated in the tutorial.

    The problem is that when I try to add my lib reference to my Qt project I get an error message: “A reference to ‘libxx’ cannot be added
    because the two projects target different platforms.”

    Please advise.

    Thanks,

    Nahum Budin.

    #20620
    nahumb
    Participant

    And one more piece of information, if applicable, Linux machine = Raspberry Pi.

    Thanks,

    Nahum Budin.

    #20627
    support
    Keymaster

    Hi,

    Sorry, combining Qt-based projects with MSBuild-based libraries is not supported directly, but there are a few workarounds.

    The recommended approach would be to switch your Qt project to use MSBuild as described in this tutorial. It involves a few extra steps, but will give fine-grain control over various build settings, will result in faster builds and will allow compiling individual files to quickly check for errors.

    Another option would be to create a Qt application project and manually edit the .pro file to turn it into a library project as described here and then edit the .pro file of the main project to link with the output of the library project. Let us know if you need further help with this.

    #20642
    nahumb
    Participant

    Hi,

    Thanks for the prompt reply.

    I was trying to implement the 1st solution but after adding the Target Section XML lines from the tutorial to the .props file (the 2 GenericGNUtool sections),
    the project loading by VS failed.
    (I could not use the full file in the example, as it is using Qt5 while I’m using Qt4 (and its a long story why I haven’t been able switching to Qt5).

    So I tried the second approach.
    It works, but raised a new issue.
    In my case, I would like to build a static library that in addition to my code, links to other static libraries (e.g. Bluetooth), so it will be easier
    to use my (integrated) library that wraps the other libraries services with a higher level API.

    Is there a way to do it (I know that VS has the lib tool)?

    Thanks,

    Nahum Budin.

    #20643
    nahumb
    Participant

    So I have walked through the .props file (for the 1st approach) again, only to find out 2 fault spaces on the long lines :-(.
    Once removed, solution is now loaded and build successfully using MS build.
    However, every time I load the solution I get the following error message: “The selected toolchain is missing the MSBuild rule files. Do you want to regenerate them?”
    I select “Yes”, I get a dialog running Preparing Toolchain for MSBuils…. , but next time I load the solution I still get the error message.

    And please also do not forget my question regarding linking a static library to another static library.

    Thanks,

    Nahum Budin.

    #20648
    support
    Keymaster

    Hi,

    Please try installing VisualGDB 5.4 Preview 2 – it resolves several cases of the spurious “regenerate MSBuild rules” message.

    Regarding the static libraries, if you are using MSBuild, you can use the “Exported Settings” page of VS Project Properties – simply add your additional library names to the “exported library names” field and VisualGDB will automatically add them to the final executable you are linking.

    If you are using QMake, this might require writing custom build rules. You can try the suggestions described on this page, however using MSBuild should be generally easier as we have designed the “exported settings” mechanism specifically for this case.

    #20652
    nahumb
    Participant

    Once again thanks for the prompt and helpful reply. The MSBuild option, as suggested works fine.
    I would like now to use the cross compilation option and let my quad-core i7 do the hard work and not the Raspberry Pi using the build over the network option, as demonstrated in the tutorials presented so far.
    What should be changed in the processes of converting the Qt project (other than the commands paths) into MSBuild and creating the library?

    My next issue is, is there a way to set IntelliSence to recognize the library context (other than manually adding the .h files)?

    Thanks,

    Nahum Budin.

    #20653
    nahumb
    Participant

    Please also note the following build messages

    2>C:\Program Files (x86)\Sysprogs\VisualGDB\MSBuild\SysprogsPlatform.targets(38,3): warning MSB4011: “C:\Users\Nahum\AppData\Local\VisualGDB\FindComponents.props” cannot be imported again. It was already imported at “E:\Nahum\Workspace\RaspberryPi3\Projects\VS\AdjHeartRapiSynth1.0\AdjHeartRapiSynth1.0\AdjHeartRapiSynth1.0.vcxproj (48,5)”. This is most likely a build authoring error. This subsequent import will be ignored.
    2>C:\Program Files (x86)\Sysprogs\VisualGDB\MSBuild\SysprogsPlatform.targets(73,2): warning : Missing toolchain profile for 192.168.3.2, ID=’com.sysprogs.toolchain.default-gcc’, version=”. IntelliSense may produce incorrect results.

    Thanks,

    Nahum.

    #20660
    support
    Keymaster

    Hi,

    Sorry, just editing the .vcxproj file to switch to cross-compilation won’t be sufficient. Instead, please do the following:

    1. Create a new cross-compiled Qt project using the QMake project subsystem. This will get all Qt-related tools in sync and ensure they work. Ensure the project builds and starts properly.
    2. Create a new cross-compiled MSBuild project. This will get the toolchain profiles and other settings to work (it will also setup IntelliSense).
    3. Finally apply the same custom rules to the newly created MSBuild project. This will add support for invoking uic/moc so you can build your project fully automatically.

    Let us know if you run into any problems and we will help.

    #20665
    nahumb
    Participant

    Thank you for the reply.

    Sorry, but I don’t understand what do you mean by: “Finally apply the same custom rules to the newly created MSBuild project”

    Can you please provide me with more detailed instructions/tutorial/demo?

    Thanks,

    Nahum.

    • This reply was modified 6 years, 7 months ago by nahumb.
    #20670
    support
    Keymaster

    Hi,

    Sorry, we don’t have a specific tutorial for using Qt with MSBuild and a cross-compiler, although the steps will be very similar – obtaining a build log file and creating GenericGNUTool rules just like you did for the directly compiled project.

    If you are not comfortable modifying the .vcxproj file, please try using Raspberry Pi 3 for compilation – its 4-core CPU is fairly fast.

    #20677
    nahumb
    Participant

    OK Thanks.

    Can you please guide me to the .props dirs/files used by VGDB to build the remote/cross Qt/MSBuild versions?

    Thanks,

    Nahum.

    #20681
    support
    Keymaster

    Hi,

    No problem. All MSBuild-specific rules are located in the <VisualGDB directory>\MSBuild folder, although we generally don’t recommend patching them as updating VisualGDB will override your changes. Instead you can add custom rules files inside your source checkout and reference those additional files from your projects, combining VisualGDB rules with your custom rules.

    #20689
    nahumb
    Participant

    Thanks again.

    Yes, indeed not recommended (nor fun)…..

    Any chance you will provide it in the near future?

    Thanks,

    Nahum.

    #20692
    support
    Keymaster

    Hi,

    Sorry, as the steps are very similar, we don’t have any short-term plans for publishing another tutorial. That said, if you encounter any specific issues while trying to apply the steps from the current tutorial, feel free to post the details here and we will help you resolve them.

Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.