Passing a gcc flag through makefile

前端 未结 3 758
清歌不尽
清歌不尽 2020-12-05 19:44

I am trying to build a pass using llvm and I have finished building llvm and its associated components. However, when I run make after following all the steps to build a pas

相关标签:
3条回答
  • 2020-12-05 20:04

    Another option is to pass -fPIC directly to make in the following way:

    make CFLAGS='-fPIC' CXXFLAGS='-fPIC'
    
    0 讨论(0)
  • 2020-12-05 20:08

    If you are moderately convinced that you should use '-fPIC' everywhere (or '-m32' or '-m64', which I need more frequently), then you can use the 'trick':

    CC="gcc -fPIC" ./configure ...
    

    This assumes a Bourne/Korn/POSIX/Bash shell and sets the environment variable CC to 'gcc -fPIC' before running the configure script. This (usually) ensures that all compilations are done with the specified flags. For setting the correct 'bittiness' of the compilation, this sometimes works better than the various other mechanisms you find - it is hard for a compilation to wriggle around it except by completely ignoring the fact you specified the C compiler to use.

    0 讨论(0)
  • 2020-12-05 20:13

    Looks like you could add the -fPIC (for position-independent code, something you want for a shared library that could be loaded at any address) by setting shell variables:

    export CFLAGS="$CFLAGS -fPIC"
    export CXXFLAGS="$CXXFLAGS -fPIC"
    

    Looking at Makefile.rules, these will be picked up and used. Seems strange that it wasn't there to begin with.

    EDIT:

    Actually, reading more in the makefiles, I found this link to the LLVM Makefile Guide. From Makefile.rules, setting either SHARED_LIBRARY=1 or LOADABLE_MODULE=1 (which implies SHARED_LIBRARY) in Makefile will put -fPIC in the compiler flags.

    0 讨论(0)
提交回复
热议问题