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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 External Fortran dll can’t find function

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
ABN Posted - 02/24/2020 : 06:43:35 AM
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?
6   L A T E S T    R E P L I E S    (Newest First)
ABN Posted - 02/26/2020 : 04:51:40 AM
quote:
Originally posted by Castiel

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




Thank you so much, your answer helped me!
Castiel Posted - 02/25/2020 : 09:14:30 AM
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
**********************************************************
ABN Posted - 02/25/2020 : 07:48:20 AM
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.
ABN Posted - 02/25/2020 : 06:17:25 AM
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)
Castiel Posted - 02/24/2020 : 6:30:15 PM
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
**********************************************************
Chris D Posted - 02/24/2020 : 12:47:24 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000