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?
Qt 6.11 is out! See what's new in the release blog

Why external Makefile not working in Qt project?

Scheduled Pinned Locked Moved Solved Qt 6
makefileqprocessg++linker errorssystem
5 Posts 2 Posters 1.7k 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 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);
    
    JonBJ 1 Reply Last reply
    0
    • O OroszB

      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);
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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 JonBJ 2 Replies Last reply
      1
      • JonBJ JonB

        @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 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
        • JonBJ JonB

          @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?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on 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 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

            • Login

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