Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 11 months ago.
How do I put multiple example cpp files in a project folder?
Hello, I'm trying to put several test .cpp files into a project so I can test various aspects of a library. I've tried this /media/uploads/JappieMike/multfiles1.tiff , but the compiler throws up "multiple definition" errors as the .cpp files are only slight variations of the same code. How do I need to arrange the test files?
2 Answers
9 years, 11 months ago.
You simply can't have multiple main() functions, it is strictly one application per project. You can use the pre-compiler #define method without putting all the code in one file.
buildOptions.h
// select program to build - Only uncomment 1. #define COMPILE_PROGRAM1 //#define COMPILE_PROGRAM2
In every file in program1s folder...
main.cpp
#include "buildOptions.h" #ifdef COMPILE_PROGRAM1 main() { ... } #endif
etc...
9 years, 11 months ago.
This is not about the files arrangement, is it? You can easily move files around the project, but all of them will be compiled and linked. The problem you have is that you want to compile some set of files within a program? If yes, that's not possible at the moment using flags or enviroment variables to change the build process.
You can however use preprocessor to remove code from compilation.
#if (COMPILE_THIS_CODE == 1) //code 1 #else //code 2 #endif
Hello Martin, I was hoping to have all the files for a project neatly encased under one main project header, that way if I ever thought they were good enough for wider publication they could go as one main heading with the library and examples in separate folders for easy compilation and use. Cheers Mike
posted by 18 Jan 2015