Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22077

GCC4.1.2, GCC6.3.0, using "-fPIE -Wl,-pie"

$
0
0

Lets say I have an project which has an library in which I have one function which returns a single value, for example:

unsigned long cFun1()
{
    return 1000;
}

Then, I have an mock of the function in the main.cpp, with the same name, and the difference is that it returns some other result, for example:

unsigned long cFun1()
{
    return 45;
}

So, in the main, I am calling the simple function like this:

int main()
{
    long retVal = cFun1();

    return 0;
}

When I use linker as:

**link_command:**%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
    ld -shared -z defs --exclude-libs ALL %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}\
    %{s} %{t} %{u*} %{x} %{z} %{Z} \
        %{L*} %(link_libgcc) %o \
    %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}

the function which is in the library is called, which is not something that I want. What I want to do is to call the mocked function which is in the main.cpp. For that I am adding following flags: -fPIE -Wl,-pie

Compiling the application with this flags results in calling the mocked function which is in the main.cpp and which returns 45, but there are warnings while compiling: Variable retVal is declared but not used in the current configuration.

So, the question is, is there any way to remove those warnings while using the "-fPIE -Wl,-pie" flags? Or, is there any other way to use mocked functionality other than using those mentioned flags?


Viewing all articles
Browse latest Browse all 22077

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>