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 use phpstorm to develop websites, but for some reason breakpoints aren't synchronized. Here
Currently I always worked with GIT and was quite satisfied. Due to some project
I'm trying to develop a custom PDF viewer using PDFLibNet library. I downloaded compiled
I have some Django websites and I want to place them on the webserver
I have a TFS structure that looks something like this: $ -MainSoftwareBranch -Dev -Main
In have a Motorola Xoom tablet and I would like to use it to
So we've finally got VS2010 on some developer stations at work and can use
Our team uses Eclipse to develop a software product, and recently we switched to
In the past, I have been developing in a very amateurish fashion, meaning I
After (another) bout with Visual Studio slowness, I went into procmon to see if

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.