Skip to content

Adding C++ functionality or switching to C++ instead of C #64

@Zacharyprime

Description

@Zacharyprime

This is the botui compilation code:

void ProgramsWidget::compile()
{
	QModelIndexList currents = ui->programs->selectionModel()->selectedIndexes();
	if(currents.size() != 1) return;

  	const QString name = m_model->name(currents[0]);

  	qDebug() << "compile clicked for " << name;

	const QString projectPath = botui::pathToKISS + name;


	const QDir includeDir(projectPath + "/include/");
	const QDir srcDir(projectPath + "/src/");

	QString binFilePath = projectPath + "bin/botball_user_program";

        QString compileCommand = "gcc -o " + binFilePath + " -lwallaby -lpthread -lm -I " + includeDir.absolutePath() + " " + srcDir.absolutePath() + "/*.c";
	qDebug() << compileCommand;

	QByteArray ba = compileCommand.toLatin1();
	const char *compileCommandC = ba.data();

	int ret = std::system(compileCommandC);


	qDebug() << "ret = " << ret;
}

The compiler is set to C directly by calling gcc.
If we wanted to switch to C++ we could just change this line:

QString compileCommand = "gcc -o " + binFilePath + " -lwallaby -lpthread -lm -I " + includeDir.absolutePath() + " " + srcDir.absolutePath() + "/*.c";

to:

QString compileCommand = "g++ -o " + binFilePath + " -lwallaby -lpthread -lm -I " + includeDir.absolutePath() + " " + srcDir.absolutePath() + "/*.cpp";

There is probably going to be other conflicts that are caused by this change, harrogate would also need to be changed to reflect this. I am not sure exactly what in Harrogate would need to be changed at this time, at some point I or whoever solves this issue will need to trace the path the code takes when you hit compile. Harrogate doesn't have any comments so it takes time to process what anything is. I am 70% sure that Harrogate feeds into pcompiler and pcompiler automatically determines the correct compiler, but I don't think g++ is setup as an option for pcompiler and it will default to gcc.

Additionally, I am unsure if KIPR as an organization will want to switch to C++, I don't know if there is some reason they decided to choose C. I view C as a primitive version of C++ and I can't think of a reason why you would choose to make a program in C over C++ other than experience level/simplicity. At very least I think we should add the option of C++.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions