The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 External Fortran dll can’t find function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

ABN

4 Posts

Posted - 02/24/2020 :  06:43:35 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release: OriginPro2015 (64-bit) Sr1
Operating System: Windows 7 64-bit

Hello!
I want to use fortran function in OriginLab. As I understand fortran code can be used in originlab via OriginC and dll from Fortan code.
For example, I made test.f90 with simple function:
REAL(8) FUNCTION SUMFT(A, B)
  !DEC$ ALIAS SUMFT, "SUMFT" 
  !DEC$ ATTRIBUTES DLLEXPORT:: SUMFT  
  !DEC$ ATTRIBUTES VALUE :: A     
  !DEC$ ATTRIBUTES VALUE :: B    
REAL(8) A
REAL(8) B

      SUMFT  = A + B 
END 

I made test.dll from fortran code via gfortran in cmd:
gfortran -c test.f90
gfortran -shared -mrtd -o test.dll test.o

and tried to call function in OriginC to according to instructions:
https://www.originlab.com/doc/OriginC/guide/Calling-Third-Party-DLL-Functions

I made test.c:
#include <Origin.h>
#include "test.h"
#pragma labtalk(1,Math)
double SUMFTmy(double A, double B)
{
	return SUMFT(A,B);
}

and test.h:
#pragma dll("C:\Users\Alexey\Documents\OriginLab\2015\User Files\OriginC\test\test.dll")
// Prototype of the function in the external DLL
double __stdcall SUMFT(double A, double B);

When I build all that in Code Builder, I get error:
C:\Users\Alexey\Documents\OriginLab\2015\User Files\OriginC\test\test.c(41) :
Error, external DLL cannot find function C:\Users\Alexey\Documents\OriginLab\2015\User Files\OriginC\test\test.dll : SUMFT

What am I doing wrong? How to fix?

Edited by - ABN on 02/24/2020 06:48:40 AM

Chris D

428 Posts

Posted - 02/24/2020 :  12:47:24 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Did you export the function from the DLL? I am not familiar with Fortran but it seems necessary to export it.

Thanks,
Chris Drozdowski
Originlab Technical Support
Go to Top of Page

Castiel

343 Posts

Posted - 02/24/2020 :  6:30:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by ABN

Origin Ver. and Service Release: OriginPro2015 (64-bit) Sr1
Operating System: Windows 7 64-bit

Hello!
I want to use fortran function in OriginLab. As I understand fortran code can be used in originlab via OriginC and dll from Fortan code.
For example, I made test.f90 with simple function:
REAL(8) FUNCTION SUMFT(A, B)
  !DEC$ ALIAS SUMFT, "SUMFT" 
  !DEC$ ATTRIBUTES DLLEXPORT:: SUMFT  
  !DEC$ ATTRIBUTES VALUE :: A     
  !DEC$ ATTRIBUTES VALUE :: B    
REAL(8) A
REAL(8) B

      SUMFT  = A + B 
END 

I made test.dll from fortran code via gfortran in cmd:
gfortran -c test.f90
gfortran -shared -mrtd -o test.dll test.o

and tried to call function in OriginC to according to instructions:
https://www.originlab.com/doc/OriginC/guide/Calling-Third-Party-DLL-Functions

I made test.c:
#include <Origin.h>
#include "test.h"
#pragma labtalk(1,Math)
double SUMFTmy(double A, double B)
{
	return SUMFT(A,B);
}

and test.h:
#pragma dll("C:\Users\Alexey\Documents\OriginLab\2015\User Files\OriginC\test\test.dll")
// Prototype of the function in the external DLL
double __stdcall SUMFT(double A, double B);

When I build all that in Code Builder, I get error:
C:\Users\Alexey\Documents\OriginLab\2015\User Files\OriginC\test\test.c(41) :
Error, external DLL cannot find function C:\Users\Alexey\Documents\OriginLab\2015\User Files\OriginC\test\test.dll : SUMFT

What am I doing wrong? How to fix?




I deem the function exported is
double sumft_(double, double)
double sumft_(double*, double*)
instead of
double SUMFT(double, double)


You may check this with Dependency Walker: http://www.dependencywalker.com/

On the other hand, make sure there are no missing dlls if you are to distribute it. It may depend on some LIBGCC_**.dll.


                                          &&&&&&&&&
                                        &&&
                                       &&
                                      &  _____ ___________
                                     II__|[] | |   I I   |
                                    |        |_|_  I I  _|
                                   < OO----OOO   OO---OO
**********************************************************

Edited by - Castiel on 02/25/2020 09:11:51 AM
Go to Top of Page

ABN

4 Posts

Posted - 02/25/2020 :  06:17:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Chris D

Hi,

Did you export the function from the DLL? I am not familiar with Fortran but it seems necessary to export it.

Thanks,
Chris Drozdowski
Originlab Technical Support



I suppose, yes. I export the function by using the !DEC$ ATTRIBUTES DLLEXPORT compiler directive (in fortran code) to according https://www.originlab.com/pdfs/originc.pdf (page 52)
Go to Top of Page

ABN

4 Posts

Posted - 02/25/2020 :  07:48:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Castiel


I deem the function exported is
double sumft_(double, double)
instead of
double SUMFT(double, double)


You may check this with Dependency Walker: http://www.dependencywalker.com/



Yes, you are right, thank you!
I check it via Dependency Walker.
I replace "SUMFT" with "sumft_" and the error don't erase in Code Builder.

But when I call function SUMFTmy in OriginLab, I get error "Originlab2015 has stopped working" - Module error name: test.dll
Apparently problem with dll, but i don't know what's wrong with it. Because compilation dll goes without errors.

Edited by - ABN on 02/25/2020 08:17:22 AM
Go to Top of Page

Castiel

343 Posts

Posted - 02/25/2020 :  09:14:30 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by ABN

quote:
Originally posted by Castiel


I deem the function exported is
double sumft_(double, double)
instead of
double SUMFT(double, double)


You may check this with Dependency Walker: http://www.dependencywalker.com/



Yes, you are right, thank you!
I check it via Dependency Walker.
I replace "SUMFT" with "sumft_" and the error don't erase in Code Builder.

But when I call function SUMFTmy in OriginLab, I get error "Originlab2015 has stopped working" - Module error name: test.dll
Apparently problem with dll, but i don't know what's wrong with it. Because compilation dll goes without errors.



I'm afraid it should have been
double sumft_(double*, double*)
.



                                          &&&&&&&&&
                                        &&&
                                       &&
                                      &  _____ ___________
                                     II__|[] | |   I I   |
                                    |        |_|_  I I  _|
                                   < OO----OOO   OO---OO
**********************************************************
Go to Top of Page

ABN

4 Posts

Posted - 02/26/2020 :  04:51:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Castiel

I'm afraid it should have been
double sumft_(double*, double*)
.




Thank you so much, your answer helped me!
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000