代码之家  ›  专栏  ›  技术社区  ›  nPn

如何将“header only(.hpp)”库用作组件?

  •  0
  • nPn  · 技术社区  · 6 年前

    我试图包含一个库,它使用诸如blah.hpp之类的文件作为“组件”,并使用esp32 idf编译它们。

    我在项目中创建了components子目录,并将库复制到components目录的子目录中。如果我用锅炉板 component.mk 文件编译器看不到后缀为.hpp的文件。如果我将文件重命名为 blah.hpp blah.cpp 编译器确实看到 废话cpp 文件,所以它只是没有看到文件 .hpp 后缀

    我尝试添加以下component.mk文件(我注意到 here )但后来我犯了以下错误。

    make[1]: *** No rule to make target '/home/john/development/esp/ble_test2/components/rxcpp/./rx-sources.o', needed by 'librxcpp.a'.  Stop.
    

    这是我正在尝试使用的component.mk文件(添加了上面提到的行)。

    #
    # Main component makefile.
    #
    # This Makefile can be left empty. By default, it will take the sources in the 
    # src/ directory, compile them and link them into lib(subdirectory_name).a 
    # in the build directory. This behaviour is entirely configurable,
    # please read the ESP-IDF documents if you need to do this.
    COMPONENT_ADD_INCLUDEDIRS=.
    COMPONENT_OBJS += $(foreach compsrcdir,$(COMPONENT_SRCDIRS),$(patsubst %.hpp,%.o,$(wildcard $(COMPONENT_PATH)/$(compsrcdir)/*.hpp)))
    
    ## Uncomment the following line to enable exception handling 
    CXXFLAGS+=-fexceptions
    CXXFLAGS+= -std=c++11
    

    这似乎是一个简单的修复方法,我确实看到esp32 idf中的组件也使用诸如blah.hpp之类的文件 here ,但我无法设置使我的编译可用的选项。

    顺便说一句,不知道在esp32上尝试使用rxcpp是否是个好主意,但我很好奇它是否能工作:)

    1 回复  |  直到 6 年前
        1
  •  1
  •   romkey    6 年前

    与包含任何头文件的方式相同-只是 #include 在适当的时候 .cpp 文件。如果使用Makefile,请确保在 .hpp 文件到由 .cpp公司 就像你想要一个 .h 文件和 .c 文件。

    不要试图使用rxcpp作为组件。它不是用来建图书馆的。就像回购协议说的,它只是头文件。你只是 #包括 在你需要的地方。

    推荐文章