Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Zacharyprime opened this issue Mar 3, 2021 · 2 comments
Open

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

Zacharyprime opened this issue Mar 3, 2021 · 2 comments

Comments

@Zacharyprime
Copy link
Member

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++.

@Zacharyprime
Copy link
Member Author

Update:
I just realized that we removed the compile button in botui at some point. So it's possible the botui line is irrelevant to adding C++.

@chrehall68
Copy link
Contributor

Check out my PR in the harrogate repository! It allows for c or c++ (since this is should really be a harrogate thing and not a botui thing).

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

No branches or pull requests

2 participants