Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic C++ class linking causes error (Read 1225 times)
Fabruary22
Newbies
*
Offline


Posts: 3
Joined: Mar 17th, 2023
C++ class linking causes error
Mar 17th, 2023 at 12:22pm
Print Post  
Dear community. Pleas tell me what's wrong with my project.

Code
Select All
Compiling debug version of 'esp-rom' for 'Generic ESP8266 Module                                                                                                    (esp8266_generic)'
ld.exe: esp-rom.cpp.o:(.text.setup+0x44): undefined reference to _ZN10UpdaterEsp15printWiFiStatusEv
ld.exe: esp-rom.cpp.o:(.text.setup+0x48): undefined reference to _ZN10UpdaterEsp7listDirEPKc

ld.exe: esp-rom.cpp.o: in function setup
esp-rom.ino:174: undefined reference to _ZN10UpdaterEsp15printWiFiStatusEv
ld.exe: E:\IDE\ARDUINO\HTTP_stm32_uploader\esp-rom\esp-rom.ino:176: undefined reference to _ZN10UpdaterEsp7listDirEPKc

collect2.exe*: error: ld returned 1 exit status

Error linking for board Generic ESP8266 Module                                                                                                    (esp8266_generic)
Debug build failed for project 'esp-rom' 



I use Visual Studio Community 2022 and Visual Micro. 
There are three files, main.ino and pair of .h and .cpp with class declaration and definition. When i put class definition to main.ino all links fine but if different files error appears. I think it is so easy my mistake but i dont want to learn c++ just one program.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Fabruary22
Newbies
*
Offline


Posts: 3
Joined: Mar 17th, 2023
Re: C++ class linking causes error
Reply #1 - Mar 17th, 2023 at 12:23pm
Print Post  
3rd file with class declaration.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2377
Joined: Feb 13th, 2019
Re: C++ class linking causes error
Reply #2 - Mar 17th, 2023 at 1:01pm
Print Post  
We cannot assist with user specific code issues generally.

I believe the issue you have is the function definitions in the UpdaterEsp.cpp, are not qualified as belonging to the declared class.

i.e. instead of 
void listDir(const char* dirname)

It should be:
void UpdaterEsp::listDir(const char* dirname)
  
Back to top
 
IP Logged
 
Fabruary22
Newbies
*
Offline


Posts: 3
Joined: Mar 17th, 2023
Re: C++ class linking causes error
Reply #3 - Mar 17th, 2023 at 1:54pm
Print Post  
Excuse me. 100% you are right! I change scope of methods in .cpp file and it now compiled. Thank YOU
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint