473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Compile DLL for use with JNI (using VC++ pref.)

Does anyone know how to compile a C++ DLL for use in JNI (Java) using Visual C++? I keeping getting a java.lang.UnsatisfiedLinkError when running my java code that is not related to a failure to find the library.

The problem I am running into is that the VC++ compiler is mangling the names of the exported functions so that the Java code cannot find it.

I know similar questions/post have been placed all over - but none of the solutions I have come accross are helping.

Not sure what information would help explain the problem...

Thanks,
born2Java
Aug 20 '07 #1
2 2437
weaknessforcats
9,208 Expert Mod 8TB
You need to turn off the mangler by identifying each function as extern "C":
Expand|Select|Wrap|Line Numbers
  1. extern "C" int MyFunciton()
  2. {
  3.  
  4. };
  5.  
Have you done this?

Of course, you lose function oveloading but a DLL is an old C thing and there is no function overloading in C.

Alternaltively, you could add a .DEF file to your DLL project and in there you can export the mangled name as something else. This will allow you to use function overloading in C++ but each overload will be in the DLL as a unique name as specified in the DEF file:
Expand|Select|Wrap|Line Numbers
  1. ;BEGIN ADLL.DEF FILE
  2. ;This DEF file is required because the argument to GetProcAddress()
  3. ;for the function is a C-string and it will never be equal to the
  4. ;C++ mangled name for the function
  5. ;This DEF file maps the mangled name to a name that can be used with GetProcAddress()
  6. ;Note also: Change project settings in Visual Studio to send the LINK this def file.
  7. ;Visual Studio.NET: Project Properties/Linker/Input/Module Definition File/...Path to the def file\Adll.def
  8. LIBRARY ADll 
  9. EXPORTS 
  10. ;Exported Name    C++ Mangled Name
  11. AreaOfSquare   =  ?AreaOfSquare@@YGHHH@Z
  12. DisplayFromDll =  ?DisplayFromDll@@YGXXZ
  13. ;END DEF FILE 
  14.  
Please note the project settting in the example above os the linker can find the DEF file.
Aug 21 '07 #2
Thanks for your reply! I had already used extern "C" for my functions - which for some reason did not resolve the problem.

I ended up using the .def file to solve the problem. On the web all the information I could find said that you did not need to reference the mangled name in the .def file, example:

EXPORTS
Java_pkg_class_function


After reading your reply I updated my .def file to inlcude the mangled name, exmple:

EXPORTS
Java_pkg_class_function = ?Java_pkg_class_function... @1

This worked wonderfully! Again, thanks for your reply, this problem had me stuck for three days.

born2Java
Aug 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jamell | last post by:
I was wondering if anyone knows how to access a control (like a textbox control) that is attached to a MS Word document. I need to do it using VC++.NET. Any example would be a big help.
3
by: Jason Heyes | last post by:
How can I define the member function of this template class using VC++ 6.0? The only way I got it to work was to define the member function inline. template <typename T> class Seq { public:...
4
by: Anthony Gallagher | last post by:
I have a bunch of libraries compiled using VC++ 6.0, and I am trying to recompile one of our projects using VC++ .NET. I get all kind of linker errors (specially in STL calls). How do I get rid of...
2
by: shama | last post by:
HI all, I am new on .net framework, I am using .net 2005 I want to create add-in for Microsoft office, using VC++ with managed code. When I had made add-in using Extensibility project ->...
0
axtens
by: axtens | last post by:
G'day everyone Recently I used Delphi to wrap libiconv for use in VB6 as a COM object. I'm now using VC++6 to wrap Bill Poser's libuninum and am pretty close to completion. This issue I have...
0
by: Sheoak | last post by:
Hi, I am developing Crystal Reports using VC++.Net Unlike VB.Net in the VC++.Net there is no report objects. How do I change the report's page layout to landscape in the IDE and also...
1
by: KDhanalakshmi | last post by:
Using Vc++ Dll In C# Code Hi I am using VC++ dll in c# application After importing dll, if i try to insert out before string sOut in the following statement, it is throwing error. The...
1
by: Vishal | last post by:
I want to execute sybase query using VC++. Can anyone give me a sample program in VC++? Thanks in advance
0
by: abc xyz | last post by:
I am new to VC++ but have a pretty good knowledge on C++.I am analysing DLL assemblies coded using VC++. But I feel that its syntax is not like our usual C++ code. Does MFC come into picture here. is...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.