Visual Studio not compiling - arduino

I am trying to compile my code. If I compile it in Arduino IDE it works, but if I try it in Visual Studio 2019 it fails.
I am trying to use a struct as a parameter.
I have tried pointer and typedef, but get the same error
I can compile it in Arduino IDE, but the same code gets this error in VS 2019:
Compiling debug version of 'test' for 'ATmega2560 (Mega 2560) (Arduino Mega)'
test.ino: 7:17: error: variable or field 'myFunction' declared void
Error compiling project sources
Debug build failed for project 'test'
test.ino: 7:17: error: 'data' was not declared in this scope
test.ino:7: note suggested alternative atan
atan
struct data{
float data;
};
data data_struct;
void myFunction(data data_struct){
}
int main(){}

You did not provide a declaration for myFunction. That's done by the Arduino IDE behind the scenes.
Try:
struct data{
float data;
};
data data_struct;
void myFunction(data data_struct);
void myFunction(data data_struct){
}
int main(){}

Related

Emulating a yamaha fm chip inside arduino

I want to run an audio emulator of the genesis fm sound chip inside arduino. I plan to run it on a rp2040 which has plenty of power to run it
This is the emulator code:
https://github.com/nukeykt/Nuked-OPN2/blob/master/ym3438.h
And this is how Im trying to instantiate it, but I have errors. Can you point me on how to run the emulator?
#include "ym3438.h"
int buff = 0;
ym3438_t myChip;
void setup() {
}
void loop() {
buff++;
//this should advance the emultor clock
OPN2_Clock(myChip, buff);
//this should generate the sound samples
OPN2_Generate(myChip, buff);
}
Thanks!!
When trying to compile I get:
Compilation error: cannot convert 'ym3438_t' to 'ym3438_t*' for argument '1' to 'void OPN2_Clock(ym3438_t*, Bit16s*)'
I have tried putting* like:
OPN2_Clock(myChip*, buff*);
But it does not work either. Honesty Im not sure how to instantiate it

undefined reference to `_imp___ZN15QSerialPortInfo14availablePortsEv'

I am working on simple app on windows to scan the serial port.
Error:
undefined reference to `_imp___ZN15QSerialPortInfo14availablePortsEv'
My Code:
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
// do something
}
What does the error mean and how to fix it.
i only needed to add QT += serialport in my project (appname.pro) file.

Error while connecting lambda function to QProcess::error

In following code I want to connect lambda function to QProcess::error signal:
void Updater::start() {
QProcess process;
QObject::connect(&process, &QProcess::error, [=] (QProcess::ProcessError error) {
qWarning() << "error " << error;
});
process.start("MyProgram");
process.waitForFinished();
}
But I get strange error:
error: no matching function for call to 'Updater::connect(QProcess*
[unresolved overloaded function type],
Updater::start()::)' });
What I do wrong here? The code executes inside method of class derived from QObject. The project configured to work with c++11.
I use Qt 5.3.1 on Linux x32 with gcc 4.9.2
Problem is that the QProcess has another error() method, so compiler just doesn't know which method use. If you want to deal with overloaded methods, you should use next:
QProcess process;
connect(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>
(&QProcess::error), [=](QProcess::ProcessError pError) {
qWarning() << "error " << pError;
});
process.start("MyProgram");
process.waitForFinished();
Yes, it looks ugly, but there is no another way (only old syntax?).
This special line tells compiler that you want to use void QProcess::error(QProcess::ProcessError error), so now there is no any ambiguity
More information you can find here.
For those who are using Qt 5.6 or later, the QProcess::error signal is deprecated. You can use the QProcess::errorOccurred signal instead to avoid the naming ambiguity and complicated casting.
QProcess process;
connect(&process, &QProcess::errorOccurred, [=](QProcess::ProcessError error) {
qWarning() << error;
});
process.start("MyProgram");
process.waitForFinished();

freebsd network program compilation

I am trying to compile some simple networking programs on freebsd 8 and running into compilation issues. I am creating a simple client-server programs but no function or structure from networking is not getting compiled.
For eg. I use standard socket() call to create a socket but I run into an error "Called object socket is not a function."
If I remove the network code then my toy program compiles. For simplicity I have just put a simple example which does not compile. :
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
void main(){
int socket = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
printf("Could create sockets without any issues.\n");
}
I compiled it with "cc toy_prog.c -lc" and gave me the mentioned error.
A very simple error. You have defined a local variable with the same name as the external function you are trying to call (socket). Try the following and you will get the same error:
int f()
{
return 0;
}
void main()
{
int f = f();
}

Linking CIL with native code

In C++/CLI the following is sample code that links native and managed code within the same file.
#include "stdafx.h"
#pragma unmanaged
__declspec( dllexport ) void func2()
{
//native code goes here
}
#pragma managed
void func_clr()
{
func2(); //managed code calls native
}
#pragma unmanaged
__declspec( dllexport ) void func()
{
func_clr(); //native calls managed
}
#pragma managed
I am trying to experiment in getting other languages to link with managed code. I can compile other languages with the available tools and can compile CIL with ilasm. Ilasm produces the final .dll/.exe directly and I cant figure out a way to link in .obj files from other compilers.

Resources