2

I'm trying to link my XPCOM extension against the 1.9.3a3pre SDK and I get the following:

error LNK2001: unresolved external symbol _moz_xmalloc

So, what lib do I need to link to? The documentation doesn't say.

This is on Windows right now, but I'll need it to build on Mac and Linux (32bit/64bit) as well.

Edit: Now with bounty.

Edit: Update: Turns out FF3.7 was cancelled. So I don't have to worry about this until FF4.

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222

5 Answers5

4

I have same error, and linking to mozalloc helps for that.

miara
  • 320
  • 1
  • 5
  • mozalloc wasn't in the xulrunner sdk (for Windows) that I downloaded. Where did you get it? – i_am_jorf Mar 19 '10 at 15:16
  • I was writing an extension for Thunderbird and I've build Thunderbird from sources before that (using latest comm-central), and this lib was in mozilla/dist/lib in Thunderbird build directory, so in your case it is probably not the solution. Does linker said where the linking error occured (what was the object the symbol was referenced in)? – miara Mar 19 '10 at 17:16
  • xpcomglue_s.lib(nsCOMPtr.obj) : error LNK2001: unresolved external symbol _moz_xmalloc xpcomglue_s.lib(nsComponentManagerUtils.obj) : error LNK2001: unresolved external symbol _moz_xmalloc – i_am_jorf Mar 21 '10 at 00:06
  • Pretty sure you're right about what I need to link too... I just wonder where to get it. Perhaps they haven't got it building on Windows yet so the xulrunner SDK doesn't have it? Maybe I just need to wait for beta? – i_am_jorf Mar 21 '10 at 00:07
  • can you give me link for mozalloc.lib, I can't find it in Mozilla Central latest SDK. – Priyank Bolia Aug 01 '10 at 11:29
1
  1. Add MOZ_NO_MOZALLOC in C++->Preprocessor->Definition property.

  2. Use xpcomglue_s_nomozalloc.lib instead of xpcomglue_s.lib in Linker->Input->Additional Dependencies

It will be OK!

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
Hao Dong
  • 53
  • 5
1

Try defining MOZ_NO_MOZALLOC when compiling your extension, you will then get a DLL that uses your CRT's allocators. (Don't forget to use the NS_* allocators for XPCOM-compatible memory.)

Neil
  • 54,642
  • 8
  • 60
  • 72
1

define 'XPCOM_GLUE' in C++ Preprocessor Definition property. It will fix the linking error.

chown
  • 51,908
  • 16
  • 134
  • 170
  • I have already defined 'XPCOM_GLUE'. still i am getting the Same error as xpcomglue_s.lib(GenericFactory.obj) : error LNK2001: unresolved external symbol __imp__moz_xmalloc. What will will be issue? – Prabhu Jan 03 '12 at 11:07
0

reminder note: another option that can cause this even though everything else seems to be configured correctly in the project, is pointing at the wrong libs folder - such as 32 bit version for a 64 bit build.

edit v40 mozalloc.lib has changed name to mozglue.lib and has some additional methods.

edit v41 mozglue.lib has changed name to mozcrt.lib

Greg Domjan
  • 13,943
  • 6
  • 43
  • 59