Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8836083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:24:35+00:00 2026-06-14T09:24:35+00:00

I try to test an executable which uses OpenCV shared library. When using gcov

  • 0

I try to test an executable which uses OpenCV shared library. When using gcov to know what code lines were covered I only get info about my .cpp files and .hpp of the library. No info is shown about .cpp files of the library.

I compiled and linked with -pg –coverage flags.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:24:36+00:00Added an answer on June 14, 2026 at 9:24 am

    Yes, gcov can give coverage information about a shared library. If I remember correctly from the problems I had getting this to work on my project, you’re probably not including the --coverage flag on the linking of the dynamic library. Here’s the smallest example I could create.

    Makefile:

    CXXFLAGS += --coverage
    LDFLAGS += --coverage
    
    myexec: myexec.cpp libmylib.so
    
    libmylib.so: mylib.o
        gcc --coverage -shared -Wl,-soname,libmylib.so -o libmylib.so mylib.o
    
    mylib.o: CXXFLAGS += -fPIC
    

    myexec.cpp:

    #include "mylib.h"
    
    int main(int argc, char** argv)
    {
        return is_even(argc);
    }
    

    mylib.h

    #ifndef MYLIB_H
    #define MYLIB_H
    
    int is_even(int num);
    
    #endif
    

    mylib.cpp

    #include "mylib.h"
    
    int is_even(int num)
    {
        if (num % 2)
            return false;
        else
            return true;
    }
    

    Output of make (so you can see exactly what the build was):

    g++ --coverage -fPIC   -c -o mylib.o mylib.cpp
    gcc --coverage -shared -Wl,-soname,libmylib.so -o libmylib.so mylib.o
    g++ --coverage  --coverage  myexec.cpp libmylib.so   -o myexec
    

    I ran the executable using LD_LIBRARY_PATH="." ./myexec a, and then ran gcov mylib.cpp. Here’s the contents of mylib.cpp.gcov:

        -:    0:Source:mylib.cpp
        -:    0:Graph:mylib.gcno
        -:    0:Data:mylib.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:#include "mylib.h"
        -:    2:
        1:    3:int is_even(int num)
        -:    4:{
        1:    5:    if (num % 2)
    #####:    6:        return false;
        -:    7:    else
        1:    8:        return true;
        -:    9:}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try a test program with just these two lines char array[256]; char**
Whenever I try to test my code with JUnit, I receive a NullPointerException -
the code below gives compilation error when I try to create test t[2]; because
$ sudo virtualenv test Password: Sorry, try again. Password: New python executable in test/bin/python
I have a project involving shared libraries ie: mylib.so (test) program using these shared
I keep getting 21002 'java.lang.NullPointerException' errors from Apple when I try to test my
I am doing the below test to try and learn more about LINQ to
I was doing a little test to try Ruby's pty and I can't get
i have problem with maven. When i try to compile test classes ( mvn
What test text do you try and type into your web forms to check

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.