Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find .dll #4

Open
4ntoine opened this issue Apr 18, 2013 · 9 comments
Open

Can't find .dll #4

4ntoine opened this issue Apr 18, 2013 · 9 comments

Comments

@4ntoine
Copy link

4ntoine commented Apr 18, 2013

extracted libclang.dll is located in C:\dev\clang3.3_march2013\clang3.3_march2013, but can't be found. Test file ExtractClassnamesTest.java is created.

C:\dev\jdk-6u32\bin\java -ea -Djava.library.path=C:\dev\clang3.3_march2013\clang3.3_march2013\ -Didea.launcher.port=7534 -Didea.launcher.bin.path=C:\dev\idea_11_community\bin -Dfile.encoding=UTF-8 -classpath C:\dev\idea_11_community\lib\idea_rt.jar;C:\dev\idea_11_community\plugins\junit\lib\junit-rt.jar;C:\dev\jdk-6u32\jre\lib\alt-rt.jar;C:\dev\jdk-6u32\jre\lib\alt-string.jar;C:\dev\jdk-6u32\jre\lib\charsets.jar;C:\dev\jdk-6u32\jre\lib\deploy.jar;C:\dev\jdk-6u32\jre\lib\javaws.jar;C:\dev\jdk-6u32\jre\lib\jce.jar;C:\dev\jdk-6u32\jre\lib\jsse.jar;C:\dev\jdk-6u32\jre\lib\management-agent.jar;C:\dev\jdk-6u32\jre\lib\plugin.jar;C:\dev\jdk-6u32\jre\lib\resources.jar;C:\dev\jdk-6u32\jre\lib\rt.jar;C:\dev\jdk-6u32\jre\lib\ext\dnsns.jar;C:\dev\jdk-6u32\jre\lib\ext\localedata.jar;C:\dev\jdk-6u32\jre\lib\ext\sunjce_provider.jar;D:\dev\src\jclang\target\test-classes;D:\dev\src\jclang\target\classes;C:\Users\sas.m2\repository\com\nativelibs4java\bridj\0.6.2\bridj-0.6.2.jar;C:\Users\sas.m2\repository\com\google\android\tools\dx\1.7\dx-1.7.jar;C:\Users\sas.m2\repository\junit\junit\4.10\junit-4.10.jar;C:\Users\sas.m2\repository\org\hamcrest\hamcrest-core\1.1\hamcrest-core-1.1.jar;C:\Users\sas.m2\repository\net\java\dev\jna\jna\3.3.0\jna-3.3.0.jar com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 clang.ExtractClassnamesTest

java.lang.UnsatisfiedLinkError: Unable to load library 'Clang': Íå íàéäåí óêàçàííûé ìîäóëü.

