locked
mingw gfortran calls visual studio compiled C files RRS feed

  • Question

  • For some reason, I have to use mingw gfortran to compile fortran main program which calls a c program compiled by visual studio 2008 (because of CUDA).

    I had a trouble when linking the objective files using Fortran. First, I didn't know which C library file I should use, so I simply chose libgcc coming with mingw gfortran. The linker didn't complain about this. However, the error message ( undefined reference to `_userfunction_') I received indicates that gfortran doesn't know the reference of the C function.  In my C program, I declared the function name as "userfunction_" with the underscore appended, and in my Fortran program I call the function as call userfunction() without the underscore. This worked when I used gfortran and gcc previously (unfortunately gcc is not supported by CUDA on Windows), but I don't know why it didn't work with the combination of gfortran and VS. Does any one have the experience on how to link gfortran and VS objective files? Thanks very much!

     

    • Moved by Nancy Shao Tuesday, May 18, 2010 4:43 AM To get better support (From:Visual Studio Extensibility)
    Sunday, May 16, 2010 8:00 PM

Answers

  • try the gcc fortran mail list and ask how to use libraries compiled by Visual Studio in gcc. 

    >In my C program, I declared the function name as "userfunction_" with the underscore appended

    Remove the underscore as the Visual C++ compiler will add another one.

     



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    Tuesday, May 18, 2010 2:38 PM

All replies

  • Hi Yu,

    I am moving this thread from Base "Visual Studio Extensibility" forum to the "Where is the forum for..." forum, since the issue is little related to VS Extensibity. And you will get better answer if you post in right forum.

    Best Regards,

    Nancy


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, May 18, 2010 4:42 AM
  • try the gcc fortran mail list and ask how to use libraries compiled by Visual Studio in gcc. 

    >In my C program, I declared the function name as "userfunction_" with the underscore appended

    Remove the underscore as the Visual C++ compiler will add another one.

     



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    Tuesday, May 18, 2010 2:38 PM
  • Thanks, I will try that!
    Wednesday, May 19, 2010 2:09 AM