Autoconf: How to get installation paths into config.h

前端 未结 4 599
囚心锁ツ
囚心锁ツ 2021-02-04 08:00

My program needs to load some files at run time, which will be installed into whatever folder is given to ./configure --datadir=/somewhere

As my program nee

4条回答
  •  囚心锁ツ
    2021-02-04 08:21

    In the event that you have a whole series of such paths that must be known by your source code, and you want to avoid excessive noise in your compilations (eg -DPATH1=/path/to/something -DPATH2=/path2/to/something2 -DPATH3=/path3/to/something3...ad infinitum), an alternative that may be desirable to some people is to create a new "mynewheader.h.in", with the lines

    #define PATH1 "@PATH1@"
    #define PATH2 "@PATH2@"
    #define PATH3 "@PATH3@"
    

    and add it to your configure.ac's AC_CONFIG_FILES line, eg:

    AC_CONFIG_FILES([Makefile mynewheader.h])
    

提交回复
热议问题