Facing undefined reference issue for stderr, srand, rand, htons etc.

6,403 views
Skip to first unread message

Anil

unread,
Jun 6, 2013, 4:40:40 AM6/6/13
to andro...@googlegroups.com
Hi All,

I am trying to build the code using Android Standalone Toolchain (android-ndk-r8e/standalone-toolchain-api14).

I am facing the undefined reference errors for "htons", "stderr", "stdin", "__isoc99_sscanf" while linking.

Please let me know how to resolve these errors.


Thanks for your support.

Regards,
Anil Kumar Maguluri

Anil

unread,
Jun 6, 2013, 7:29:30 AM6/6/13
to andro...@googlegroups.com

I am not using Android.mk and Application.mk files. I am running the standalone toolchain from linux shell like the below.

arm-linux-androideabi-gcc -g -Wall -Wpointer-arith -Wreturn-type -Wstrict-prototypes -I../include -I/usr/include -D_REENTRANT -fPIC -c text_file.c

The above command is able to compile and create object file.

But when it is linking, i am getting the below errors.

/home/user/android-ndk-r8e/standalone-toolchain-api14/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: test_file.o: in function finally:hashtbtest.c:45: error: undefined reference to 'stderr'
/home/user/android-ndk-r8e/standalone-toolchain-api14/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: test_file.o: in function main:hashtbtest.c:94: error: undefined reference to 'stdin'



On Thursday, June 6, 2013 2:27:51 PM UTC+5:30, Ben Pope wrote:


On Thursday, 6 June 2013 16:40:40 UTC+8, Anil wrote:
Hi All,

I am trying to build the code using Android Standalone Toolchain (android-ndk-r8e/standalone-toolchain-api14).

I am facing the undefined reference errors for "htons", "stderr", "stdin", "__isoc99_sscanf" while linking.

Please let me know how to resolve these errors.

Sounds like you need to link a c and c++ library... have you set up APP_STL?
 
Ben 

Ben Pope

unread,
Jun 6, 2013, 10:34:11 PM6/6/13
to andro...@googlegroups.com
On 06/06/13 19:29, Anil wrote:
>
> I am not using Android.mk and Application.mk files. I am running the
> standalone toolchain from linux shell like the below.
>
> arm-linux-androideabi-gcc -g -Wall -Wpointer-arith -Wreturn-type
> -Wstrict-prototypes -I../include -I/usr/include -D_REENTRANT -fPIC -c
> text_file.c
>
> The above command is able to compile and create object file.
>
> But when it is linking, i am getting the below errors.
>
> /home/user/android-ndk-r8e/standalone-toolchain-api14/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld:
> test_file.o: in function finally:hashtbtest.c:45: error: undefined
> reference to 'stderr'
> /home/user/android-ndk-r8e/standalone-toolchain-api14/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld:
> test_file.o: in function main:hashtbtest.c:94: error: undefined
> reference to 'stdin'

Perhaps you should try
arm-linux-androideabi-g++ for c++ code?


You need to decide which std library implementation you want to use, in
the NDK directory is sources/cxx-stl/ which contains various std
libraries. I recommend gnu-libstdc++.

You'll want to add the appropriate include path with -I (I don't know
which one it is picking up by default), the library search path with -L
and the library with -l.

Something like:

arm-linux-androideabi-g++
-I/path/to/ndk/sources/cxx-stl/gnu-libstdc++/4.6/include
-I/path/to/ndk/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include
-L/path/to/ndk/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi
-lgnustl_shared

Ben

Ben Pope

unread,
Jun 6, 2013, 10:36:22 PM6/6/13
to andro...@googlegroups.com
On 07/06/13 10:34, Ben Pope wrote:
> On 06/06/13 19:29, Anil wrote:
>>
>> I am not using Android.mk and Application.mk files. I am running the
>> standalone toolchain from linux shell like the below.
>>
>> arm-linux-androideabi-gcc -g -Wall -Wpointer-arith -Wreturn-type
>> -Wstrict-prototypes -I../include -I/usr/include -D_REENTRANT -fPIC -c
>> text_file.c
>>
>> The above command is able to compile and create object file.
>>
>> But when it is linking, i am getting the below errors.
>>
>> /home/user/android-ndk-r8e/standalone-toolchain-api14/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld:
>>
>> test_file.o: in function finally:hashtbtest.c:45: error: undefined
>> reference to 'stderr'
>> /home/user/android-ndk-r8e/standalone-toolchain-api14/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld:
>>
>> test_file.o: in function main:hashtbtest.c:94: error: undefined
>> reference to 'stdin'
>
> Perhaps you should try
> arm-linux-androideabi-g++ for c++ code?

And I also noticed your file is text_file.c, but it fails to link with
stderr, which is, presumably c++, so try renaming your file to .cpp and
using g++ first.

Ben

Reply all
Reply to author
Forward
0 new messages