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

  • Home
  • SEARCH
  • 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 6388163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:14:41+00:00 2026-05-25T03:14:41+00:00

We develop some project in plain C (C99). But, we have one library as

  • 0

We develop some project in plain C (C99). But, we have one library as source codes (math library) in C++. We need this library so I would like to ask, what is the most elegant way to integrate this source codes?

Ratio between sizes of C and C++ is 20:1 so moving to C++ is not the option. Should we use static library? DLL? (It’s all on Windows).

  • 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-05-25T03:14:41+00:00Added an answer on May 25, 2026 at 3:14 am

    EDIT: Based on discussion in the comment, I should point out that separating things into a C-compatible struct duck and a derived class Duck is probably unnecessary. You can probably safely shovel the implementation into struct duck and eliminate class Duck, thus obviating real(…). But I don’t know C++ well enough (in particular, the way it interacts with the C universe) to offer a definitive answer on this.


    There is no reason you can’t simply link all your C and C++ code together into a single binary.

    Interfacing to the C++ code requires that you wrap the C++ API in a C API. You can do this by declaring a bunch of functions inside extern "C" { ... } when compiling the C++ code, and without the extern declaration when compiling the C client code. E.g.:

    #ifdef __cplusplus
    extern "C" {
    #endif
    
    typedef struct duck duck;
    
    duck* new_duck(int feet);
    void delete_duck(duck* d);
    void duck_quack(duck* d, float volume);
    
    #ifdef __cplusplus
    }
    #endif
    

    You can define the duck struct in your C++ source, and even inherit the real Duck class from it:

    struct duck { };
    
    class Duck : public duck {
    public:
        Duck(int feet);
        ~Duck();
    
        void quack(float volume);
    };
    
    inline Duck* real(duck* d) { return static_cast<Duck*>(d); }
    
    duck* new_duck(int feet) { return new Duck(feet); }
    void delete_duck(duck* d) { delete real(d); }
    void duck_quack(duck* d, float volume) { real(d)->quack(volume); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I develop an open source project on codeplex.com. I committed some wrong changesets to
In the project I am currently working on, we have the need to develop
I plan to develop some native C++ project in VS2010. But it is possible
I have try to simulate and develop base of some zend project and in
I need to develop a project that needs to have a Ticker and an
i have an individual dev account and a project from some company. would it
I develop some PHP project on Linux platform. Are there any disadvantages of putting
I'm using seeds.rb to load some dummy data into my project as I develop
I need to develop some sort of application featuring Editing Movie slices, Adding and
i have some WinForms app (Framework to develop some simple apps), written in C#.

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.