Skip to content

Instantly share code, notes, and snippets.

@suy
Created May 25, 2020 07:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suy/69f7a3ae7701fed27b8fd5bc19a19cb2 to your computer and use it in GitHub Desktop.
Save suy/69f7a3ae7701fed27b8fd5bc19a19cb2 to your computer and use it in GitHub Desktop.
A simple tool to sort and print in a more human readable form the compiler output
#include <QtCore>
static void dump(const char* name, const QStringList& variable) {
QTextStream out(stdout);
out << variable.count() << " " << name << endl;
foreach (const QString& item, variable) {
out << " " << item << endl;
}
}
int main(int argc, char* argv[])
{
QCoreApplication application(argc, argv);
QStringList defines;
QStringList libraries;
QStringList libraryPaths;
QStringList includes;
QStringList objects;
foreach (const QString& element, application.arguments()) {
if (element.startsWith("-D"))
defines << element;
if (element.startsWith("-l"))
libraries << element;
if (element.startsWith("-L"))
libraryPaths << element;
if (element.startsWith("-I"))
includes << element;
if (element.endsWith(".o"))
objects << element;
}
qSort(defines);
qSort(libraries);
qSort(libraryPaths);
qSort(includes);
qSort(objects);
dump("defines", defines);
dump("libraries", libraries);
dump("library paths", libraryPaths);
dump("includes", includes);
dump("objects", objects);
return 0;
}
@suy
Copy link
Author

suy commented May 25, 2020

Just a quick paste. The code is old, and I did not bother to fix the usage of deprecated qSort, or port to range-for instead of foreach.

Usage: cat /tmp/compiler-cli.txt | xargs ./compiler-command-line-helper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment