3

I'm new to c++ programming and currently working on an llvm front-end development project. When I link the object files created by llc, my linker cannot locate the following functions. I know that these are standard c++ library functions but using -lstdc++ doesn't work. Now my question is that where are these functions defined and how can I link them with my object files, and actually what do they do?

declare noalias i8* @_Znam(i64)

declare noalias i8* @_Znwm(i64)
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
user1723583
  • 553
  • 1
  • 6
  • 18
  • Isn't this a duplicate of your older question http://stackoverflow.com/q/12750526 ? What's the difference between this one and the old one? – Oak Jan 13 '13 at 08:47
  • Yes, but as no one answered that question I tried to ask it in another way – user1723583 Jan 13 '13 at 09:50

1 Answers1

4

These functions are standard C++ library functions, in particular, operator new[](unsigned long) and operator new(unsigned long). They should be provided by your C++ runtime library. Depending on which compiler you're using this will be libsupc++ or libc++abi or libcxxrt.

Anton Korobeynikov
  • 9,074
  • 25
  • 28
  • Thanks for your help, but it seems that these libraries aren't installed on my system. How should I install them? I'm using g++ to link the object files and my system is ubuntu 11.04 – user1723583 Jan 15 '13 at 13:52
  • Then you definitely have libsupc++. Either directly, or as a part of libstdc++. – Anton Korobeynikov Jan 15 '13 at 19:57
  • So, why cannot g++ locate these functions? I used -lsupc++. Also, I found that libsupc++.a is in folder /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5, so added this folder to the search path but this error occurred again – user1723583 Jan 16 '13 at 11:45
  • How have you generated your IR? – Anton Korobeynikov Jan 16 '13 at 16:35
  • 1
    In fact, I'm writing a compiler for a DSL in java and in order to learn how to generate intermediate code I utilized the llvm language reference and the demo version of clang. When I was working on arrays I saw that clang generated a call to @_Znam and also a call to @_Znwm when allocating memory for an object, therefore I did what clang did, but encountered the the following errors: 'undefined reference to operator new(unsigned long)' & 'undefined reference to operator new[](unsigned long)' – user1723583 Jan 16 '13 at 18:19
  • These are C++-level constructs. And you should not use them blindly :) In fact, you should not use them at all! Most probably, mangling is a bit different for your platform. – Anton Korobeynikov Jan 17 '13 at 09:28
  • In my language all arrays are dynamic (i.e. their size is determined at runtime), so for example if I want to define an array of integers I can't use '%x = alloca [%len x i32]', and if I shouldn't use @_Znam (like clang) then how do I allocate memory for them? – user1723583 Jan 17 '13 at 13:37
  • You can use any way of allocating memory available for you. E.g. via ordinary malloc. – Anton Korobeynikov Jan 18 '13 at 15:10