Flag Options Waf (Compiling with gcov in waf)

350 views
Skip to first unread message

na...@algo-logic.com

unread,
Oct 6, 2017, 9:02:50 PM10/6/17
to ns-3-users
How are we able to add linker flag options in waf?

I am attempting to integrate gcovr with waf and am running into issues. Here is the error I encounter 

src/alsdk/binary/byteorder.test.cpp.2.o: In function `global constructors keyed to 65535_0_byteorder.test.cpp':
byteorder.test.cpp:(.text+0x8b2): undefined reference to `__gcov_init'
src/alsdk/binary/byteorder.test.cpp.2.o:(.data.rel+0x48): undefined reference to `__gcov_merge_add'
src/alsdk/binary/byteorder.cpp.1.o: In function `global constructors keyed to 65535_0_byteorder.cpp':
byteorder.cpp:(.text+0xe7): undefined reference to `__gcov_init'
src/alsdk/binary/byteorder.cpp.1.o:(.data.rel+0x48): undefined reference to `__gcov_merge_add'
collect2: ld returned 1 exit status

In waf I want to configure the compiler to run with these flags
-fprofile-arcs -ftest-coverage -fPIC -O0 example1.cpp -o example1

I attempt to do this within the configure method in the wscript
self.env.append_value('CXXFLAGS', ['-std=c++98', '-fprofile-arcs', '-ftest-coverage', '-fPIC'])

However, I receive the error shown above. I would also like to include linker flags in waf
LFLAGS: -lgcov --coverage

1. How can I include these linker flags in waf?
2. How to integrate gcov with waf

Tom Henderson

unread,
Oct 7, 2017, 11:05:46 AM10/7/17
to ns-3-...@googlegroups.com, na...@algo-logic.com
This is typically done by extending the LINKFLAGS within the wscript, or
appending and passing the LDFLAGS environment variable.

For instance, see in the top-level wscript:

        env.append_value('LINKFLAGS', '-lgcov')


> 2. How to integrate gcov with waf

Many years ago, our main wscript was extended to support gcov and lcov. 
I tried it not too long ago and it still worked.  Here is a brief HOWTO:
https://www.nsnam.org/wiki/Developer_FAQ#Using_gcov_and_lcov_code_coverage_tools

- Tom

na...@algo-logic.com

unread,
Oct 9, 2017, 7:28:08 PM10/9/17
to ns-3-users
Hi Tom, 

My version of waf does not support --enable-gcov command for waf. The current version of waf I am using is 1.9.11. I also tried adding linker flags in my top level wscript to no avail. As a result I still receive the same error, 

src/alsdk/binary/byteorder.test.cpp.2.o: In function `global constructors keyed to 65535_0_byteorder.test.cpp':
byteorder.test.cpp:(.text+0x8b2): undefined reference to `__gcov_init'
src/alsdk/binary/byteorder.test.cpp.2.o:(.data.rel+0x48): undefined reference to `__gcov_merge_add'
src/alsdk/binary/byteorder.cpp.1.o: In function `global constructors keyed to 65535_0_byteorder.cpp':
byteorder.cpp:(.text+0xe7): undefined reference to `__gcov_init'
src/alsdk/binary/byteorder.cpp.1.o:(.data.rel+0x48): undefined reference to `__gcov_merge_add'
collect2: ld returned 1 exit status

src/alsdk/device/protocols/arq/order_queue.test.cpp.15.o: In function `global constructors keyed to 65535_0_order_queue.test.cpp':
order_queue.test.cpp:(.text+0x1ff2): undefined reference to `__gcov_init'
src/alsdk/device/protocols/arq/order_queue.test.cpp.15.o:(.data.rel+0x48): undefined reference to `__gcov_merge_add'
src/alsdk/device/protocols/arq/order_queue.cpp.7.o: In function `global constructors keyed to 65535_0_order_queue.cpp':
order_queue.cpp:(.text+0x367): undefined reference to `__gcov_init'
src/alsdk/device/protocols/arq/order_queue.cpp.7.o:(.data.rel+0x48): undefined reference to `__gcov_merge_add'
collect2: ld returned 1 exit status

Any idea on what the issue could be?

Tom Henderson

unread,
Oct 10, 2017, 12:11:33 AM10/10/17
to ns-3-...@googlegroups.com
On 10/09/2017 04:28 PM, na...@algo-logic.com wrote:
> Hi Tom,
>
> My version of waf does not support --enable-gcov command for waf. The
> current version of waf I am using is 1.9.11.

Yes, you must be using your own waf installation; the most recent ns-3
supported version is 1.8.19.  Anyway, the --enable-gcov is specific to
ns-3's wscript; you can perhaps copy the approach from there.
It is a linking error of some sort; this StackOverflow has some suggestions:
https://stackoverflow.com/a/18778157

- Tom

Tom Henderson

unread,
Oct 10, 2017, 9:23:33 AM10/10/17
to ns-3-...@googlegroups.com

>
>
> Many years ago, our main wscript was extended to support gcov and lcov.
> I tried it not too long ago and it still worked.  Here is a brief HOWTO:
>
> https://www.nsnam.org/wiki/Developer_FAQ#Using_gcov_and_lcov_code_coverage_tools
>
>
>
>

An update to the above:  Sebastien pointed out a problem with our
current installation of lcov.  I updated the wiki slightly to note
this.  Until this bug is resolved with ./waf --lcov-report, users should
probably install lcov on their system and run it directly (as described
in the bug report here:
https://www.nsnam.org/bugzilla/show_bug.cgi?id=2799).

- Tom


Reply all
Reply to author
Forward
0 new messages