How do I add more source files to the Makefile when using the Unix-toolchain? I've tried a lot of different things but there's always something missing.
How to use more than one source file
(11 posts) (4 voices)-
Posted 5 years ago #
-
If you have more than one file, they have to be #include-d from main.cpp as appropriate, but that should just work. Have you tried that?
Posted 5 years ago # -
Yes header files are included. But the .c-files aren't compiled, and if I can make them be compiled, the wirish and libmaple directories aren't in the include path. And if I manage to get the include path there, the compiled object files aren't linked with the final app...
But do you mean that if I have foo.h and foo.c (or .cpp) in the same directory as main.cpp it's supposed to work without mentioning any of them in the Makefile? In my tests it was diskio.h, sd_spi_stm32.c, ff.h, ff.c (i.e. not always .h/.c-pairs) for a start, but no .c file is compiled.
(btw. I'm not talking about the IDE, I prefer to use emacs and make)
Posted 5 years ago # -
I see what you mean. The make rule which targeted main.o was previously in a pretty hidden place; I've pushed a change to our libmaple github repository which exposes it:
$ cd $LIB_MAPLE_HOME
$ git pullYou should see some noise about build-targets.mk, and the top-level directory will then contain a file by that name. That's where the rule to build main.o lives. Copy it over to your project directory as well (the same way you did with the Makefile). Hopefully, you can add to its prerequisites to get everything to build correctly for your project; if you're using emacs and make, hopefully you know what that means.
I realize that this is not too user-friendly and apologize, but we're all pushing towards IDE 0.0.7 at the moment. We'll fix things up later so you'll only have to edit a list of your c/c++ sources and update this thread then.
Posted 5 years ago # -
Yeah, that seems to work. I've got a small test.h/test.c to compile and link with the main program.
Thanks!Posted 5 years ago # -
Great, glad to hear it! Let us know if you run into any more problems.
Posted 5 years ago # -
Sorry, I'm new to makefiles and build-targets.mk makes no sense to me right now.
Where can I learn to understand the "prerequisites" of build-targets.mk if I need to compile other source files within my project folder during make?
Posted 4 years ago # -
Tokenekie,
Modifying build-targets.mk was a hack I proposed so that snigelen could get his job done. The right thing to do for multiple source files is to link against a precompiled libmaple archive. Instructions for building a libmaple.a are in the top-level README of libmaple's master branch (at the bottom, section "Instructions to create a library"). (This information will be folded into the official 0.0.10 docs).
If you're asking for more information about libmaple's build structure, it is based on the recommendations made in the paper "Recursive Make Considered Harmful":
Posted 4 years ago # -
Until a pretty way for supporting multiple source files is released, is it possible to have some documentation on how to "hack" the
build-targets.mk
file to support multiple source files? I have my main.cpp file, but I also have a few other c and cpp files I need compiled. I could of course copy everything into main.cpp, but then I'd have an unorganized mess.Posted 4 years ago # -
robodude666,
Not sure what you mean by "pretty" -- what sort of thing would you like?
If you don't like the idea of linking against libmaple.a, you may be able to modify Xavier's setup in his preen project to your purposes:
Posted 4 years ago # -
Nothing specific.
After a few hours of messing around, and referencing my AVR makefiles, I ended up with something similar though not as pretty. I'll update my makefile later when I reorganize my project.
Posted 4 years ago #
Reply
You must log in to post.