Automatically including object files using Boost.build

400 views Asked by At

I'm using the latest version of boost-build found in boost 1.46. Given main.cpp which depends on a.h and b.h, using the boost-build's ability to auto-detect dependencies my jam file is simply

exe my_prog : main.cpp ;

But, if there is an implementation file, b.cpp, the object b.o is not produced nor linked in. I'd like my build scripts to be minimal, and not require tweaking everytime I add a new file. So, how can I do this automatically?

Edited to reflect true intent vs. what I was asking for.

1

There are 1 answers

4
AFoglia On BEST ANSWER

Is there any reason this won't work?

exe my_prog : main.cpp b.cpp ;

Doing it the way you want sounds painful and unpleasant, especially for someone new to boost-build. Plus there may be times when you only need the header, and not the cpp.

If your code is impeccably organized, and you only need the files in the current directory, you can get all the cpp files easily enough:

exe my_prog : [ glob *.cpp ] ;

(There are other arguments to glob that will allow you to filter out backup/recovery files your editor may create. And there are other versions of glob that descend into child directories.)

If you have multiple cpp files needed by multiple final executables, you will be better off making a library with the lib rule and using that as one of the sources for your executable.

lib blib : b.cpp ;
exe my_prog : main.cpp blib ;