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 won't link (Read 6005 times)
ConversantMachines
Newbies
*
Offline


Posts: 3
Joined: Dec 6th, 2015
.c won't link
Dec 6th, 2015 at 8:56pm
Print Post  
AtmelStudio 7.0.634
Arduino IDE for Atmel Studio 7

Open the Blink example
Add a .c and header from Visual Micro menu
Declare void DoNothing() in .h
Define void DoNothing() {} in .c
Try to link

Linker tells me it can't find DoNothing()

I've attached the sample project.   

Can anyone get it to build?




« Last Edit: Dec 6th, 2015 at 9:32pm by ConversantMachines »  

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


Posts: 12186
Location: United Kingdom
Joined: Apr 10th, 2010
Re: .c won't link
Reply #1 - Dec 6th, 2015 at 9:09pm
Print Post  
Hi,

Have you included .c sources in projects before?  Is this your first time?

Thanks
  
Back to top
IP Logged
 
ConversantMachines
Newbies
*
Offline


Posts: 3
Joined: Dec 6th, 2015
Re: .c won't link
Reply #2 - Dec 6th, 2015 at 9:21pm
Print Post  
Hi Tim,

I've been developing C/C++ for over 25 years on numerous platforms including Visual Studio.  To answer your general question, have I included C sources in projects before? Yes, quite a few times  Smiley This is the first time I've included files in a VM project.  If I select New Arduino Class and Header, works like a charm. 

I turned on avr-gcc -Q flag and I see the symbol being generated and the linker is including the .o file.

Doesn't make any sense.  Can email you a zip of the solution if you have minute to take a look.

Thanks


  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12186
Location: United Kingdom
Joined: Apr 10th, 2010
Re: .c won't link
Reply #3 - Dec 6th, 2015 at 10:06pm
Print Post  
Okay so new to arduino? You are welcome to post your code or email to info[at]visualmicro.com

Did you add a ; after the prototype you created in the .h?

Did you #include the .h in the .c?

If you attempted to call the method from the .ino source did you mark the prototype as extern?

Does the code build when using the arduino ide?

Thanks

  
Back to top
IP Logged
 
ConversantMachines
Newbies
*
Offline


Posts: 3
Joined: Dec 6th, 2015
Re: .c won't link
Reply #4 - Dec 7th, 2015 at 1:01pm
Print Post  
Figured it out.

Guess avr-gcc is set for cpp by default so got to wrap pure C header files in extern "C" { } when including in .ino file (which is compiled as .cpp).

I've attached a copy of the Blink sketch that builds.
« Last Edit: Dec 7th, 2015 at 1:04pm by ConversantMachines »  

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


Posts: 12186
Location: United Kingdom
Joined: Apr 10th, 2010
Re: .c won't link
Reply #5 - Dec 7th, 2015 at 1:04pm
Print Post  
Yes that makes sense, Thanks
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint