stdlib.h and unresolved externals

I'm working on a small jni project where and I'm trying to get the shared object to link up correctly. I was able to get it to work just fine until I added a reference to a std call. For example:

c code:

JNIEXPORT jint JNICALL Java_JNITest_gduif_1init (JNIEnv *env, jobject obj, jint flags){

std::string str = "test";

return flags;

}

My compile code is as follows

gcc34 -fPIC -I$JAVA_HOME/include -I$JAVA_HOME/include/linux -shared -o ../jnilibs/libJNITest.so JNITest.cpp

this code produces the following when i call nm -- demangle libJNITest.so

000017a4 d DW.ref.__gxx_personality_v0

00000540 T Java_JNITest_gduif_1init

000016a0 a _DYNAMIC

00001774 a _GLOBAL_OFFSET_TABLE_

w _Jv_RegisterClasses

U _Unwind_Resume@@GCC_3.0

U std::allocator<char>::allocator()

U std::allocator<char>::~allocator()

U std::basic_string<char, std::char_traits><char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)

U std::basic_string<char, std::char_traits><char>, std::allocator<char> >::~basic_string()

00001690 d __CTOR_END__

0000168c d __CTOR_LIST__

00001698 d __DTOR_END__

00001694 d __DTOR_LIST__

0000067c r __FRAME_END__

0000169c d __JCR_END__

0000169c d __JCR_LIST__

000017a8 A __bss_start

w __cxa_finalize@@GLIBC_2.1.3

000005cc t __do_global_ctors_aux

000004a8 t __do_global_dtors_aux

0000179c d __dso_handle

w __gmon_start__

U __gxx_personality_v0

000017a8 A _edata

000017ac A _end

000005fc T _fini

000003e8 T _init

00000480 t call_gmon_start

000017a8 b completed.1

00000504 t frame_dummy

000017a0 d p.0

It appears that the reference to std::string are causing some unresolved externals. I saw an example somewhere where someone used a --add-stdcall-alias option to their compile line, however I get errors saying that option is not valid for /usr/bin/ld

Anyone else have problems when using <stdlib.h> with jni code?

System specs:

Fedora Core 6

gcc 4.1.1

GNU ld version 2.17.50.0.6-2.fc6 20061020

[2283 byte] By [BrianSmitha] at [2007-11-27 4:42:30]
# 1
Removed accidental post.
Niceguy1a at 2007-7-12 9:54:04 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

> I'm working on a small jni project where and I'm

> trying to get the shared object to link up correctly.

> I was able to get it to work just fine until I added

> a reference to a std call. For example:

>

> c code:

> JNIEXPORT jint JNICALL Java_JNITest_gduif_1init

> (JNIEnv *env, jobject obj, jint flags){

> std::string str = "test";

> return flags;

> }

The following example works fine on my machine:

======StdStringTest.java=============

public class StdStringTest {

static {

System.loadLibrary("stdstringtest");

}

StdStringTest() {

System.out.println(test(42));

}

public static void main(String[] args) {

new StdStringTest();

}

private native int test(int flag);

}

=========StdStringTest.cpp==============================

#include "StdStringTest.h"

#include <string>

JNIEXPORT jint JNICALL Java_StdStringTest_test

(JNIEnv *env, jobject obj, jint flag) {

std::string str = "test";

return flag + 1;

}

Compiled with:

gcc -shared -I/usr/java/jdk1.6.0_01/include -I /usr/java/jdk1.6.0_01/include/linux -o libstdstringtest.so StdStringTest.cpp

gcc version 4.1.2

Niceguy1a at 2007-7-12 9:54:04 > top of Java-index,Java HotSpot Virtual Machine,Specifications...