Linker Error>Undefined reference error to xyz

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2005
Posts: 4
Reputation: rony is an unknown quantity at this point 
Solved Threads: 0
rony rony is offline Offline
Newbie Poster

Linker Error>Undefined reference error to xyz

 
0
  #1
Jul 25th, 2005
I am using Dev-C++ to create a dll file which will link Java-JNI-C-Fortran

The project contains CCode.C and JavaCode.h and when I compile, I find the following error: Linker Error>Undefined referece to 'sumsqauredf'

The CCode.C file is

  1. // CCode with documentation
  2.  
  3. #include <stdio.h>
  4.  
  5. #include "JavaCode.h" // Required header for JNI
  6.  
  7. // FORTRAN routines have to be prototyped as extern, and parameters are
  8. // passed by reference. Note also that for g77 the function name in C by
  9. // default must be prefixed by a "_".
  10.  
  11. extern int sumsquaredf_(int *, int []);
  12.  
  13. // When calling C code from Java, main() must be replaced by a declaration
  14. // similar to below, where the function name is given by "Java_" + the name
  15. // of the class in the Java code that calls this C code, in this case
  16. // "JavaCode", + "_" + the name of this C function called from Java, in this
  17. // case "sumsquaredc". This is followed by at least two parameters as below,
  18. // plus possibly more if more are required.
  19.  
  20. JNIEXPORT jint JNICALL Java_JavaCode_sumsquaredc(JNIEnv *env,
  21. jobject obj, jintArray ja) {
  22.  
  23. // Data from any additional parameters are passed via special pointers as
  24. // shown here.
  25.  
  26. jsize n = (*env)->GetArrayLength(env, ja);
  27. jint *a = (*env)->GetIntArrayElements(env, ja, 0);
  28. int i,result;
  29.  
  30. printf("-- We are now in the C program CCode --\n");
  31. printf("Print contents of array a[] copied from arr[] in Java\n");
  32. for (i=0; i<n; i++)
  33. printf("%2d %5d\n",i,a[i]);
  34.  
  35. printf("Call the FORTRAN code\n");
  36.  
  37. // The data are passed to the FORTRAN program, then the results are returned
  38. // in a way similar to this.
  39.  
  40. result = sumsquaredf(&n,a);
  41. printf("-- We have now returned back to the C program --\n");
  42.  
  43. printf("Print contents of array a[]\n");
  44. for (i=0; i<n; i++)
  45. printf("%2d %5d\n",i,a[i]);
  46.  
  47. printf("Sum of squares in array = %d\n",result);
  48.  
  49. // Instead of ending as a normal C program, the pointers must be cleared
  50. // before returning to Java.
  51.  
  52. (*env)->ReleaseIntArrayElements(env, ja, a, 0);
  53. return result;
  54. }
<< moderator edit: added [code][/code] tags >>

The JavaCode.h is
  1. /* DO NOT EDIT THIS FILE - it is machine generated */
  2. #include <jni.h>
  3. /* Header for class JavaCode */
  4.  
  5. #ifndef _Included_JavaCode
  6. #define _Included_JavaCode
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #undef JavaCode_MAXSIZE
  11. #define JavaCode_MAXSIZE 10L
  12. /*
  13.  * Class: JavaCode
  14.  * Method: sumsquaredc
  15.  * Signature: ([I)I
  16.  */
  17. JNIEXPORT jint JNICALL Java_JavaCode_sumsquaredc
  18. (JNIEnv *, jobject, jintArray);
  19.  
  20. #ifdef __cplusplus
  21. }
  22. #endif
  23. #endif
<< moderator edit: added [code][/code] tags >>

The Fortran file FortranCode.f is
C FortranCode.f
  1. INTEGER FUNCTION SUMSQUAREDF(N,A)
  2. INTEGER A(*)
  3. WRITE(6,'("-- We are now in the FORTRAN program FortranCode --")')
  4. WRITE(6,'("Print contents of array A() copied from a[] in C "
  5. 1 "program - note the unit offset")')
  6. DO I=1,N
  7. WRITE(6,'(2I5)')I,A(I)
  8. ENDDO
  9. WRITE(6,'("Calculate then print out squares of elements with "
  10. 1 "accumulated sums")')
  11. ISUM=0
  12. DO I=1,N
  13. A(I)=A(I)*A(I)
  14. ISUM=ISUM+A(I)
  15. WRITE(6,'(3I5)')I,A(I),ISUM
  16. ENDDO
  17. SUMSQUAREDF=ISUM
  18. END
<< moderator edit: added [code][/code] tags >>

How can I solve this prob?

Thanks
Rony
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,681
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Linker Error>Undefined reference error to xyz

 
0
  #2
Jul 25th, 2005
Check your spelling.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC