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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:49:45+00:00 2026-06-01T14:49:45+00:00

How do you call a C++ function from a D program? What commands should

  • 0

How do you call a C++ function from a D program?
What commands should I use?
I’m trying to use dmd on Fedora.

  • 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-01T14:49:47+00:00Added an answer on June 1, 2026 at 2:49 pm

    Simplest example I can think of, if you’re calling C functions:

    $ cat a.c
    int f(int a, int b){
        return a + b + 42;
    }
    $ cat a.di
    extern (C):
    int f(int, int);
    $ cat b.d
    import std.stdio;
    import a;
    void main(){
        writeln( f( 100, 1000) );
    }
    $ gcc -c a.c
    $ dmd b.d a.o
    $ ./b
    1142
    $ 
    

    If you’re using shared objects, you could so something like:

    $ cat sdltest.di
    module sdltest;
    
    extern (C):
    
    struct SDL_version{
        ubyte major;
        ubyte minor;
        ubyte patch;
    }
    
    SDL_version * SDL_Linked_Version();
    
    $ cat a.d
    import std.stdio;
    import sdltest;
    
    void main(){
        SDL_version *ver = SDL_Linked_Version();
        writefln("%d.%d.%d", ver.major, ver.minor, ver.patch);
    }
    
    $ dmd a.d -L-lSDL
    $ ./a
    1.2.14
    $ 
    

    In this example, I linked with an SDL function. The -L argument to dmd allows you to pass arguments to ld, in this case -lSDL to link with SDL.

    D interface files (.di) are described here.

    You should also take a look at htod.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I call a C++ function from a C program, is it possible?,
I'm writing a simple program to call a Java function from my C program.
I'm trying to call a function from a form within the same .php file,
I'm trying to call a function from inside the call of another function. If
I'm trying to call a user-defined MATLAB function from a C application, but I'm
I need to call a function from another program. If the other program were
I want to call a function from a .NET DLL (coded in C#) from
Can I call a function from lisp from a library written in c or
How can I call a function from inside the function, so it becomes recursive?
How do you call function lol() from outside the $(document).ready() for example: $(document).ready(function(){ function

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.