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 8346993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:12:21+00:00 2026-06-09T07:12:21+00:00

If I have a class which will be compiled to a shared object. The

  • 0

If I have a class which will be compiled to a shared object.
The class is declared in a .h file and implemented in a .cpp file.

This class contains a couple of inline methods.

If I write some program that links with this shared library and includes the .h file,
I will get undefined reference errors when linking it.

Is that because there are no symbols exported for inline methods ?

Am I understanding this correctly ?

UPDATE: some example code below

somelib.h

#ifndef __ABC_LIB_H
#define __ABC_LIB_H
#include <iostream>
class ABC {
    ABC();
    ~ABC();
    inline void not_callable_outside_library();
    void callable_outside_library();
};
#endif

somelib.cpp

#include "somelib.h"
ABC::ABC() {}
ABC::~ABC() {}
void ABC::not_callable_outside_library(){ std::cout<<"not_callable_outside_library"<<std::endl; }
void ABC::callable_outside_library(){ std::cout<<"callable_outside_library"<<std::endl; }

program.cpp

#include "somelib.h"
int main() {
    ABC x;
    x.not_callable_outside_library();
    return 0;
};

Compile somelib.cpp as a shared library( .so object) and link it program.cpp then you get the binary called program.

Now you should get an undefined reference when linking.

  • 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-09T07:12:23+00:00Added an answer on June 9, 2026 at 7:12 am

    Inline functions must be defined in header files. Contrast what you have to the following:

    somelib.h:

    #ifndef ABC_LIB_H
    #define ABC_LIB_H
    
    #include <iostream>
    class ABC {
        ABC();
        ~ABC();
        void not_callable_outside_library();
        void callable_outside_library();
    };
    
    inline void ABC::not_callable_outside_library() {
        std::cout << "not_callable_outside_library\n";
    }
    
    #endif
    

    somelib.cpp:

    #include "somelib.h"
    
    ABC::ABC() { }
    ABC::~ABC() { }
    void ABC::callable_outside_library() {
        std::cout << "callable_outside_library\n";
    }
    

    program.cpp:

    #include "somelib.h"
    
    int main() {
        ABC x;
        x.not_callable_outside_library();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on an oophp application. I have a site class which will
I have a static timer class which will be called by ANY webpage to
Let's say I have a list in a class which will be used in
I have developed an utility class for spring which is a singleton which will
I'm creating a class that will have one public method, which returns a value
I have class A which extends the Activity class. This class is in package
I have class World which manages creation of object... After creation it calls afterCreation
I have this shared pimpl*. It forward declares the implementation object and has a
I have class which have one public method Start , one private method and
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a

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.