Page 1 of 2
Multi-file program in NXC
Posted: 12 Nov 2011, 18:30
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?
Re: Multi-file program in NXC
Posted: 12 Nov 2011, 18:35
by HaWe
do you mean:
including libraries to a main program by e.g.:
#include "xyz.h"
#include "abc.nxc"
?
Re: Multi-file program in NXC
Posted: 12 Nov 2011, 19:38
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.
Re: Multi-file program in NXC
Posted: 12 Nov 2011, 20:16
by HaWe
why #endif?
maybe you should post the code or at least a snippet...
Re: Multi-file program in NXC
Posted: 12 Nov 2011, 21:44
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...
}
Re: Multi-file program in NXC
Posted: 12 Nov 2011, 23:14
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...
Re: Multi-file program in NXC
Posted: 13 Nov 2011, 01:03
by fuzzball27
How do I compile the source code? The compiler complains about there not being a main task.
Re: Multi-file program in NXC
Posted: 13 Nov 2011, 03:46
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).
Re: Multi-file program in NXC
Posted: 13 Nov 2011, 09:08
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.
Re: Multi-file program in NXC
Posted: 13 Nov 2011, 19:19
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?