Help, error: expected constructor, destructor, or type conversion before '(' token

Hello all, I’m relatively new to this and I’m starting my first big project.
I’m making a simple gamepad controller using the Joystick Library and I cant figure out how to fix it.
Can anyone help me?

Error message:

JoystickFinal:12:18: error: expected constructor, destructor, or type conversion before ‘(’ token

Joystick_Joystick(0x15, JOYSTICK_TYPE_JOYSTICK, 4, 0, true, true, false, false, false, false,
-----------------------^
false, false, false, false, false);

Don’t post snippets (Snippets R Us!)


aren’t you missing a space?
Joystick_space hereJoystick(0x15, JOYSTICK_TYPE_JOYSTICK, 4, 0, true, true, false, false, false, false,...

I knew it was something simple like that! thanks

What does it mean if something isn’t declared in the scope?
I have quite a few of that error

Edit: Nevermind, I figured that one out lol

OK this one is way over my head:

C:\Users\propm\AppData\Local\Temp\ccVYxV9W.ltrans0.ltrans.o: In function Joystick_::sendState() [clone .constprop.19]': C:\Program Files (x86)\Arduino\libraries\ArduinoJoystickLibrary-master/Joystick.cpp:677: undefined reference to DynamicHID()’
C:\Program Files (x86)\Arduino\libraries\ArduinoJoystickLibrary-master/Joystick.cpp:677: undefined reference to DynamicHID_::SendReport(unsigned char, void const*, int)' C:\Users\propm\AppData\Local\Temp\ccVYxV9W.ltrans0.ltrans.o: In function global constructors keyed to 65535_0_JoystickFinal.ino.cpp.o.2185’:
:(.text.startup+0x20a): undefined reference to DynamicHID()' <artificial>:(.text.startup+0x210): undefined reference to DynamicHID_::AppendDescriptor(DynamicHIDSubDescriptor*)’
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Leonardo.

Also there has to be a better way to post code and errors, what is it?

post the full code, explain which library (links to source) you are using, on which hardware, how things are wired and powered (electrical diagram not fritzing ), which version of the IDE etc…

Tutorial I’m following: Arduino Joystick 2.0 Library - Beginners Guide - YouTube

Libraries: GitHub - MHeironimus/ArduinoJoystickLibrary: An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.

Hardware: Arduino Pro Micro, 3 tactile buttons, 1 joystick with built in button.

IDE Version 1.8.13

Full Code:

 #include <Joystick.h>


#define joyX A0
#define joyY A1
#define joyButton 2
#define button1 3
#define button2 4
#define button3 5

Joystick_ Joystick(0x15, JOYSTICK_TYPE_JOYSTICK, 4, 0, true, true, false, false, false, false, false, false, false, false, false);

const bool initAutoSendState = true;

int xAxis_ = 0;
int yAxis_ = 0;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int joyButtonState = 0;

void setup() {
  pinMode(joyButton, INPUT_PULLUP);
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);

  Joystick.begin();

}

void loop() {
  xAxis_ = analogRead(joyX);
  xAxis_ = map(xAxis_, 0, 1023, 0, 255);
  Joystick.setXAxis(xAxis_);

  yAxis_ = analogRead(joyY);
  yAxis_ = map(yAxis_, 0, 1023, 0, 255);
  Joystick.setYAxis(yAxis_);

  int currentjoyButtonState = !digitalRead(joyButton);
  if (currentjoyButtonState != joyButtonState) {
    Joystick.setButton (0, currentjoyButtonState);
    joyButtonState = currentjoyButtonState;
  }

  int currentButtonState1 = !digitalRead(button1);
  if (currentButtonState1 != buttonState1) {
    Joystick.setButton (0, currentButtonState1);
    buttonState1 = currentButtonState1;
  }

  int currentButtonState2 = !digitalRead(button2);
  if (currentButtonState2 != buttonState2) {
    Joystick.setButton (0, currentButtonState2);
    buttonState2 = currentButtonState2;
  }

  int currentButtonState3 = !digitalRead(button3);
  if (currentButtonState3 != buttonState3) {
    Joystick.setButton (0, currentButtonState3);
    buttonState3 = currentButtonState3;
  }

  delay(10);

}

Full Error message:

C:\Users\propm\AppData\Local\Temp\ccVYxV9W.ltrans0.ltrans.o: In function `Joystick_::sendState() [clone .constprop.19]':
C:\Program Files (x86)\Arduino\libraries\ArduinoJoystickLibrary-master/Joystick.cpp:677: undefined reference to `DynamicHID()'
C:\Program Files (x86)\Arduino\libraries\ArduinoJoystickLibrary-master/Joystick.cpp:677: undefined reference to `DynamicHID_::SendReport(unsigned char, void const*, int)'
C:\Users\propm\AppData\Local\Temp\ccVYxV9W.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_JoystickFinal.ino.cpp.o.2185':
<artificial>:(.text.startup+0x20a): undefined reference to `DynamicHID()'
<artificial>:(.text.startup+0x210): undefined reference to `DynamicHID_::AppendDescriptor(DynamicHIDSubDescriptor*)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Leonardo.

When you get weird library compile error such as

It’s always good to Google it as you are likely not the first one to see it

Have a look at Arduino Pro Micro · Issue #38 · MHeironimus/ArduinoJoystickLibrary · GitHub

Got it!
I had manually installed the library and did it wrong.

Now I have an uploading error however:

Sketch uses 7820 bytes (27%) of program storage space. Maximum is 28672 bytes. Global variables use 284 bytes (11%) of dynamic memory, leaving 2276 bytes for local variables. Maximum is 2560 bytes. processing.app.debug.RunnerException at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:152) at cc.arduino.UploaderUtils.upload(UploaderUtils.java:77) at processing.app.SketchController.upload(SketchController.java:732) at processing.app.SketchController.exportApplet(SketchController.java:703) at processing.app.Editor$UploadHandler.run(Editor.java:2055) at java.lang.Thread.run(Thread.java:748) Caused by: processing.app.SerialException: Error touching serial port 'COM4'. at processing.app.Serial.touchForCDCReset(Serial.java:107) at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:136) ... 5 more Caused by: jssc.SerialPortException: Port name - COM4; Method name - openPort(); Exception type - Port busy. at jssc.SerialPort.openPort(SerialPort.java:164) at processing.app.Serial.touchForCDCReset(Serial.java:101) ... 6 more

seems you have something open already on the serial port

Yep, one system reset fixed that problem.

I do believe I just finished my first Arduino project!
Thanks for the help @J-M-L

congrats !!!

My 12 year daughter is making a smart glasses for a school project

she is getting an error in the programme

ROGMEM const char* weekString = {"", “Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”};

bitmap.h:1243:43: error: variable ‘bitmap_array’ must be const in order to be put into read-only section by means of ‘attribute((progmem))’

Missing a P ➜ PROGMEM

Also better to have PROGMEM after probably


const char* weekString[] PROGMEM = {…};

gives me another error message

PROGMEM const unsigned char* bitmap_array[ ICON_BITMAP_32] = {

Post the full code

—-
( please read How to get the best out of this forum and post accordingly (including code tags and necessary documentation))

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.