Allow user to set linker arguments
MODIFY
src/ccmanager.cpp
src/ccmanager.cpp
@@ -19,13 +19,13 @@ const static QString s_testprogram = "int main() { return 0; }";
* - %1: path to compiler executable
* - %2: machine architecture
* - %3: machine ABI
+ * - %4: user compiler arguments
* - -x c: Enforce compilation as C language (allows us to use C++ compilers)
- * - %4: input source file
- * - %5: output executable
- * - -static-libgcc: Ensure that we link to a static stdlib
- * - -lm: link with the math library
+ * - %5: input source file
+ * - %6: output executable
+ * - %7: user linker arguments
*/
-const static QString s_baseCC = "%1 -march=%2 -mabi=%3 %4 -x c %5 -o %6 -static-libgcc -lm";
+const static QString s_baseCC = "%1 -march=%2 -mabi=%3 %4 -x c %5 -o %6 %7";
CCManager::CCManager() {
if (RipesSettings::value(RIPES_SETTING_CCPATH) == "") {
@@ -165,6 +165,9 @@ std::pair<QString, QStringList> CCManager::createCompileCommand(const QString& f
// Substitute in and out files
s_cc = s_cc.arg(filename).arg(outname);
+ // Substitute additional linker arguments
+ s_cc = s_cc.arg(RipesSettings::value(RIPES_SETTING_LDARGS).toString());
+
const auto arglist = s_cc.split(" ");
return {arglist[0], arglist.mid(1)};

MODIFY
src/ripessettings.h
src/ripessettings.h
@@ -11,6 +11,7 @@ namespace Ripes {
#define RIPES_SETTING_REWINDSTACKSIZE ("simulator_rewindstacksize")
#define RIPES_SETTING_CCPATH ("compiler_path")
#define RIPES_SETTING_CCARGS ("compiler_args")
+#define RIPES_SETTING_LDARGS ("linker_args")
#define RIPES_SETTING_CONSOLEECHO ("console_echo")
#define RIPES_SETTING_CONSOLEBG ("console_bg_color")
#define RIPES_SETTING_CONSOLEFONTCOLOR ("console_font_color")
@@ -29,6 +30,7 @@ const static std::map<QString, QVariant> s_defaultSettings = {
{RIPES_SETTING_REWINDSTACKSIZE, 100},
{RIPES_SETTING_CCPATH, ""},
{RIPES_SETTING_CCARGS, "-O0"},
+ {RIPES_SETTING_LDARGS, "-static-libgcc -lm"}, // Ensure statically linked executable + link with math library
{RIPES_SETTING_CONSOLEECHO, "true"},
{RIPES_SETTING_CONSOLEBG, QColor(Qt::white)},
{RIPES_SETTING_CONSOLEFONTCOLOR, QColor(Qt::black)},

MODIFY
src/settingsdialog.cpp
src/settingsdialog.cpp
@@ -171,7 +171,7 @@ QWidget* SettingsDialog::createEditorPage() {
CCHLayout->addWidget(pathBrowseButton);
- // Add compiler argument widget
+ // Add compiler arguments widget
auto [ccArgLabel, ccArgs] = createSettingsWidgets<QLineEdit>(RIPES_SETTING_CCARGS, "Compiler arguments:");
auto* CCArgHLayout = new QHBoxLayout();
CCArgHLayout->addWidget(ccArgLabel);
@@ -181,18 +181,26 @@ QWidget* SettingsDialog::createEditorPage() {
// have been added, implicitely validating the arguments along with it.
connect(ccArgs, &QLineEdit::textChanged, [=, ccpath = ccpath] { emit ccpath->textChanged(ccpath->text()); });
- pageLayout->addWidget(CCGroupBox);
+ // Add linker arguments widget
+ auto [ldArgLabel, ldArgs] = createSettingsWidgets<QLineEdit>(RIPES_SETTING_LDARGS, "Linker arguments:");
+ auto* LDArgHLayout = new QHBoxLayout();
+ LDArgHLayout->addWidget(ldArgLabel);
+ LDArgHLayout->addWidget(ldArgs);
+ CCLayout->addLayout(LDArgHLayout);
+ connect(ldArgs, &QLineEdit::textChanged, [=, ccpath = ccpath] { emit ccpath->textChanged(ccpath->text()); });
// Add effective compile command line view
auto* CCCLineHLayout = new QHBoxLayout();
CCCLineHLayout->addWidget(new QLabel("Compile command:"));
- m_compileCommand = new QLineEdit();
- m_compileCommand->setReadOnly(true);
+ m_compileCommand = new QLabel();
+ m_compileCommand->setWordWrap(true);
+ m_compileCommand->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+ m_compileCommand->setTextInteractionFlags(Qt::TextSelectableByMouse);
CCCLineHLayout->addWidget(m_compileCommand);
- CCCLineHLayout->setEnabled(false);
-
CCLayout->addLayout(CCCLineHLayout);
+ pageLayout->addWidget(CCGroupBox);
+
// Trigger initial rehighlighting
CCManager::get().trySetCC(CCManager::get().currentCC());

MODIFY
src/settingsdialog.h
src/settingsdialog.h
#include <QDialog>
QT_FORWARD_DECLARE_CLASS(QLineEdit);
+QT_FORWARD_DECLARE_CLASS(QLabel);
namespace Ripes {
@@ -26,7 +27,7 @@ private:
*/
void CCPathChanged(bool valid);
QLineEdit* m_ccpath = nullptr;
- QLineEdit* m_compileCommand = nullptr;
+ QLabel* m_compileCommand = nullptr;
QWidget* createEditorPage();
QWidget* createSimulatorPage();

Allow user to set linker arguments