I'm developing an llvm-based compiler and when I try to generate executable file the following error occurs: ./bin/llvmcode.s:35: undefined reference to `operator new[](unsigned long)' Note that in the generated IR, the function '@_Znam' is called which is located in one of llvm libraries. So, I should have linked the generated assembly file with that library. Here is the code I used to do that: llvm-as ./bin/llvmcode.ll llc ./bin/llvmcode.bc g++ -g ./bin/llvmcode.s \`llvm-config --cppflags --ldflags --libs core jit native\` -O3 -o executable -rdynamic What's wrong with this code that causes the above error, and what's the best way to generate an executable file from ll files? Any assistance would be appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130109/d01a608a/attachment.html>
On Wed, Jan 9, 2013 at 5:32 AM, Ali Sedaghat <ali.sedaghatbaf at gmail.com> wrote:> I'm developing an llvm-based compiler and when I try to generate > executable file the following error occurs: > > ./bin/llvmcode.s:35: undefined reference to `operator new[](unsigned > long)' > > Note that in the generated IR, the function '@_Znam' is called which is > located in one of llvm libraries. So, I should have linked the generated > assembly file with that library.That operator is defined in the C++ standard library. You probably don't want to be linking the output of your compiler with LLVM libraries, they'd be what you'd use to build the compiler itself. However, g++ should find the required function anyway. It's possible you have to add a "-lstdc++" (or -lc++ if you're using libc++, etc). But it makes me wary about the rest of your toolchain. Tim.
First, I shoud thank you for your suggested solution. Now, I have another question. I use the following command to generate executable file from llvm bitcode: On Wed, Jan 9, 2013 at 8:18 PM, Tim Northover <t.p.northover at gmail.com>wrote:> On Wed, Jan 9, 2013 at 5:32 AM, Ali Sedaghat <ali.sedaghatbaf at gmail.com> > wrote: > > I'm developing an llvm-based compiler and when I try to generate > > executable file the following error occurs: > > > > ./bin/llvmcode.s:35: undefined reference to `operator new[](unsigned > > long)' > > > > Note that in the generated IR, the function '@_Znam' is called which is > > located in one of llvm libraries. So, I should have linked the generated > > assembly file with that library. > > That operator is defined in the C++ standard library. You probably > don't want to be linking the output of your compiler with LLVM > libraries, they'd be what you'd use to build the compiler itself. > > However, g++ should find the required function anyway. It's possible > you have to add a "-lstdc++" (or -lc++ if you're using libc++, etc). > But it makes me wary about the rest of your toolchain. > > Tim. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130109/3b4fa2e7/attachment.html>