MOD54415 WebServer webfuncs.cpp

Discussion to talk about software related topics only.
Post Reply
jediengineer
Posts: 192
Joined: Mon Dec 17, 2012 6:24 am

MOD54415 WebServer webfuncs.cpp

Post by jediengineer »

Hey all,

So I tried creating a separate file for my project called "WebFuncs.cpp" to house all of the web server functions I'll be using, and I'm getting a compiler error I don't understand (newb). I attached my project, could someone look at it? A lot of it is copy and paste from NB examples, and the whole thing worked well until I messed with the web server routines and made a separate file to handle them... Thanks All!!
Attachments
WebControls.zip
(298.95 KiB) Downloaded 319 times
User avatar
dciliske
Posts: 624
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: MOD54415 WebServer webfuncs.cpp

Post by dciliske »

So... You've got multiple things wrong; it'll be easiest if I just make a list :D

1. You're including a '.cpp' file. <- Don't ever do this (unless you really know what your doing and have an extremely good reason, and you're still probably wrong).
2. We're missing include guards in NetworkDebug.h (sorry). I've put them in and committed.
3. FooWithParameters and UnitInfo are not defined in HtmlVar.h.
4. Foo is not declared as 'extern "C"' in WebFuncs.cpp.
5. If you are building this as a makefile project (aka not using NBEclipse), you'll need to add WebFuncs.cpp to the CXXRSRCS list.

I think that's everything that was an issue.
Dan Ciliske
Project Engineer
Netburner, Inc
jediengineer
Posts: 192
Joined: Mon Dec 17, 2012 6:24 am

Re: MOD54415 WebServer webfuncs.cpp

Post by jediengineer »

Thanks!

So I am doing this as an NBEclipse project, I made sure of that.

I'm not understanding what you meant about the networkdebug.h file... could you elaborate? and what do I do on my end to get rid of that error?

Including the .cpp file was a mistake, I was originally going to copy over the webfuncs.h and include that - I must have added .cpp instead of .h by mistake. It has been removed all together.

FooWithParameters, Foo, and UnitInfo are defined in both copies of HtmlVar.h, the one in the html folder, and the one in the main folder.

Foo is now declared as 'extern"C"'

Could you try to build this? I'm still getting the same errors, plus some... I re-attached the project. Maybe has something to do with the NetworkDebug.h ? Please advise, and let me know if there's anything I can change in the file to get back on track here. Thanks!
Attachments
WebControls.zip
(301.74 KiB) Downloaded 279 times
User avatar
dciliske
Posts: 624
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: MOD54415 WebServer webfuncs.cpp

Post by dciliske »

Oh, my apologies, I remembered my changes incorrectly; they should be declared as extern "C" in htmlvar.h Also, could you also be sure to include you're actual console output (which will include the error) when you post problems with a project? Often times simply seeing the error and console output is enough to determine the cause of the problem.

As for NetworkDebug.h, I'm referring to a C/C++/general programming idiom called an "include guard". The gist of an include guard is that you place it in a header file to protect against multiple inclusions of that file's source in a single source file. This is relevant because include files should as a matter of good programming practice include all of their dependencies, and as a result headers are often included multiple times. The gist is that you wrap the entire contents of the header file inside one giant ifndef and as the ifndef's first line define the macro you check is not defined, like this:

Code: Select all

#ifndef  NETWORKDEBUG_H
	#define  NETWORKDEBUG_H

         ..... Header stuff goes here .....

        #endif
Dan Ciliske
Project Engineer
Netburner, Inc
jediengineer
Posts: 192
Joined: Mon Dec 17, 2012 6:24 am

Re: MOD54415 WebServer webfuncs.cpp

Post by jediengineer »

Thanks Dan,

The Extern"C" fixed everything... Good to go!!! I also edited the NetworkDebug.h file and fixed that as you wrote. Should be good to go.



Tony
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: MOD54415 WebServer webfuncs.cpp

Post by tod »

Code: Select all

#pragma once
At the top of an include file also works as an include guard for most development environments. I like it because
  • It's cleaner
  • you can't accidentally forget or delete the #endif of the standard include guards.
Some people don't like it because it has the potential to be less portable, but I have yet to use a dev. environment that doesn't support it.
Post Reply