944,017 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 10178
  • C++ RSS
Jul 25th, 2005
0

Linker Error>Undefined reference error to xyz

Expand Post »
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

C++ Syntax (Toggle Plain Text)
  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
C++ Syntax (Toggle Plain Text)
  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
C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rony is offline Offline
4 posts
since Jul 2005
Jul 25th, 2005
0

Re: Linker Error>Undefined reference error to xyz

Check your spelling.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: MAPI Unicode problem
Next Thread in C++ Forum Timeline: C++ How do you create multifile project





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC