Gnu Makefile - Handling dependencies

后端 未结 12 2691
滥情空心
滥情空心 2021-02-07 20:24

What approach do C++ programmers on Unix platform use to create and manage Makefiles?

I was using hand made Makefiles for my projects but they don\'t handle header file

12条回答
  •  無奈伤痛
    2021-02-07 21:05

    I prefer to use CMake, even though it's not strictly the solution to your problem.

    It's a project description language that'll generate your Makefiles, Visual Studio Project, Eclipse Project, KDevelop, etc for you. All the dependencies are done for you:

    CMakeLists.txt

    add_executable(my_exe file1.c file2.c)
    target_link_libraries(my_exe my_library)
    add_subdirectory(lib)
    

    In lib/CMakeLists.txt

    add_library(my_library file3.c file4.c)
    

    This creates a my_exe from file1.c file2.c linked against my_library. I find this much simpler. It also has things like package discovery:

    find_package(Qt4)
    

提交回复
热议问题