Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Upp .dll
Upp .dll [message #26108] Thu, 01 April 2010 15:18 Go to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I have several apps in C++.
Using Upp is very good and and easy, with help of course.

I would like to pull some functions out of a Java app and have them as a .dll. The Java app also uses jogl.dll.

Most of the technical issues on linking will be with the java app but what issues may I run into as far as a .dll made with Upp?
Re: Upp .dll [message #26109 is a reply to message #26108] Thu, 01 April 2010 15:22 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Well I have tried before creating a DLL from U++ but for me it did not work with Java. I tried making a simple C++ client for the DLL and it worked, but when the same function was called form Java it failed.

I hope you have more luck with this.
Re: Upp .dll [message #26111 is a reply to message #26109] Thu, 01 April 2010 17:17 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
That could be the biggest problem, C++ to Java.
The jogl.dll is also java code AFAIK, it is from Sun.

Using a socket in C++, Upp or Python works with a Java app but for several functions a more direct link would be preferred.

[Updated on: Thu, 01 April 2010 17:28]

Report message to a moderator

Re: Upp .dll [message #26117 is a reply to message #26111] Fri, 02 April 2010 02:01 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
This or something similar is probably the way to do it.
http://www.math.ucla.edu/~anderson/JAVAclass/JavaInterface/J avaInterface.html
Re: Upp .dll [message #26119 is a reply to message #26117] Fri, 02 April 2010 09:37 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
As always I have sources all over the place if I don't use version control, but I think I found some of my earlier attempts. Seems quite out of date realative to final attempts though.

File attached.
  • Attachment: MyApps.rar
    (Size: 1.47KB, Downloaded 202 times)

[Updated on: Fri, 02 April 2010 09:39]

Report message to a moderator

Re: Upp .dll [message #26125 is a reply to message #26119] Fri, 02 April 2010 14:26 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I looked at the code in MyApps.rar but didn't understand it.
I found this on the JNI (Java Native Interface)
http://java.sun.com/docs/books/jni/html/intro.html

"It is a tutorial intended for the beginning users who are unfamiliar with the JNI."
Just what I need, sometimes it is hard to understand new concepts until the basics are written down and there is code I can try, debug to step through and make small changes to simple existing code that works.
Chapter 2 has the Java app code, HelloWorld.java, the C header code, HelloWorld.h for the connection or link to the Hello-World.dll.
Re: Upp .dll [message #26128 is a reply to message #26125] Sat, 03 April 2010 03:48 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I tried this example.
http://java.sun.com/docs/books/jni/html/intro.html

On the command got up to compiling the HelloWorld.c code.
cl -Ic:\java\include -Ic:\java\include\win32 -MD -LD HelloWorld.c -FeHelloWorld.dll

and get this error:
HelloWorld.c
HelloWorld.c(1) : fatal error C1083: Cannot open include file: 'jni.h': No such file or directory

I have included in the path C:\Program Files\Java\jdk1.7.0\include where jni.h is located

PATH=C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Program Files\Java\jdk1.7.0\bin;
C:\Program Files\Java\jdk1.7.0\include;
C:\Program Files\Microsoft Visual Studio 9.0\VC\bin;
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE
(the path is all one line)

With cbpporter's MyApps.rar I get the same error when running in theIDE:
C:\MyApps\jni\main.cpp(2) : fatal error C1083: Cannot open include file: 'jni.h': No such file or directory

How do I get the jni.h seen in theIDE (or on the command line)?
Re: Upp .dll [message #26130 is a reply to message #26128] Sun, 04 April 2010 07:19 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Gave up on JNI.
Too many links on the web re include files that were not solved.
Including the directories in the Win PATH didn't help.
After changing the command line include
-Ic:\"Program Files"\Java\jdk1.7.0\include the double quotes still split between Program and Files
Copied the Java directory to C:\
-Ic:\Java\jdk1.7.0\include finds jni.h but
-Ic:\Java\jdk1.7.0\win32 does not find jni_md.h

In the PATH is:
C:\Program Files\Microsoft Visual Studio 9.0\VC\bin;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files\Microsoft Visual Studio 9.0\VC\include
"Cannot open include file: 'stdio.h': No such file or directory

I looked at JNA but will try GCC/GCJ CNI.
Re: Upp .dll [message #26138 is a reply to message #26130] Mon, 05 April 2010 14:47 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
You must configure the include path from TheIDE or your command line. I has nothing to do with PATH.

I don't know exactly how the command line must look, but -Ic:\"Program Files"\Java\jdk1.7.0\include seems wrong to me. Try
-I"c:\Program Files\Java\jdk1.7.0\include".


Re: Upp .dll [message #26139 is a reply to message #26138] Mon, 05 April 2010 15:45 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
"You must configure the include path from TheIDE on your command line." I will need to find out how that is done. For Eclipse and MSVC that was done in the IDE.

I tried several different ways for the double quotes, it still split between Program and Files.

"The Visual Studio 2005 Command Prompt automatically sets up the correct path to the Visual C++ compiler and any needed libraries, so it is used instead of the regular Command Prompt window."
http://msdn.microsoft.com/en-us/library/ms235639%28VS.80%29. aspx

This was important for the C++ includes, admin. privileges (even though UAC is off). Then they compiled OK with:
cl -I"c:\Program Files\Java\jdk1.7.0\include" -I"c:\Program Files\Java\jdk1.7.0\include\win32" -MD -LD HelloWorld.c -FeHelloWorld.dll

The files look good, have not been able to run it yet.

Apparently GCC/GCJ CNI and Swig depend on the JNI or similar.
It is just the interface from Java to Native code.

The necessary changes to the JNI files can be compiled on the command line.
It would be good to do it in theIDE.

Once this is set up a C++ .dll can be made with Upp.
The Java app code will be changed with Eclipse.
  • Attachment: Hello.zip
    (Size: 5.97KB, Downloaded 222 times)

[Updated on: Mon, 05 April 2010 16:50]

Report message to a moderator

Re: Upp .dll [message #26145 is a reply to message #26139] Tue, 06 April 2010 00:41 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Previously, after copying the Java directory, it compiled with:
cl -Ic:\Java\jdk1.7.0\include -Ic:\Java\jdk1.7.0\include\win32 -MD -LD HelloWorld.c -FeHelloWorld.dll

My PATH originally was: C:\Windows\system32;C:\Windows
I added the Java but that probably was not necessary as that worked before.
After running the MS SDK CMD Shell (which is SetEnv.cmd) this is the PATH, what a mess.

PATH=C:\Program Files\Microsoft Visual Studio 9.0\VC\Bin;C:\Program Files\Micros
oft Visual Studio 9.0\VC\vcpackages;C:\Program Files\Microsoft Visual Studio 9.0
\Common7\IDE;C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin;C:\Windows\Microso
ft.NET\Framework\v3.5;C:\Windows\Microsoft.NET\Framework\v2. 0.50727;C:\Program F
iles\Microsoft SDKs\Windows\v7.0\Setup;C:\Windows\system32;C:\Windows;C:\Wi ndows
\System32\Wbem;C:\Java\jdk1.7.0\bin;C:\Java\jdk1.7.0\include ;C:\Program Files\Mi
crosoft Visual Studio 9.0\VC\bin;C:\Program Files\Microsoft Visual Studio 9.0\Co
mmon7\IDE;C:\Program Files\Microsoft Visual Studio 9.0\VC\include

After removing any changes to the original and re doing the javac, javah and cl and trying java HelloWorld:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\MyApps\JNIex\HelloWorld.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1922)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1848)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1078)
at HelloWorld.<clinit>(HelloWorld.java:7)

line 7: printf("Hello World!\n");
then the C/C++ cl compiled .h/.dll

Attached is the code as in the original example.
  • Attachment: Hello.zip
    (Size: 6.07KB, Downloaded 377 times)

[Updated on: Tue, 06 April 2010 02:24]

Report message to a moderator

Re: Upp .dll [message #26146 is a reply to message #26145] Tue, 06 April 2010 06:07 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Downloaded Dependency Walker (depends.exe)
http://dependencywalker.com/

Running this on HelloWorld.dll
MSVCR90.DLL cannot be found
That is in the Microsoft Visual C++ 2008 Redistributable Package
http://www.microsoft.com/downloads/details.aspx?familyid=9B2 DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en

It is not included in the links provided when installing Upp, I left the Redistributable selected but it was not in there, I may be wrong on this.

I added this to my PATH:
C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT

depends.exe finds MSVCR90.DLL but "java HelloWorld" now gives this error:
R6034
An application has made an attempt to load the C runtime library incorrectly

I tried copying MSVCR90.DLL to the same directory as HelloWorld.dll and got the same error.

[Updated on: Tue, 06 April 2010 09:21]

Report message to a moderator

Re: Upp .dll [message #26150 is a reply to message #26108] Tue, 06 April 2010 09:58 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
TheIDE -> setup -> build methods -> INCLUDE paths
Re: Upp .dll [message #26152 is a reply to message #26150] Tue, 06 April 2010 10:24 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
mr_ped wrote on Tue, 06 April 2010 09:58

TheIDE -> setup -> build methods -> INCLUDE paths

Could this be limited to just one project?
Re: Upp .dll [message #26155 is a reply to message #26108] Tue, 06 April 2010 10:48 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
TheIDE -> project -> package organizer -> select the package which should be affected, right click into the large area on right, select "New internal includes..", enter directory's full path.

update:
It will affect compilation of all project's packages, no matter where you put that setting, but if the other packages are used in different projects, they will be compiled without it, so make sure you put that setting into every package which actually really needs that include path, it will carry it over to all projects where that package is used.

[Updated on: Tue, 06 April 2010 10:50]

Report message to a moderator

Re: Upp .dll [message #26162 is a reply to message #26155] Tue, 06 April 2010 15:33 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
R6034
An application has made an attempt to load the C runtime library incorrectly

This error needs a manifest embedded in the .dll
http://msdn.microsoft.com/en-us/library/ms235591%28v=VS.80%2 9.aspx

Is there a way to do this in Upp?

[Updated on: Tue, 06 April 2010 15:34]

Report message to a moderator

Re: Upp .dll [message #26260 is a reply to message #26162] Mon, 19 April 2010 16:20 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Got the basics of a JNI working from the command line.
Getting the depends paths was a hassle as in the previous posts.
To embed the manifest in the .dll it can be done with mt.exe, which
is included in the MS SDK when installing U++

Here is a .zip with everything. The HW.bat will do it all except
setting the paths.

Making a .dll in U++ and then embedding the manifest with mt.exe may work after changing the .java and .h files as required for an app.

  • Attachment: JNIex.zip
    (Size: 7.62KB, Downloaded 219 times)
Re: Upp .dll [message #26270 is a reply to message #26260] Tue, 20 April 2010 01:56 Go to previous message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
With the ability to set the paths in theIDE as mr_ped mentioned this should be much easier than adding to PATH.
Previous Topic: [solved, i guess]difficulty with sqlite3 schema
Next Topic: image drawing
Goto Forum:
  


Current Time: Sat Apr 20 06:54:01 CEST 2024

Total time taken to generate the page: 0.17298 seconds