-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example of possible makefile for mlpack examples #75
Conversation
@rcurtin I think this is a possible example for a Makefile. I only made it for one example, if it is good, I will copy it everywhere with minor modifications. |
Maybe we could add this makefile to our CI tests. |
Do we want to keep the current folder structure or do we want to put everything in the root directory? Depending on the decision, I think a single Makefile as all we need? |
@zoq I would prefer to have separate |
Maybe we can make it work for other examples? Like point users to this makefile and we make sure it works across all examples, and a user could call |
@shrit thanks for writing this up! I think I would agree that we should have one Makefile in each directory. My impression is that a user will come along and look at an individual directory, not at the whole project. But it seems like it would be easy to have the best of both worlds... just have a top-level Makefile call out recursively to all the subdirectories? This is a really generic Makefile, which is nice because we could just drop it in other directories, but it might be a little hard to understand for people not too familiar with the (really weird!) Makefile language. In some sense even the Makefile itself is an example, so I'd hope to keep it as simple as we can. But I'm not sure exactly where the right level is. The configurable parameters at the top are really nice, but maybe we can hardcode the sources and compilation commands, so we get something like this?
Might be good to put a disclaimer at the top or something, too, that says "you might need to modify this to get it to work on your system, but it should work in most places", or something like that. It's just an example after all, not meant to build in every possible place. 😄 Anyway, let me know what you think, these are just my opinions. We could go with something else if desired. |
I agree, one makefile by example seems to be a good idea, with a recursive call for the entire project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @shrit, looks good! Thanks for simplifying. I left a couple comments about the experiences I had while trying to use it; let me know what you think. Personally I think this looks good overall; want to deploy it to the other directories too? 👍
mnist_simple/Makefile
Outdated
default: all | ||
|
||
$(TARGET): $(OBJS) | ||
$(CXX) $(CXXFLAGS) $(INCLFLAGS) $(LIBS) $(LDFLAGS) $(OBJS) -o $(TARGET) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this work right on my system (I have to specify -L/home/ryan/src/mlpack/build/lib/
in LDFLAGS
and -I/home/ryan/src/mlpack/build/include/ -I/home/ryan/src/mlpack/build/deps/ensmallen-2.11.5/include/
in INCLFLAGS
), I had to move $(OBJS) -o $(TARGET)
to the beginning of the command:
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) $(OBJS) -o $(TARGET) $(INCLFLAGS) $(LDFLAGS) $(LIBS)
I think it is ready to be deployed on other examples. |
# LDFLAGS := -L/path/to/mlpack/library/ # if installed locally | ||
INCLFLAGS := -I . #Add header directories for any includes that aren't on the default compiler search path. | ||
|
||
OBJS := $(SRC:.cpp=.o) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe do we need to specify a separate rule for the .cpp -> .o compilation? The .cpps are being compiled without the INCLFLAGS
or CXXFLAGS
:
$ head -18 Makefile
# This is a simple Makefile used to build the example source code.
# This example might requires some modifications in order to work correctly on
# your system.
# If you're not using the Armadillo wrapper, replace `armadillo` with linker commands
# for the BLAS and LAPACK libraries that you are using.
TARGET := mnist_simple
SRC := mnist_simple.cpp
LIBS_NAME := armadillo mlpack boost_serialization
CXX := g++
CXXFLAGS := -std=c++11 -Wall -Wextra -O3 -DNDEBUG
# Use these CXXFLAGS instead if you want to compile with debugging symbols and without optimizations.
# CXXFLAGS := -std=c++11 -Wall -Wextra -g -O0
LDFLAGS := -fopenmp
LDFLAGS := -L/home/ryan/src/mlpack/build/lib/ # if installed locally
INCLFLAGS := -I/home/ryan/src/mlpack/build/include/ -I/home/ryan/src/mlpack/build/deps/ensmallen-2.11.5/include/ #Add header directories for any includes that aren't on the default compiler search path.
$ make
g++ -std=c++11 -Wall -Wextra -O3 -DNDEBUG -c -o mnist_simple.o mnist_simple.cpp
mnist_simple.cpp:16:10: fatal error: mlpack/core.hpp: No such file or directory
16 | #include <mlpack/core.hpp>
| ^~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: mnist_simple.o] Error 1
@rcurtin This one seems to be working, I kept one rule. If it seems good to you, I will deploy these modifications on other examples |
Nice, that seems to work. It seems also like you could use
(Of course, you would want to include the default I think that using
Anyway, up to you what you want to do. Overall it looks great to me---want to apply that the changes to all the other Makefiles? I think this PR is ready once you do that. 👍 |
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Co-Authored-By: Ryan Curtin <ryan@ratml.org>
Co-Authored-By: Ryan Curtin <ryan@ratml.org>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
Signed-off-by: Omar Shrit <shrit@lri.fr>
@rcurtin I think we can merge it now, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks @shrit! It looks good to me and works on my setup. My last super minor comment: maybe it's better to use +=
for the LDFLAGS
too? Up to you if you want to make the change.
Signed-off-by: Omar Shrit <shrit@lri.fr>
@@ -0,0 +1,36 @@ | |||
# This is a simple Makefile used to build the example source code. | |||
# This example might requires some modifications in order to work correctly on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are using the same style guidelines here as for the mlpack repo, so maybe we should adjust the line length here; see https://github.com/mlpack/mlpack/wiki/DesignGuidelines#line-length-and-wrapping for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I need to apply this on all files
@@ -0,0 +1,36 @@ | |||
# This is a simple Makefile used to build the example source code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we should print a similar message in the build step, not sure the first thing a user will do is to look into the Makefile for more information. Let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure, If any system supports posix and have gcc installed, the user should not have any issue with this makefiles. The only possible modifications are setting LD_FLAGS
and INCLUDES
if required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess if there are issues we will see them, so fine with me to go with the current version.
Co-authored-by: Marcus Edel <marcus.edel@fu-berlin.de>
Co-authored-by: Marcus Edel <marcus.edel@fu-berlin.de>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second approval provided automatically after 24 hours. 👍
Signed-off-by: Omar Shrit <shrit@lri.fr>
@rcurtin we can merge now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting everything together!
Thanks @shrit! 👍 |
Signed-off-by: Omar Shrit shrit@lri.fr