-
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);
-
@OroszB
Whatever the issue is, your later alternativeprocss.start()
orsystem()
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?
-
@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.)