Multi-file program in NXC

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
fuzzball27
Posts: 103
Joined: 29 Sep 2010, 17:14
Location: US

Multi-file program in NXC

Post by fuzzball27 »

I've been making attempts to create a multi-file program in NXC, but I have been having quite a bit of difficulty. I'm curious, what are the basics to tell the NBC compiler to treat all files as one program?
fuzzball27 >>-->
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Multi-file program in NXC

Post by HaWe »

do you mean:
including libraries to a main program by e.g.:
#include "xyz.h"
#include "abc.nxc"

?
fuzzball27
Posts: 103
Joined: 29 Sep 2010, 17:14
Location: US

Re: Multi-file program in NXC

Post by fuzzball27 »

Yes. That's what I'm asking about. The problem that I have is that the included file can't be compiled... also, the compiler keeps saying that #endif is an invalid preprocessor command.
fuzzball27 >>-->
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Multi-file program in NXC

Post by HaWe »

why #endif?
maybe you should post the code or at least a snippet...
fuzzball27
Posts: 103
Joined: 29 Sep 2010, 17:14
Location: US

Re: Multi-file program in NXC

Post by fuzzball27 »

I was using #ifndef to avoid multiple definitions. I deleted the code because it was very small. It was something like this:

Code: Select all

#ifndef _SOURCECODE
#define _SOURCECODE
//subroutines...
#endif
The main task was something like this:

Code: Select all

#include "Sourcecode.nxc"//The name of the previous code file.

task main() {
//code...
}
fuzzball27 >>-->
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Multi-file program in NXC

Post by HaWe »

that should have been correct, it's the same way I use it:

Code: Select all

  // file: stdlib.h
  #ifndef _STDLIB_H_
  #define _STDLIB_H_
  
  //******************************************************************************
  // code
  //******************************************************************************

  #endif // _STDLIB_H_
I assume there was a typo...
fuzzball27
Posts: 103
Joined: 29 Sep 2010, 17:14
Location: US

Re: Multi-file program in NXC

Post by fuzzball27 »

How do I compile the source code? The compiler complains about there not being a main task.
fuzzball27 >>-->
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Multi-file program in NXC

Post by mattallen37 »

I do it by throwing in a dummy task main(){}, and then just leave it uncommented to compile. Often I will use task main as a test task for functions that the library supports, and then comment it out whenever I am done testing (so that when I #include it in another program, it doesn't complain about two task mains).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Multi-file program in NXC

Post by HaWe »

I do it other way round:
I'm programming in one whole file, and when I think I will need one function or the other further on for other projects, I copy them into my existing stdlib.h and nxcio.h libraries. Debugging multi-file projects is not easy in Bricxcc.
But I agree, it would be desirable if one could have code-highlighting and test-compiling also of libraries / header files ( *.h) for syntax checking even without having a task main, in case there have been made some mistakes accidentally when having changed the code subsequently.
fuzzball27
Posts: 103
Joined: 29 Sep 2010, 17:14
Location: US

Re: Multi-file program in NXC

Post by fuzzball27 »

mattallen37 wrote:I do it by throwing in a dummy task main(){}, and then just leave it uncommented to compile.
How do you compile your final product all together?
fuzzball27 >>-->
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests