'new' undeclared (first use in this function)

2,839 views
Skip to first unread message

murkser

unread,
Sep 3, 2010, 5:57:41 PM9/3/10
to android-ndk
Hi!

I am quite new to the android-ndk.
For this line

str = new char[50];

I get the " 'new' undeclared (first use in this function) "-Error. I
thought C++ is supported?
Thank you for your help.

Alex

Tim Mensch

unread,
Sep 3, 2010, 6:07:38 PM9/3/10
to andro...@googlegroups.com
On 9/3/2010 3:57 PM, murkser wrote:
> I am quite new to the android-ndk.
> For this line
>
> str = new char[50];
>
> I get the " 'new' undeclared (first use in this function) "-Error. I
> thought C++ is supported?
Looks like you're building as C. What's your file extension?

Tim

murkser

unread,
Sep 3, 2010, 6:13:25 PM9/3/10
to android-ndk
I have two files in this project.
The file with the function I want to use in java has *.c (with *.cpp I
get an error here)
In this file I start a function from another file (*.cpp) where I want
to put my C++ code (including str = new char[50]; )

Tim Mensch

unread,
Sep 3, 2010, 10:56:56 PM9/3/10
to andro...@googlegroups.com
On 9/3/2010 4:13 PM, murkser wrote:
> I have two files in this project.
> The file with the function I want to use in java has *.c (with *.cpp I
> get an error here)
> In this file I start a function from another file (*.cpp) where I want
> to put my C++ code (including str = new char[50]; )
new is a keyword in C++. If the file in question is being built as C++,
there is no way for "new" to be undefined; you can get link errors if it
can't find the proper library, though. Are you saying that the "new
char[50]" appears in a .cpp file? And that the .cpp file is being
included in Android.mk as part of LOCAL_SRC_FILES?

What is the exact error message you're getting? And what does the
compile line look like when you run:

ndk-build V=1

...to get a verbose build?

Tim

alan

unread,
Sep 6, 2010, 4:34:35 AM9/6/10
to android-ndk
is the cpp extension defined correctly in your make file?

murkser

unread,
Sep 6, 2010, 1:25:53 PM9/6/10
to android-ndk
I declared everything as .cpp and now it works. Thanks for your help.
Reply all
Reply to author
Forward
0 new messages