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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:06:43+00:00 2026-05-25T02:06:43+00:00

I am dynamically linking to a fortran static object and need to be able

  • 0

I am dynamically linking to a fortran static object and need to be able (at run time) to take the name of the fortran function (which is a C++ string) and name mangle it appropriately for the compiler. Is there any pre-built function that would serve this purpose? In the statically linked case I am using autoconf’s FC_FUNC.

For clarity, I want a function that would be able to take a string, interpret it as a fortran subroutine name and mangle it appropriately for the given compiler. In psuedo-C++,:

std::string subroutine = "FORTRANSUBROUTINE";
std::string symbol     = FortranMangle(subroutine);

std::cout << symbol << endl; // Would output something like "fortransubroutine_"

I do not know all of the used name mangling schemes to write this mysterious “FortranMangle” function, myself.

  • 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-25T02:06:44+00:00Added an answer on May 25, 2026 at 2:06 am

    Here’s a quick and dirty C solution that abuses the existing macros to extract the mangling rules and print the mangled result. Most of this gets elided by the optimizer, so only the relevant cases exist. You should be able to adapt this to your code.

    #include <stdio.h>
    #include <string.h>
    
    /* The autoconf macros, predefined here for uppercase, underscore,
     * extra underscore */
    #define FC_FUNC(name, NAME) NAME ## _
    #define FC_FUNC_(name, NAME) NAME ## __
    
    #define STR(arg) STR1(arg)
    #define STR1(arg) #arg
    
    int main(int argc, char **argv)
    {
        const char normal[] = STR(FC_FUNC(l, U));
        const char w_uscore[] = STR(FC_FUNC_(l, U));
        char ucase, uscore, extra_uscore;
        char buf[256];
        int i;
    
        ucase = normal[0] == 'l' ? 0 : 1;
        if (sizeof(normal) > sizeof("l"))
            uscore = 1;
        else
            uscore = 0;
    
        if (sizeof(w_uscore) > sizeof(normal))
            extra_uscore = 1;
        else
            extra_uscore = 0;
    
        printf("upper: %d uscore: %d extra :%d\n", ucase, uscore, extra_uscore);
    
        if (argc < 2)
            return -1;
    
        /* Copy string, converting case */
        for (i=0; i < strlen(argv[1]); i++)
        {
            buf[i] = ucase ? toupper(argv[1][i]) : tolower(argv[1][i]);
        }
    
        if (uscore)
            buf[i++] = '_';
    
        if (extra_uscore && strchr(argv[1], '_'))
        {
            buf[i++] = '_';
        }
    
        buf[i] = '\0';
    
        printf("old: %s - new %s\n", argv[1], buf);
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I dynamically added rows to a table but it doesn't seem to take hover
How would you dynamically subscribe to a C# event so that given a Object
I have some dynamically created inputs which are not server-side controls. I want to
I have a C++ executable and I'm dynamically linking against several libraries (Boost, Xerces-c
I've a program that implements a plugin system by dynamically loading a function from
I have A header file which contains declaration of a function, let's call it
I've the following piece of code in my program which dynamically links wtsapi32.dll file
Problem Overview I have a dynamically produced web page, X , which consists of
I use tcmalloc in my main program A by adding -ltcmalloc in linking time.
I am writing an executable which uses dlopen() (LoadLibrary() on Windows) to dynamically load

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.