make: implicit rule to link c++ project

后端 未结 7 1035
礼貌的吻别
礼貌的吻别 2020-12-31 04:52

I am working my way through a make tutorial. Very simple test projects I am trying to build has only 3 files: ./src/main.cpp ./src/implementation.cpp and

7条回答
  •  旧时难觅i
    2020-12-31 05:12

    According to the make manual, you can use the implicit linking rule with multiple objects if one of these matches the executable name, eg:

    VPATH = src include
    CPPFLAGS = -I include
    
    main: implementation.o
    main.o: header.hpp
    implementation.o: header.hpp
    

    This will build an executable named main from both main.o and implementation.o.

    Note however that the builtin implicit rule uses the C compiler for linking, which will not link against the C++ std library by default, you will need to add the flag -lstdc++ to LDLIBS explicitly

提交回复
热议问题