Cannot compile on Win10/Netbeans

139 views
Skip to first unread message

Peter Nellemann

unread,
Dec 2, 2015, 9:27:19 AM12/2/15
to javacpp
So, having spent a week trying to get things to work, I'm nearly there. As an aside, I haven't worked with Java in nearly 4 years, and never something like JavaCPP before, I'm traditionally a C# developer, but my PhD position tasks me with Java.

Anyways! My goal is pretty much as we suspect> I want to communicate with a C++ .DLL from my Java code. So far, I've done the following, using the Netbeans IDE on a  64-bit installation of Windows10 with Maven for building and CygWin for terminal functionality:

Added the JavaCPP portions to the pom.xml as follows:

<build>
       
<plugins>
           
<plugin>
               
<groupId>org.apache.maven.plugins</groupId>
               
<artifactId>maven-dependency-plugin</artifactId>
               
<version>2.3</version>
               
<executions>
                   
<execution>
                       
<goals>
                           
<goal>properties</goal>
                       
</goals>
                   
</execution>
               
</executions>
           
</plugin>
                     
           
<plugin>
               
<groupId>org.codehaus.mojo</groupId>
               
<artifactId>nbm-maven-plugin</artifactId>
               
<extensions>true</extensions>
           
</plugin>
           
           
<plugin>
               
<groupId>org.codehaus.mojo</groupId>
               
<artifactId>exec-maven-plugin</artifactId>
               
<version>1.2.1</version>
               
<executions>
                   
<execution>
                       
<id>javacpp</id>
                       
<phase>process-classes</phase>
                       
<goals>
                           
<goal>exec</goal>
                       
</goals>
                       
<configuration>
                           
<executable>java</executable>
                           
<arguments>
                               
<argument>-jar</argument>      
                               
<argument>C:\Users\pne\.m2\repository\org\bytedeco\javacpp\1.1\javacpp-1.1.jar</argument>
                               
<!--<argument>${org.bytedeco:javacpp:jar:1.1}</argument>-->
                               
<argument>-classpath</argument>
                               
<argument>${project.build.outputDirectory}</argument>
                               
<argument>-d</argument>        
                               
<argument>${project.build.outputDirectory}</argument>
                           
</arguments>
                       
</configuration>
                   
</execution>
               
</executions>
           
</plugin>            
       
</plugins>
   
</build>

   
<dependencies>
       
<dependency>
           
<groupId>org.netbeans.api</groupId>
           
<artifactId>org-netbeans-api-annotations-common</artifactId>
           
<version>RELEASE80</version>
       
</dependency>
       
       
<dependency>
           
<groupId>net.java.dev.jna</groupId>
           
<artifactId>jna</artifactId>
           
<version>4.2.1</version>
       
</dependency>
       
       
<dependency>
           
<groupId>org.bytedeco</groupId>
           
<artifactId>javacpp</artifactId>
           
<version>1.1</version>
       
</dependency>
   
</dependencies>

the argument for -jar does not work with the commented-out code, but linking directly to the repository does.

My code I'm trying to compile:

package dk.sdu.mmmi.dk.sdu.mmmi.controleum.impl.modelcommunicator;

/**
 *
 * @author pne
 */

import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.annotation.*;

@Platform(include="MAEXP.h")
@Namespace("NativeLibrary")
public class MAEXP {
   
public static class MAEXPClass extends Pointer{
       
static {Loader.load();}
       
public MAEXPClass() { allocate(); }
       
public native void  allocate();
       
       
public native @StdString String stringTest(String txt);
   
}    
}

Trying to compile gives an error with cl command. So I tried some C++ compilers. Currently, I have a grand total of three installed, neither of which will work. Gah! Installed compilers are the Netbeans C++ compiler, Visual Studio 2015 C++ and mingwe-w64 compiler. All to no avail, it still refuses to work. My error:

Enter code here.--- nbm-maven-plugin:3.14:manifest (default-manifest) @ dk.sdu.mmmi.controleum.impl.modelcommunicator ---
NBM
Plugin generates manifest
Adding on module's Class-Path:
    net.java.dev.jna:jna:jar:4.2.1
    org.bytedeco:javacpp:jar:1.1

--- exec-maven-plugin:1.2.1:exec (javacpp) @ dk.sdu.mmmi.controleum.impl.modelcommunicator ---
Generating C:\Workspace\Controleum\dk.sdu.mmmi.controleum.impl.modelcommunicator\target\classes\jniMAEXP.cpp
Compiling C:\Workspace\Controleum\dk.sdu.mmmi.controleum.impl.modelcommunicator\target\classes\jniMAEXP.dll
cl "/IC:\Program Files\Java\jdk1.8.0_66\include" "/IC:\Program Files\Java\jdk1.8.0_66\include\win32" C:\Workspace\Controleum\dk.sdu.mmmi.controleum.impl.modelcommunicator\target\classes\jniMAEXP.cpp /W3 /Oi /O2 /EHsc /Gy /GL /MD /LD /link /OUT:C:\Workspace\Controleum\dk.sdu.mmmi.controleum.impl.modelcommunicator\target\classes\jniMAEXP.dll
Exception in thread "main" java.io.IOException: Cannot run program "cl": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at org.bytedeco.javacpp.tools.Builder.compile(Builder.java:318)
    at org.bytedeco.javacpp.tools.Builder.generateAndCompile(Builder.java:372)
    at org.bytedeco.javacpp.tools.Builder.build(Builder.java:643)
    at org.bytedeco.javacpp.tools.Builder.main(Builder.java:773)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
    at java.lang.ProcessImpl.start(ProcessImpl.java:137)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 4 more
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 6.609s
Finished at: Wed Dec 02 15:14:06 CET 2015
Final Memory: 19M/219M..

If anyone has any idea of how to proceed from here, I would be very grateful, as I'm at my wits end and Java is not exactly my Fort=e *yet, I hope, considering this as yet another learning opportunity). And if Java is bad, C++ is worse, as I've never touched it prior to now.

Samuel Audet

unread,
Dec 5, 2015, 2:23:27 AM12/5/15
to javacpp...@googlegroups.com
On 12/02/2015 11:26 PM, Peter Nellemann wrote:
> Exception in thread "main" java.io.IOException: Cannot run program "cl": CreateProcess error=2, The system cannot find the file specified

The "cl.exe" compiler comes with Visual Studio, and you said you've
installed it, but are you making sure to run this inside a "Native Tools
Command Prompt"?

Samuel
Reply all
Reply to author
Forward
0 new messages