Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a gcc flag through makefile

Tags:

gcc

makefile

llvm

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 pass including the makefile, I get the following

relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC

After tyring to find a fix by googling the error message, I came to know that this is not specific to llvm. A few solutions suggested that I should use "--enable-shared" while running configure but that didn't help my case. Now I want to re-build llvm using fPIC, as the error says. But how do I do this using the makefile?

like image 256
Arjun Singri Avatar asked Aug 09 '09 04:08

Arjun Singri


People also ask

How do I pass a flag in Makefile?

The only way of doing that is to edit the makefile to change the options. There is no convenient way to override the options without modifying the makefile . This is where make flags come into play. Flags in make are just variables containing options that should be passed to the tools used in the compilation process.

What is Cflag in Makefile?

CFLAGS and CXXFLAGS are either the name of environment variables or of Makefile variables that can be set to specify additional switches to be passed to a compiler in the process of building computer software.


1 Answers

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.

like image 162
Harold L Avatar answered Sep 19 '22 12:09

Harold L