at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:166)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:239)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:202)
at clang.ClangLibrary.<clinit>(ClangLibrary.java:19)
at clang.ExtractClassnamesTest.testExtract(ExtractClassnamesTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code -1

@amishne
Copy link

amishne commented Apr 18, 2013

Try opening ClangLibrary.java and modify JNA_LIBRARY_NAME from "Clang" to "clang"; does that help?

@4ntoine
Copy link
Author

4ntoine commented Apr 18, 2013

No: java.lang.UnsatisfiedLinkError: Unable to load library 'clang'

@amishne
Copy link

amishne commented Apr 18, 2013

You can try setting jna.library.path instead of java.library.path; though the latter should also work as far as I know. Another option (what I do) is to set the path from within the code: move the initialization from the static fields of ClangLibrary to your own code, and make sure to call NativeLibrary.addSearchPath before NativeLibrary.getInstance. At least it works for me (with "clang" and not "Clang") - on Linux, though, not Windows, so the problem may be something else entirely.

@4ntoine
Copy link
Author

4ntoine commented Apr 18, 2013

Test source

/**

  • Test to extract class names
    */
    public class ExtractClassnamesTest extends TestCase {

    @test
    public void testExtract() throws IOException {
    ClangLibrary lib = ClangLibrary.INSTANCE;

    File file = File.createTempFile("source", ".cpp");
    
    RawResourceCopier copier = new RawResourceCopier();
    copier.copyFromResource(getClass().getClassLoader().getResourceAsStream("main.cpp"), file);
    
    ClangLibrary.CXTranslationUnit translationUnit = lib.clang_parseTranslationUnit(null, file.getAbsolutePath(), null, 0, null, 0, 0);
    assertNotNull(translationUnit);
    

    }

}


C:\dev\jdk-6u32\bin\java -ea -Djna.library.path=C:\dev\clang3.3_march2013\clang3.3_march2013\ -Didea.launcher.port=7532 -Didea.launcher.bin.path=C:\dev\idea_11_community\bin -Dfile.encoding=UTF-8 -classpath C:\dev\idea_11_community\lib\idea_rt.jar;C:\dev\idea_11_community\plugins\junit\lib\junit-rt.jar;C:\dev\jdk-6u32\jre\lib\alt-rt.jar;C:\dev\jdk-6u32\jre\lib\alt-string.jar;C:\dev\jdk-6u32\jre\lib\charsets.jar;C:\dev\jdk-6u32\jre\lib\deploy.jar;C:\dev\jdk-6u32\jre\lib\javaws.jar;C:\dev\jdk-6u32\jre\lib\jce.jar;C:\dev\jdk-6u32\jre\lib\jsse.jar;C:\dev\jdk-6u32\jre\lib\management-agent.jar;C:\dev\jdk-6u32\jre\lib\plugin.jar;C:\dev\jdk-6u32\jre\lib\resources.jar;C:\dev\jdk-6u32\jre\lib\rt.jar;C:\dev\jdk-6u32\jre\lib\ext\dnsns.jar;C:\dev\jdk-6u32\jre\lib\ext\localedata.jar;C:\dev\jdk-6u32\jre\lib\ext\sunjce_provider.jar;D:\dev\src\jclang\target\test-classes;D:\dev\src\jclang\target\classes;C:\Users\sas.m2\repository\com\nativelibs4java\bridj\0.6.2\bridj-0.6.2.jar;C:\Users\sas.m2\repository\com\google\android\tools\dx\1.7\dx-1.7.jar;C:\Users\sas.m2\repository\junit\junit\4.10\junit-4.10.jar;C:\Users\sas.m2\repository\org\hamcrest\hamcrest-core\1.1\hamcrest-core-1.1.jar;C:\Users\sas.m2\repository\net\java\dev\jna\jna\3.3.0\jna-3.3.0.jar com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 clang.ExtractClassnamesTest

java.lang.UnsatisfiedLinkError: Unable to load library 'clang': È�õ�
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:166)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:239)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:202)
at clang.ClangLibrary.(ClangLibrary.java:19)
at clang.ExtractClassnamesTest.testExtract(ExtractClassnamesTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code -1

@4ntoine
Copy link
Author

4ntoine commented Apr 18, 2013

I'll try later on mac

@4ntoine
Copy link
Author

4ntoine commented Apr 18, 2013

config.jnaerator file contains absolute paths:
-I/usr/lib/gcc/x86_64-linux-gnu/4.6/include/
-I/usr/include/c++/4.6/x86_64-linux-gnu/
-I/usr/include/x86_64-linux-gnu/
-I/usr/include/linux/
-Isrc/main/c/clang-c/

Should they be changed? "mvn clean install" finished without any errors

@4ntoine
Copy link
Author

4ntoine commented Apr 19, 2013

for mac i have to add

<dependency>
    <groupId>com.nativelibs4java</groupId>
    <artifactId>jnaerator-runtime</artifactId>
    <version>0.11</version>
        <scope>compile</scope>
</dependency>

@4ntoine
Copy link
Author

4ntoine commented Apr 19, 2013

i was able to compile test, but it returns unit = null.
(cpp file exists and is valid. i believe libclang.so was found as no error in the log as for windows).
so i heed simple example on how to make it working.

package clang;

import junit.framework.TestCase;

/**
 * Extract meta-info test
 */
public class ExtractTest extends TestCase {

    public void testExtract1() {
        ClangLibrary lib = ClangLibrary.INSTANCE;

        ClangLibrary.CXTranslationUnit unit = lib.clang_parseTranslationUnit(null, "/Users/me/dev/clang/source.cpp", null, 0, null, 0, 0);
    }
}

@4ntoine
Copy link
Author

4ntoine commented Apr 19, 2013

Probably i was trying to use wrong function just to parse the file.
clang_indexSourceFile seems to be what i need but it just returns result = 1 in the test

public void testExtract1() {
        ClangLibrary lib = ClangLibrary.INSTANCE;

        callbacks.startedTranslationUnit = new IndexerCallbacks.startedTranslationUnit_callback() {
            @Override
            public Pointer apply(Pointer client_data, Pointer reserved) {
                return null; // not invoked
            }
        };

        int result = lib.clang_indexSourceFile(null, null, callbacks, 1, 0, "/Users/me/dev/clang/source.cpp", null, 0,  null, 0, null, 0);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants