Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Why external Makefile not working in Qt project?
QtWS25 Last Chance

Why external Makefile not working in Qt project?

Scheduled Pinned Locked Moved Solved Qt 6
makefileqprocessg++linker errorssystem
5 Posts 2 Posters 948 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    OroszB
    wrote on 28 Apr 2022, 12:31 last edited by
    #1

    I have a Qt Widget Application in Ubuntu.
    I also have another project, which contains some .cpp files, this project has a Makefile.

    This Makefile looks like this:

    g++ -o Output main.cpp MyClass.h MyClass.cpp -std=c++11
    

    I have a model layer in the Qt project, here I want to call the Makefile of another project like this:

    QProcess process;
    process.setWorkingDirectory("/path/to/my/another/project/");
    process.setStandardErrorFile("/path/to/my/another/project/error.txt");
    process.start("make");
    process.waitForFinished();
    

    When the process finished in the error.txt I got linking errors.
    When I run this Makefile from terminal I got a proper output.

    What should I set in Qt to be able to use make or g++ command inside the code without any linking error?
    Which settings can ruin the compile or what should I change in my Qt project?

    I tried it many ways:
    create shell script when I call make command and process that script in Qt.
    create shell script when I type the full g++ command and process that script in Qt.
    I tried this:

    process.start("sh", QStringList() << "-c" << "g++ -o Output main.cpp MyClass.h MyClass.cpp -std=c++11");
    

    I used system function like this:

    system("g++ -o Output main.cpp MyClass.h MyClass.cpp -std=c++11);
    
    J 1 Reply Last reply 28 Apr 2022, 13:41
    0
    • O OroszB
      28 Apr 2022, 12:31

      I have a Qt Widget Application in Ubuntu.
      I also have another project, which contains some .cpp files, this project has a Makefile.

      This Makefile looks like this:

      g++ -o Output main.cpp MyClass.h MyClass.cpp -std=c++11
      

      I have a model layer in the Qt project, here I want to call the Makefile of another project like this:

      QProcess process;
      process.setWorkingDirectory("/path/to/my/another/project/");
      process.setStandardErrorFile("/path/to/my/another/project/error.txt");
      process.start("make");
      process.waitForFinished();
      

      When the process finished in the error.txt I got linking errors.
      When I run this Makefile from terminal I got a proper output.

      What should I set in Qt to be able to use make or g++ command inside the code without any linking error?
      Which settings can ruin the compile or what should I change in my Qt project?

      I tried it many ways:
      create shell script when I call make command and process that script in Qt.
      create shell script when I type the full g++ command and process that script in Qt.
      I tried this:

      process.start("sh", QStringList() << "-c" << "g++ -o Output main.cpp MyClass.h MyClass.cpp -std=c++11");
      

      I used system function like this:

      system("g++ -o Output main.cpp MyClass.h MyClass.cpp -std=c++11);
      
      J Offline
      J Offline
      JonB
      wrote on 28 Apr 2022, 13:41 last edited by JonB
      #2

      @OroszB
      Whatever the issue is, your later alternative procss.start() or system() calls should not help/be relevant/necessary.

      There is no reason why you should not be able to run a compilation/link elsewhere via QProcess.

      When the process finished in the error.txt I got linking errors.

      When I run this Makefile from terminal I got a proper output.

      You should analyse why the other process produces link errors --- what is wrong/goes wrong --- when run from your app instead of from the command line. (You should also redirect standard output as well as error --- you never know when something might appear there.)

      Purely at a guess: since you do seem to have set the working directory for the other process, which is good, are the environment variables the same when spawned from your first app/Qt Creator versus what they are set to when run from the command line?

      O J 2 Replies Last reply 28 Apr 2022, 13:59
      1
      • J JonB
        28 Apr 2022, 13:41

        @OroszB
        Whatever the issue is, your later alternative procss.start() or system() calls should not help/be relevant/necessary.

        There is no reason why you should not be able to run a compilation/link elsewhere via QProcess.

        When the process finished in the error.txt I got linking errors.

        When I run this Makefile from terminal I got a proper output.

        You should analyse why the other process produces link errors --- what is wrong/goes wrong --- when run from your app instead of from the command line. (You should also redirect standard output as well as error --- you never know when something might appear there.)

        Purely at a guess: since you do seem to have set the working directory for the other process, which is good, are the environment variables the same when spawned from your first app/Qt Creator versus what they are set to when run from the command line?

        O Offline
        O Offline
        OroszB
        wrote on 28 Apr 2022, 13:59 last edited by
        #3

        @JonB Which enviroment variables should I set in Qt? I know that exist the setProcessEnvironment() function, but I do not know what should I set with it.

        1 Reply Last reply
        0
        • J JonB
          28 Apr 2022, 13:41

          @OroszB
          Whatever the issue is, your later alternative procss.start() or system() calls should not help/be relevant/necessary.

          There is no reason why you should not be able to run a compilation/link elsewhere via QProcess.

          When the process finished in the error.txt I got linking errors.

          When I run this Makefile from terminal I got a proper output.

          You should analyse why the other process produces link errors --- what is wrong/goes wrong --- when run from your app instead of from the command line. (You should also redirect standard output as well as error --- you never know when something might appear there.)

          Purely at a guess: since you do seem to have set the working directory for the other process, which is good, are the environment variables the same when spawned from your first app/Qt Creator versus what they are set to when run from the command line?

          J Offline
          J Offline
          JonB
          wrote on 28 Apr 2022, 14:05 last edited by
          #4

          @JonB said in Why external Makefile not working in Qt project?:

          You should analyse why the other process produces link errors --- what is wrong/goes wrong --- when run from your app instead of from the command line. (You should also redirect standard output as well as error --- you never know when something might appear there.)

          1 Reply Last reply
          0
          • O Offline
            O Offline
            OroszB
            wrote on 28 Apr 2022, 17:31 last edited by
            #5

            I solved it, the makefile contains this command as well:

            flex MyLanguage.l
            

            and in the OS there is two intalled flex, Qt used the wrong one.

            1 Reply Last reply
            0

            4/5

            28 Apr 2022, 14:05

            • Login

            • Login or register to search.
            4 out of 5
            • First post
              4/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved