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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:09:42+00:00 2026-05-26T07:09:42+00:00

I would like to write a C++ program that calls the mvndst_() subroutine from

  • 0

I would like to write a C++ program that calls the mvndst_() subroutine from

http://www.math.wsu.edu/faculty/genz/software/fort77/mvndstpack.f

On Linux, if I create test.cc:

extern "C" {
    int mvndst_(int *, double *, double *, int *, double *, int *,
                double *, double *, double *, double *, int *);
};
int main() {
    return 0;
}

and compile via

g++ -c -o test.o test.cc
gfortran -c -o mvndstpack.o mvndstpack.f
gfortran -Mnomain -o test test.o mvndstpack.o

then I get

mvndstpack.o: In function `main':
mvndstpack.f:(.text+0x4a2a): multiple definition of `main'
test.o:test.cc:(.text+0x0): first defined here
collect2: ld returned 1 exit status

However, if I run strip -N main mvndstpack.o prior to linking, then the linking succeeds. Can someone explain why the -Mnomain flag did not work here? I’d also like to avoid a solution that uses “strip” since the behavior of “strip” on Mac OS X appears to be different (i.e., the -N option is not available, and I’m not sure of another way to obtain the right behavior). I’d also like to avoid editing the original Fortran source, if possible.

Details:
– GNU Fortran (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
– g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
– GNU strip (GNU Binutils for Ubuntu) 2.21.53.20110810
– strip on Mac OS X 10.6 Snow Leopard

  • 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-26T07:09:43+00:00Added an answer on May 26, 2026 at 7:09 am

    I can’t find any documentation for the -Mnomain option, but gfortran doesn’t complain about it (it seems to pass it on to the linker). But it also didn’t complain when I ran

    gfortran -Mnoplatypus -o test test.o mvndstpack.o
    

    So my guess is that it doesn’t support -Mnomain, and that it’s being silently ignored. (Either that, or there’s a -Mnoplatypus option, but that hardly seems likely.)

    What worked for me was to comment out the PROGRAM TSTNRM .. END lines in mvndstpack.f (lines 15 through 62).

    That’s probably the most sensible approach anyway; you don’t want to use the Fortran main program, so you might as well not compile it, rather than trying to trick the linker into ignoring it.

    (If you prefer, you can use #if ... #endif or #ifdef ... #endif.)

    EDIT:

    Since your main program is in C++, you probably need to use g++, not gfortran, to create the executable:

    g++ -c -o test.o test.cc
    gfortran -c -o mvndstpack.o mvndstpack.f
    g++ -o test test.o mvndstpack.o
    

    (And at some point you’ll actually want to call the function.)

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

Sidebar

Related Questions

I would like to write a program that will identify a machine( for licensing
I would like to write a small tool that takes a C++ program (a
I would like to write a program that sets an environment variable in an
I would like to write a program that reads all the unused clusters on
I would like to write a small program in C# which goes through my
I'm trying to link 10 computers together, the program I would like to write
For example, how would I write a program like senuti ? Are there any
I would like to write a plug-in that will allow a custom written CRM
I would like to write some scripts in python that do some automated changes
I would like to write a utility that will provide me with a relatively

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.