Boost C++ Libraries

PrevUpHomeNext

I am getting a "Duplicate name of actual target" error. What does that mean?

The most likely case is that you are trying to compile the same file twice, with almost the same, but differing properties. For example:

exe a : a.cpp : <include>/usr/local/include ;
exe b : a.cpp ;

The above snippet requires two different compilations of a.cpp, which differ only in their include property. Since the include feature is declared as free Boost.Build does not create a separate build directory for each of its values and those two builds would both produce object files generated in the same build directory. Ignoring this and compiling the file only once would be dangerous as different includes could potentially cause completely different code to be compiled.

To solve this issue, you need to decide if the file should be compiled once or twice.

  1. To compile the file only once, make sure that properties are the same for both target requests:

    exe a : a.cpp : <include>/usr/local/include ;
    exe b : a.cpp : <include>/usr/local/include ;
    

    or:

    alias a-with-include : a.cpp : <include>/usr/local/include ;
    exe a : a-with-include ;
    exe b : a-with-include ;
    

    or if you want the includes property not to affect how any other sources added for the built a and b executables would be compiled:

    obj a-obj : a.cpp : <include>/usr/local/include ;
    exe a : a-obj ;
    exe b : a-obj ;
    

    Note that in both of these cases the include property will be applied only for building these object files and not any other sources that might be added for targets a and b.

  2. To compile the file twice, you can tell Boost.Build to compile it to two separate object files like so:

          obj a_obj : a.cpp : <include>/usr/local/include ;
          obj b_obj : a.cpp ;
          exe a : a_obj ;
          exe b : b_obj ;
    

    or you can make the object file targets local to the main target:

          exe a : [ obj a_obj : a.cpp : <include>/usr/local/include ] ;
          exe b : [ obj a_obj : a.cpp ] ;
    

    which will cause Boost.Build to actually change the generated object file names a bit for you and thus avoid any conflicts.

    Note that in both of these cases the include property will be applied only for building these object files and not any other sources that might be added for targets a and b.

A good question is why Boost.Build can not use some of the above approaches automatically. The problem is that such magic would only help in half of the cases, while in the other half it would be silently doing the wrong thing. It is simpler and safer to ask the user to clarify his intention in such cases.


PrevUpHomeNext