i'm compiling a jni project.here is detail of the problem i encountering:
r
oot#kaiwiiho:/home/kaiwii/svn# make
gcc -shared build/utimebufClass.o build/contextClass.o build/fsClass.o build/javafuse_jni.o build/statClass.o build/statvfsClass.o build/fileinfoClass.o build/conninfoClass.o -o build/libjavafuse.so
gcc -g -Wall `pkg-config --cflags fuse` -Iinclude -I/usr/java/jdk1.6.0_31/include -I/usr/java/jdk1.6.0_31/include/linux `pkg-config --libs fuse` -L/usr/java/packages/lib/i386 -L/lib -L/usr/lib -ljvm -Lbuild -ljavafuse src/javafuse.c -o javafuse
src/javafuse.c: In function ‘javafuse_readdir’:
src/javafuse.c:2194:22: warning: cast from pointer to integer of different size
src/javafuse.c:2195:25: warning: cast from pointer to integer of different size
src/javafuse.c:2207:15: warning: cast to pointer from integer of different size
src/javafuse.c:2208:18: warning: cast to pointer from integer of different size
src/javafuse.c:2256:16: warning: cast from pointer to integer of different size
src/javafuse.c:2257:19: warning: cast from pointer to integer of different size
src/javafuse.c:2271:15: warning: cast to pointer from integer of different size
src/javafuse.c:2272:18: warning: cast to pointer from integer of different size
src/javafuse.c: In function ‘javafuse_releasedir’:
src/javafuse.c:2332:12: warning: assignment from incompatible pointer type
src/javafuse.c: In function ‘javafuse_fsyncdir’:
src/javafuse.c:2420:12: warning: assignment from incompatible pointer type
/usr/bin/ld: cannot find -ljvm
collect2: ld returned 1 exit status
make: *** [javafuse] 错误 1
root#kaiwiiho:/home/kaiwii/svn# ldconfig
root#kaiwiiho:/home/kaiwii/svn# gedit /etc/ld.so.conf
root#kaiwiiho:/home/kaiwii/svn# make
gcc -shared build/utimebufClass.o build/contextClass.o build/fsClass.o build/javafuse_jni.o build/statClass.o build/statvfsClass.o build/fileinfoClass.o build/conninfoClass.o -o build/libjavafuse.so
gcc -g -Wall `pkg-config --cflags fuse` -Iinclude -I/usr/java/jdk1.6.0_31/include -I/usr/java/jdk1.6.0_31/include/linux `pkg-config --libs fuse` -L/usr/java/packages/lib/i386 -L/lib -L/usr/lib -ljvm -Lbuild -ljavafuse src/javafuse.c -o javafuse
src/javafuse.c: In function ‘javafuse_readdir’:
src/javafuse.c:2194:22: warning: cast from pointer to integer of different size
src/javafuse.c:2195:25: warning: cast from pointer to integer of different size
src/javafuse.c:2207:15: warning: cast to pointer from integer of different size
src/javafuse.c:2208:18: warning: cast to pointer from integer of different size
src/javafuse.c:2256:16: warning: cast from pointer to integer of different size
src/javafuse.c:2257:19: warning: cast from pointer to integer of different size
src/javafuse.c:2271:15: warning: cast to pointer from integer of different size
src/javafuse.c:2272:18: warning: cast to pointer from integer of different size
src/javafuse.c: In function ‘javafuse_releasedir’:
src/javafuse.c:2332:12: warning: assignment from incompatible pointer type
src/javafuse.c: In function ‘javafuse_fsyncdir’:
src/javafuse.c:2420:12: warning: assignment from incompatible pointer type
/usr/bin/ld: cannot find -ljvm
collect2: ld returned 1 exit status
make: *** [javafuse] 错误 1
And for sake that the the libjvm.so have aready exisited in the /usr/lib,i directly make a conf file,/etc/ld.so.conf.d/my.conf:
/usr/lib
/usr/local/lib
and then i use command ldconfig.
but unfortunately,i still encounter the same problem yet.
Any idea?thx
This command:
gcc -g -Wall `pkg-config --cflags fuse` -Iinclude \
-I/usr/java/jdk1.6.0_31/include \
-I/usr/java/jdk1.6.0_31/include/linux `pkg-config --libs fuse` \
-L/usr/java/packages/lib/i386 -L/lib -L/usr/lib -ljvm -Lbuild -ljavafuse \
src/javafuse.c -o javafuse
is incorrect. The order of libraries and sources on the link line matters, and your order is wrong.
But that's not what your problem is right now. You insist that libjvm.so exists in /usr/lib, but have shown no evidence that it does. What does ls -l /usr/lib/libjvm.so actually print?
Note that it would be highly unusual to find libjvm.so in /usr/lib. Usually one would expect to find it in e.g. /usr/java/packages/lib/i386/server, and you are not searching that directory.
Update:
well. libjvm.so is not actually in the /usr/lib but in /usr/java/jdk1.6.0_31/jre/lib/i386/server
In that case, you need to add -L/usr/java/jdk1.6.0_31/jre/lib/i386/server to your link line.
And i gedit a conf file ...
Obviously that's not sufficient.
The error is coming because JAVA_HOME & LD_LIBRARY_PATH is not consistent for Linux.So after analysis i discover that JAVA_HOME and LD_LIBRARY_PATH is resetting everytime whenever the terminal window is closed.
So setting the JAVA_HOME permanently resolved the error like:-
JAVA_HOME=/usr/java/latest
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/latest/bin:/bin:/sbin:/usr/lib64/qt-3.3/bin
LD_LIBRARY_PATH=/usr/java/jdk1.8.0_111/jre/lib/amd64/server:/usr/local/lib:/usr/lib64:/usr/lib:/usr/local/lib64:
Related
I am trying to include a C++ library with my swing project..
When I compile the jnilib/so, with stdio.h it works fine for this:
gcc -shared -o libhello.jnilib hello.c -fPIC -I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include/darwin
I am trying to import and need to use gnu-libstdc++/4.9
How do I link my java project?
When I try to build the jni file:
It will throw this:
test.c:5:10: fatal error: 'string' file not found
#include <string>
EDIT
Now when I link to this:
-I /Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include
It throws this error:
...
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:69:37: error: use of undeclared identifier '_U'
static const mask graph = _P | _U | _L | _N;
^
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:69:42: error: use of undeclared identifier '_L'
static const mask graph = _P | _U | _L | _N;
^
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:69:47: error: use of undeclared identifier '_N'
static const mask graph = _P | _U | _L | _N;
^
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:70:32: error: use of undeclared identifier '_C'
static const mask cntrl = _C;
^
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:71:32: error: use of undeclared identifier '_P'
static const mask punct = _P;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
EDIT2
After adding -I /Users/timnuwin/Documents/ndk/android-ndk-r12b/platforms/android-17/arch-x86/usr/include now it throws:
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:164:11: error: no member named 'vfwscanf' in the global namespace
using ::vfwscanf;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:170:11: error: no member named 'vswscanf' in the global namespace
using ::vswscanf;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:174:11: error: no member named 'vwscanf' in the global namespace
using ::vwscanf;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:191:11: error: no member named 'wcstof' in the global namespace
using ::wcstof;
~~^
In file included from hello.cpp:6:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/sstream:38:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/istream:38:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/ios:44:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/basic_ios.h:37:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/locale_facets.h:39:
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwctype:89:11: error: no member named 'iswblank' in the global namespace; did you
mean 'isblank'?
using ::iswblank;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/platforms/android-17/arch-x86/usr/include/ctype.h:88:5: note: 'isblank' declared here
int isblank(int);
^
1 warning and 5 errors generated.
EDIT3
Okay I think I'm a little closer here's the updated includes...
gcc -shared -o libhello.jnilib hello.cpp -fPIC
-I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include
-I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include/darwin
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/backward
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/debug
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/decimal
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/experimental
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/ext
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/parallel
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/profile
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/tr1
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/tr2
But now it throws:
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/tr1/stdio.h:8:10: fatal error: 'tr1/cstdio' file not found
#include
EDIT
Alrighty, setting the include to be the base dir include -I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include now throws:
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:98:11: error: no member named 'FILE' in the global namespace
using ::FILE;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:99:11: error: no member named 'fpos_t' in the global namespace
using ::fpos_t;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:101:11: error: no member named 'clearerr' in the global namespace
using ::clearerr;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:102:11: error: no member named 'fclose' in the global namespace
using ::fclose;
~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:103:11: error: no member named 'feof' in the global namespace
using ::feof;
~~^
clang++ -shared -o libhello.jnilib hello.cpp -fPIC -funwind-tables -no-canonical-prefixes -fexceptions -frtti -Os -g -DNDEBUG -DNDEBUG -fPIC -std=gnu++11 -I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include/darwin -isystem /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include -isystem /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -I /Users/timnuwin/Documents/ndk/android-ndk-r12b/platforms/android-17/arch-x86/usr/include
That cmd was able to create my jnilib file. :D 3 days later hehe
I'm trying to link a library in a JNI project I have. I'm running into a strange bug where the console output tells me that there was a "symbol not found for x86 64 architecture". I'm kinda stumped on what could be going wrong. There are other classes but they're way too many to put here. Here's my code:
EDIT: I'll include the entire console debug log. It doesn't mention which symbol is the one in question.
EDIT 2: I fixed a static variable that was a problem, but it's still giving an error. Updated the code to reflect changes
Console Debug Log:
14:24:05 **** Build of configuration Debug for project HPA* Program ****
make all
cc -v -c -stdlib=libstdc++ -fPIC -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/ HPAProgram.c++ -o libhpaprogram.o
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name HPAProgram.c++ -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 224.1 -v -coverage-file "/Users/zalbhathena/Documents/workspace/Thesis-Test-Application/HPA* Program/jni/libhpaprogram.o" -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0 -I /System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/ -stdlib=libstdc++ -fdeprecated-macro -fdebug-compilation-dir "/Users/zalbhathena/Documents/workspace/Thesis-Test-Application/HPA* Program/jni" -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -o libhpaprogram.o -x c++ HPAProgram.c++
clang -cc1 version 5.0 based upon LLVM 3.3svn default target x86_64-apple-darwin13.0.0
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
libtool -dynamic -lSystem libhpaprogram.o -o libhpaprogram.dylib
ld: warning: -macosx_version_min not specified, assuming 10.8
Undefined symbols for architecture x86_64:
"__Z11create_dcdtv", referenced from:
_Java_HPAProgram_sayHello in libhpaprogram.o
ld: symbol(s) not found for architecture x86_64
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: internal link edit command failed
make: *** [libhpaprogram.dylib] Error 1
14:24:05 Build Finished (took 162ms)
HPAProgram.c++
#include <stdio.h>
#include "HPAProgram.h"
#include "DCDTWrapper.h"
extern void create_dcdt();
JNIEXPORT void JNICALL Java_HPAProgram_sayHello (JNIEnv *env, jobject obj) {
printf("Hello World!\n");
create_dcdt();
}
DCDTWrapper.h
# include "DCDTsrc/se_dcdt.h"
# include "DCDTsrc/gs_polygon.h"
# include <stdlib.h>
void create_dcdt ();
DCDTWrapper.c++
# define END 12345.6
# define FIRST_EXAMPLE Example1
//# include "DCDTsrc/se_dcdt.h"
//# include "DCDTsrc/gs_polygon.h"
//# include <stdlib.h>
# include "DCDTWrapper.h"
static double Example1[] =
{ -10, -10, 10, -10, 10, 10, -10, 10, END,
1, 1, 7, 3, 3, 8, END,
END };
static const double* CurExample = FIRST_EXAMPLE;
static SeDcdt *TheDcdt;
static GsPolygon CurPath;
static GsPolygon CurChannel;
static float CurX1=0, CurY1=0, CurX2=0, CurY2=0;
static int CurSelection=0; // -2,-1: moving point, >0: moving polygon
void create_dcdt ()
{
const double* data = CurExample;
GsPolygon pol;
// domain:
while ( *data!=END ) { pol.push().set((float)data[0],(float)data[1]); data+=2; }
TheDcdt->init ( pol, 0.00001f );
while ( *++data!=END )
{ pol.size(0);
while ( *data!=END ) { pol.push().set((float)data[0],(float)data[1]); data+=2; }
TheDcdt->insert_polygon ( pol );
}
}
makefile:
# Define a variable for classpath
CLASS_PATH = ../bin
# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)
all: libhpaprogram.dylib
# $# matches the target, $< matches the first dependancy
libhpaprogram.dylib:
cc -v -c -stdlib=libstdc++ -fPIC -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/ HPAProgram.c++ -o libhpaprogram.o
libtool -dynamic -lSystem libhpaprogram.o -o libhpaprogram.dylib
HPAProgram.h : HPAProgram.class
javah -classpath $(CLASS_PATH) $*
clean:
rm HPAProgram.h libhpaprogram.o libhpaprogram.dylib
This is your problem:
static void create_dcdt ();
When you declare a global object static in a header file, every single translation unit (ie: cpp file) that includes it will want to create their own version of that object.
You probably want to qualify create_dcdt() with extern:
extern void create_dcdt();
Then in the file DCDTWrapper.c++ remove the static qualifier.
This will tell the compiler to allow all versions of the undefined object to be resolved at link time, to a single version that lives in one cpp file.
(the extern keyword is probably optional but you certainly do not want to use static here)
The second part of your problem is that you are not including the DCDTWrapper.c++ file in your build project.
Modify your makefile like this:
libhpaprogram.dylib:
cc -v -c -stdlib=libstdc++ -fPIC -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/ HPAProgram.c++ -o libhpaprogram.o
cc -v -c -stdlib=libstdc++ -fPIC -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/ DCDTWrapper.c++ -o DCDTWrapper.o
libtool -dynamic -lSystem libhpaprogram.o DCDTWrapper.o -o libhpaprogram.dylib
I fixed my problem, here's the updated makefile:
SRC=DCDTsrc
TGT=obj
INCLUDES=-IDCDTsrc DCDTWrapper.h SearchAlgorithms.h
FLAGS=-stdlib=libstdc++ -std=c++0x -D GS_SYSTEM_RAND_LIBS -lm -fPIC -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/ -v
SOURCES=$(wildcard $(SRC)/*.cpp) DCDTWrapper.cpp SearchAlgorithms.cpp
OBJS=$(addprefix $(TGT)/, $(notdir $(SOURCES:.cpp=.o)))
CC=g++
# Define a variable for classpath
CLASS_PATH = ../bin
# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)
$(TGT)/%.o: $(SRC)/%.cpp
$(CC) $(FLAGS) -c $< -o $#
$(TGT)/%.o: %.cpp
$(CC) $(FLAGS) -c $< -o $#
# $# matches the target, $< matches the first dependancy
libsearchalgorithms.dylib: $(OBJS)
libtool -lc -lstdc++ -ldl -macosx_version_min 10.9 -lm -dynamic -lSystem $(OBJS) -o libsearchalgorithms.dylib
SearchAlgorithms.h : SearchAlgorithms.class
javah -classpath $(CLASS_PATH) $*
clean:
rm -rf $(TGT)
mkdir $(TGT)
if [ -a SearchAlgorithms.h ] ; \
then \
rm SearchAlgorithms.h ; \
fi;
if [ -a libsearchalgorithms.o ] ; \
then \
rm libsearchalgorithms.o ; \
fi;
if [ -a libsearchalgorithms.dylib ] ; \
then \
rm libsearchalgorithms.dylib ; \
fi;
all:clean SearchAlgorithms.h libsearchalgorithms.dylib
I am getting something like the following:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no viewerNativeDLL in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at viewer.SarBufferedImage.<clinit>(SarBufferedImage.java:356)
at viewer.viewerJPanel.<init>(viewerJPanel.java:34)
at viewer.ViewerView.initComponents(ViewerView.java:457)
at viewer.ViewerView.<init>(ViewerView.java:33)
at viewer.ViewerApp.main(ViewerApp.java:21)
This is even though I have set LD_LIBRARY_PATH to the path where I built my shared object.
Did I build that shared object wrong? This is the makefile I used to build the shared lib:
CPP = g++
CFLAGS = -O3 -Wall -fopenmp -fPIC
INC = -I ../../VC/readers/ -I../../VC/writers -I../../VC/common/ -I /home/dcole/software/xerces-c-3.1.1/src -I /home/dcole/software/java/jdk1.6.0_23/include -I /home/dcole/software/java/jdk1.6.0_23/include/linux
LIB2 = -L/usr/lib64/ -L../../lib/IDT.a -L../../lib/Linux/libxerces-c.a -L../../lib/Linux/libxerces-c-3.1.so -lcurl -lidn -ldl -lssl -L../../lib/Linux/libfftw3f.a -lpthread
all: ViewerNative.o
${CPP} ${CFLAGS} -shared -o libviewerNativeDLL.so ViewerNative.o ${LIB2}
ViewerNative.o: ViewerNative.cpp viewer_SarBufferedImage.h
${CPP} ${INC} ${CFLAGS} -c ViewerNative.cpp ${LIB2}
Am I missing something with the way I am creating viewerNativeDLL.so?
If I do a ldd-d libviewerNativeDLL.so I get this:
undefined symbol: _ZTIN11xercesc_3_117SAXParseExceptionE (./libviewerNativeDLL.so)
undefined symbol: _ZN11xercesc_3_117SAXParseExceptionD1Ev (./libviewerNativeDLL.so)
linux-vdso.so.1 => (0x00007fff41f21000)
libcurl.so.4 => /usr/lib64/libcurl.so.4 (0x00007fc30bcd4000)
libidn.so.11 => /lib64/libidn.so.11 (0x00007fc30baa2000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fc30b89d000)
libssl.so.8 => /usr/lib64/libssl.so.8 (0x00007fc30b649000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fc30b42d000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fc30b122000)
libm.so.6 => /lib64/libm.so.6 (0x00007fc30ae9f000)
libgomp.so.1 => /usr/lib64/libgomp.so.1 (0x00007fc30ac92000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc30aa77000)
libc.so.6 => /lib64/libc.so.6 (0x00007fc30a709000)
libldap-2.4.so.2 => /usr/lib64/libldap-2.4.so.2 (0x00007fc30a4c4000)
librt.so.1 => /lib64/librt.so.1 (0x00007fc30a2bb000)
libgssapi_krb5.so.2 => /usr/lib64/libgssapi_krb5.so.2 (0x00007fc30a090000)
libkrb5.so.3 => /usr/lib64/libkrb5.so.3 (0x00007fc309df4000)
libk5crypto.so.3 => /usr/lib64/libk5crypto.so.3 (0x00007fc309bcd000)
libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fc3099ca000)
libz.so.1 => /lib64/libz.so.1 (0x00007fc3097b5000)
libssl3.so => /lib64/libssl3.so (0x00007fc309581000)
libsmime3.so => /lib64/libsmime3.so (0x00007fc309357000)
libnss3.so => /lib64/libnss3.so (0x00007fc309024000)
libnssutil3.so => /lib64/libnssutil3.so (0x00007fc308e05000)
libplds4.so => /lib64/libplds4.so (0x00007fc308c02000)
libplc4.so => /lib64/libplc4.so (0x00007fc3089fe000)
libnspr4.so => /lib64/libnspr4.so (0x00007fc3087c1000)
libssh2.so.1 => /usr/lib64/libssh2.so.1 (0x00007fc30859a000)
/lib64/ld-linux-x86-64.so.2 (0x0000003e34a00000)
libcrypto.so.8 => /usr/lib64/libcrypto.so.8 (0x00007fc308215000)
liblber-2.4.so.2 => /usr/lib64/liblber-2.4.so.2 (0x00007fc308005000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fc307dec000)
libsasl2.so.2 => /usr/lib64/libsasl2.so.2 (0x00007fc307bd1000)
libkrb5support.so.0 => /usr/lib64/libkrb5support.so.0 (0x00007fc3079c8000)
libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fc3077c6000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fc30758e000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fc307370000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007fc307113000)
So I can clearly see they are missing, but how come I dont get any errors? What is the fix? I have linked in the static and shared libraries from xerces
edit: I am now actually getting this when I try to run it:
$ java -Djava.library.path=/home/dcole/IM/work/ext/VC.viewer/viewerNativeDLL/ -jar viewer.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/dcole/IM/work/ext/VC.viewer/viewerNativeDLL/libviewerNativeDLL.so: /home/dcole/IM/work/ext/VC.viewer/viewerNativeDLL/libviewerNativeDLL.so: undefined symbol: _ZTIN11xercesc_3_117SAXParseExceptionE
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1728)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at viewer.SarBufferedImage.<clinit>(SarBufferedImage.java:356)
at viewer.viewerJPanel.<init>(viewerJPanel.java:34)
at viewer.ViewerView.initComponents(ViewerView.java:457)
at viewer.ViewerView.<init>(ViewerView.java:33)
at viewer.ViewerApp.main(ViewerApp.java:21)
edit2:
following the suggestion below, I changed the say I was linking to the libraries, which gives me this command and output:
g++ -O3 -Wall -fopenmp -fPIC -shared -o libviewerNativeDLL.so ViewerNative.o -L/usr/lib64/ ../../lib/IDT.a ../../lib/Linux/libxerces-c.a ../../lib/Linux/libxerces-c-3.1.so -lcurl -lidn -ldl -lssl ../../lib/Linux/libfftw3f.a -lpthread
/usr/bin/ld: ../../lib/Linux/libxerces-c.a(PlatformUtils.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
../../lib/Linux/libxerces-c.a: could not read symbols: Bad value
I guess I will have to recompile xerces with fPIC?
I think the reason is the way you link to the libraries:
-L../../lib/Linux/libxerces-c-3.1.so
-L option is used to specify the search directories for the libraries, and the libraries themselves are specified using -l option.
It should probably be:
-L../../lib/Linux/ -lxerces-c-3.1
or just put the lib without -L
../../lib/Linux/libxerces-c-3.1.so
edit:
You may check with nm libxerces-c-3.1.so|grep ParseException (same for libxerces-c.a) if there's such symbol defined. Make sure also that libxerces that you use for compilation (include paths -I) and the one you use for linking is the same.
Passing -Wl,-no-undefined when linking your library will help you see undefined symbols during linking rather than trying to load the library later.
You are linking again shared libraries, e.g. -L../../lib/Linux/libxerces-c-3.1.so Unless all these are included, your shared library which needs them cannot load.
root#everton-laptop:/opt/tinyos-1.x/apps/Blink# make pc
compiling Blink to a pc binary
ncc -o build/pc/main.exe -g -O0 -board=micasb -pthread -target=pc -Wall -Wshadow -DDEF_TOS_AM_GROUP=0x7d -Wnesc-all -fnesc-nido-tosnodes=1000 -fnesc-cfile=build/pc/app.c Blink.nc -lm
In file included from /opt/tinyos-1.x/tos/platform/pc/packet_sim.h:55,
from /opt/tinyos-1.x/tos/platform/pc/nido.h:81,
from /opt/tinyos-1.x/tos/platform/pc/hardware.h:43,
from /opt/tinyos-1.x/tos/system/tos.h:144:
/opt/tinyos-1.x/tos/types/AM.h:155: parse error before `struct'
/opt/tinyos-1.x/tos/types/AM.h:156: parse error before `struct'
/opt/tinyos-1.x/tos/types/AM.h:158: parse error before `struct'
/opt/tinyos-1.x/tos/types/AM.h: In function `TOS_MsgLength':
/opt/tinyos-1.x/tos/types/AM.h:186: parse error before `TOS_Msg'
In file included from /opt/tinyos-1.x/tos/platform/pc/hardware.h:116,
from /opt/tinyos-1.x/tos/system/tos.h:144:
/opt/tinyos-1.x/tos/platform/pc/eeprom.c: At top level:
/opt/tinyos-1.x/tos/platform/pc/eeprom.c:115: warning: declaration of `length' shadows global declaration
/opt/tinyos-1.x/tos/types/AM.h:158: warning: location of shadowed declaration
/opt/tinyos-1.x/tos/platform/pc/eeprom.c:145: warning: declaration of `length' shadows global declaration
/opt/tinyos-1.x/tos/types/AM.h:158: warning: location of shadowed declaration
make: *** [build/pc/main.exe] Error 1
Tried compiling BLink and i keep getting the above error and not sure what to do next. any help would be nice .
Looking at the CVS repository for tos/types/AM.h, it looks like it's choking on the following code:
154: enum {
155: MSG_DATA_SIZE = offsetof(struct TOS_Msg, crc) + sizeof(uint16_t), // 36 by default
156: TINYSEC_MSG_DATA_SIZE = offsetof(struct TinySec_Msg, mac) + TINYSEC_MAC_LENGTH, // 41 by default
157: DATA_LENGTH = TOSH_DATA_LENGTH,
158: LENGTH_BYTE_NUMBER = offsetof(struct TOS_Msg, length) + 1,
159: TINYSEC_NODE_ID_SIZE = sizeof(uint16_t)
160: };
The common item from lines 155, 156, and 158 are the offsetof() macro, which should be defined in stddef.h and which looks like should have been brought in by the tos.h before it causes AM.h to be included, so offsetof() should already be defined.
You might want to verify whether or not the compiler you're using has offsetof() properly defined and/or why it's not available for use in AM.h. If necessary, you can probably define it yourself using a more or less usual implementation:
#define offsetof(st, m) ((size_t) ( (char *)&((st *)(0))->m - (char *)0 )) // stolen from Wikipedia
I have some classes that implement interfaces, some of which have methods whose parameters are by definition unused in the particular class implementation. e.g. A "Shape" interface may define a "contains(point)" method, but my particular class defines a line, which cannot contain anything since it's 1-dimensional, so it always returns false and never uses point.
However, when I compile with GCJ, I'm assaulted with hundreds of "warning: parameter x is unused" messages.
I tried using the -Wno-all flag to disable warnings, as well as the others documented in gcj's manpage, but these have no effect. How do I instruct GCJ to not bother me with these trivial warnings?
I've managed to disable all warnings affecting my source code using:
gcj -Wno-all -Wno-unchecked -Wno-raw *.java
You may want to add more -Wno-... flags to disable more warnings. To figure out the possible flags, I examined the body of the methods org.eclipse.jdt.internal.compiler.batch.Main.handleWarningToken and org.eclipse.jdt.internal.compiler.batch.Main.handleErrorOrWarningToken in the Eclipse Batch Compiler ecjsrc-3.5.2.zip and ecjsrc-3.8.zip.
Specify all these flags to get all warnings disabled:
-Wno-all
-Wno-allDeadCode
-Wno-allDeprecation
-Wno-allJavadoc
-Wno-allOver-ann
-Wno-all-static-method
-Wno-assertIdentifier
-Wno-boxing
-Wno-charConcat
-Wno-compareIdentical
-Wno-conditionAssign
-Wno-constructorName
-Wno-deadCode
-Wno-dep-ann
-Wno-deprecation
-Wno-discouraged
-Wno-emptyBlock
-Wno-enumIdentifier
-Wno-enumSwitch
-Wno-enumSwitchPedantic
-Wno-fallthrough
-Wno-fieldHiding
-Wno-finalBound
-Wno-finally
-Wno-forbidden
-Wno-hashCode
-Wno-hiding
-Wno-includeAssertNull
-Wno-incomplete-switch
-Wno-indirectStatic
-Wno-interfaceNonInherited
-Wno-intfAnnotation
-Wno-intfNonInherited
-Wno-intfRedundant
-Wno-javadoc
-Wno-localHiding
-Wno-maskedCatchBlock
-Wno-maskedCatchBlocks
-Wno-nls
-Wno-noEffectAssign
-Wno-noImplicitStringConversion
-Wno-null
-Wno-nullDereference
-Wno-over-ann
-Wno-over-sync
-Wno-packageDefaultMethod
-Wno-paramAssign
-Wno-pkgDefaultMethod
-Wno-raw
-Wno-redundantSuperinterface
-Wno-resource
-Wno-semicolon
-Wno-serial
-Wno-specialParamHiding
-Wno-static-access
-Wno-static-method
-Wno-staticReceiver
-Wno-super
-Wno-suppress
-Wno-switchDefault
-Wno-syncOverride
-Wno-synthetic-access
-Wno-syntheticAccess
-Wno-typeHiding
-Wno-unavoidableGenericProblems
-Wno-unchecked
-Wno-unnecessaryElse
-Wno-unqualifiedField
-Wno-unqualified-field-access
-Wno-unsafe
-Wno-unused
-Wno-unusedAllocation
-Wno-unusedArgument
-Wno-unusedArguments
-Wno-unusedImport
-Wno-unusedImports
-Wno-unusedLabel
-Wno-unusedLocal
-Wno-unusedLocals
-Wno-unusedPrivate
-Wno-unusedThrown
-Wno-unusedTypeArgs
-Wno-uselessTypeCheck
-Wno-varargsCast
-Wno-warningToken
Although I haven't found an option to do this directly with gcj, one workaround is to pipe the output into grep and look for the pattern "error:", and then only show that line and a few surrounding lines.
e.g.
javac *.java 2>&1 | grep -B 3 -A 2 "error:"