PDA

View Full Version : JNI C++ Compilation Errors




jw2002
Feb 23, 2008, 01:32 PM
I am having a terrible time trying to compile even the simplest source code that links to a jni header file under OS X v 10.5.2. Here is the program "blort.cpp":


#include "jawt_md.h"
int main()
{
return 0;
}



And here is the compilation attempt and resulting set of error messages:


% cc -v
Using built-in specs.
Target: powerpc-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5465~16/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin9 --program-prefix= --host=powerpc-apple-darwin9 --target=powerpc-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5465)
% cc -c -I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers blort.cpp

In file included from /System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:5,
from /System/Library/Frameworks/AppKit.framework/Headers/NSResponder.h:8,
from /System/Library/Frameworks/AppKit.framework/Headers/NSView.h:8,
from /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers/jawt_md.h:11,
from blort.cpp:1:
/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:120: error: stray ‘@’ in program
In file included from /System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:6,
from /System/Library/Frameworks/AppKit.framework/Headers/NSResponder.h:8,
from /System/Library/Frameworks/AppKit.framework/Headers/NSView.h:8,
from /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers/jawt_md.h:11,
from blort.cpp:1:
/System/Library/Frameworks/Foundation.framework/Headers/NSZone.h:8: error: stray ‘@’ in program
In file included from /System/Library/Frameworks/AppKit.framework/Headers/NSResponder.h:8,
from /System/Library/Frameworks/AppKit.framework/Headers/NSView.h:8,
from /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers/jawt_md.h:11,
from blort.cpp:1:
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:8: error: stray ‘@’ in program
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:9: error: stray ‘@’ in program

... 5000+ remaining lines of errors deleted ...


I noticed that there is no "--enable-java-awt=gtk" flag listed as part of the gcc compiler executable that I am using (installed with latest version of Xcode 3.0). And I assume that this is why the compiler is getting tripped up on the '@' symbols that are present deep down within the system level jni header files.

When I compile the same program on a redhat box, it is successful:


% cc -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.4/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)
% cc -c -I/usr/local/java/jdk1.6.0_03-32/include/linux -I/usr/local/java/jdk1.6.0_03-32/include blort.cpp
% ls blort.o
blort.o


Any suggestions? Thanks.



kainjow
Feb 24, 2008, 03:58 PM
Did you ever get this working? It looks like the JavaVM headers on Mac OS X #include Cocoa headers, so you may need to make GCC aware that you're compiling Objective-C code.