undefined reference to `operator new(unsigned int)'

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

undefined reference to `operator new(unsigned int)'

Klaus T.
Hi,

Recently I started moving from GCC to Clang to compile my own OS. I am using Windows and to compile my source files I use "clang++ -ccc-host-triple i686-pc-linux" and  link them with i686-elf-ld. However, when I use the "new operator" (like int*p = new int; ...) I get "undefined reference to `operator new(unsigned int)'" while linking and yes, I use -lstdc++. When I compile my source files with GCC I don't have this problem. Any ideas?

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: undefined reference to `operator new(unsigned int)'

Eli Friedman
On Fri, Apr 8, 2011 at 2:33 PM, Klaus T. <[hidden email]> wrote:
> Hi,
> Recently I started moving from GCC to Clang to compile my own OS. I am using
> Windows and to compile my source files I use "clang++ -ccc-host-triple
> i686-pc-linux" and  link them with i686-elf-ld. However, when I use the "new
> operator" (like int*p = new int; ...) I get "undefined reference to
> `operator new(unsigned int)'" while linking and yes, I use -lstdc++. When I
> compile my source files with GCC I don't have this problem. Any ideas?

Can you attach the .s output from GCC and clang?

-Eli

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: undefined reference to `operator new(unsigned int)'

Eli Friedman
On Fri, Apr 8, 2011 at 3:33 PM, Klaus T. <[hidden email]> wrote:

> Here you are.
>
> 2011/4/9 Eli Friedman <[hidden email]>
>>
>> On Fri, Apr 8, 2011 at 2:33 PM, Klaus T. <[hidden email]> wrote:
>> > Hi,
>> > Recently I started moving from GCC to Clang to compile my own OS. I am
>> > using
>> > Windows and to compile my source files I use "clang++ -ccc-host-triple
>> > i686-pc-linux" and  link them with i686-elf-ld. However, when I use the
>> > "new
>> > operator" (like int*p = new int; ...) I get "undefined reference to
>> > `operator new(unsigned int)'" while linking and yes, I use -lstdc++.
>> > When I
>> > compile my source files with GCC I don't have this problem. Any ideas?
>>
>> Can you attach the .s output from GCC and clang?

(For future reference, please use reply-to-all so cfe-dev ends up on
the CC list.)

It looks like the gcc-generated code is calling _Znwm, while the
clang-generated code is calling _Znwj, which means clang is coming up
with the "wrong" definition of size_t.  So basically, the issue is
that "-ccc-host-triple i686-pc-linux" doesn't accurately reflect your
target.  What's the output of gcc -v?

-Eli

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: undefined reference to `operator new(unsigned int)'

Eli Friedman
On Fri, Apr 8, 2011 at 4:56 PM, Klaus T. <[hidden email]> wrote:
> Using built-in specs.
> COLLECT_GCC=i686-elf-gcc
> Target: i686-elf
> Configured with: ../gcc-4.6.0/configure --target=i686-elf
> --prefix=/usr/i686-gcc
>  --disable-nls --enable-languages=c,c++ --with-newlib --with-gmp=/local/gmp
> --with-mpfr=/local/mpfr --with-mpc=/local/mpc
> Thread model: single
> gcc version 4.6.0 (GCC)

Mmm... clang doesn't have support for "i686-elf" at the moment.
Patches welcome.  (Please ask if you need guidance).

-Eli

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev