Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

link error when using jni

Status
Not open for further replies.

bilbobaggio

Technical User
May 17, 2005
7
GB
Hi,

I have a class called myClass and i compile for use with jni using the following 'cl -Ic:\program*\Java\jdk1.5.0_01\include -Ic:\program*\Java\jdk1.5.0_01\include\win32 -LD myClassImpl.cpp -FemyClass.dll'

myClassImpl.cpp implements the native call to getNum.

class myClass {
private:
int num;
public:
myClass() { num = 7; }
~myClass() {}

int getNum() { return num; }
};

My problem is that when myClass is implemented in a single file as above everything works fine. But when i separate myClass to have a header file (myClass.h) and a .cpp file implementing the constructor and getNum methods I get the following error when compiling with 'cl' as above:

/dll
/implib:myClass.lib
/out:myClass.dll
myClassImpl.obj
Creating library myClass.lib and object myClass.exp
myClassImpl.obj : error LNK2001: unresolved external symbol "public: __thiscall myClass::myClass(void)" (??0SingleInt@@QAE@XZ)
myClass.dll : fatal error LNK1120: 1 unresolved externals

I have looked for an answer on the web and what people seem to say is that this is plainly a c/c++ linker problem and nothing to do with the jni part.

Thanks for any assistance.
 
I can't reproduce your problem (it works OK with VC++ 6.0 SP5).
With this declaration you have inline constructor in class declaration. What constructor you implement in a separate file?
Apropos, in this case better use a common approach:
Code:
...
myClass():num(7) {}
...
May be you forget to add implementation file to your project?
 
myClass.h is :

class myClass {
private:
int num;
public:
myClass();
~myClass() {}

int getNum();
};

myClass.cpp is :

#include "myClass.h"

myClass::myClass()
{ num = 7; }

int myClass::getNum()
{ return num; }

When the two files are separate as shown here i get the error. However when all is in a single file it compiles ok.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top