Friday, July 10, 2009

Unresolved external NS_NewGenericModule2...resolved

Today I tryed to build my first XPCOM module using this link. It's a great tutorial and you can make a XPCOM component in no time, but when I tryed to build it in windows I got this error:

Error 1 error LNK2001: unresolved external symbol "unsigned int __cdecl NS_NewGenericModule2(struct nsModuleInfo const *,class nsIModule * *)" (?NS_NewGenericModule2@@YAIPBUnsModuleInfo@@PAPAVnsIModule@@@Z)

I've searched and found out that I wasn't the only one having this issue. Some suggested you have to change the Gecko SDK version, but the real solution to the problem is this.
To solve the problem and set the flag in MVS you should go to Project > Properties > Configuration properties > Linker > Command line and then just paste "-LIBPATH:C:\...\gecko-sdk\lib xpcomglue_s.lib xpcom.lib nspr4.lib" in the Additional options textbox and voila!
Hope this helps!

P.S. I did't came with a new solution to the problem, but made it clear how to add linker flags to your MVS project.

2 comments:

  1. Thanks for this post, it pointed me in the right direction.

    I was able to build against 1.9.2 using VS 2008 when I added the preprocessor flag XPCOM_GLUE_USE_NSPR, removed the linker reference to xpcomglue.lib, and added xpcom.lib and xpcomglue_s.lib.

    ReplyDelete
  2. I had this issue, too, and I changed -lxpcomglue (using Makefiles in Linux) to -lxpcomglue_s and -lxpcom, but still the undefined symbol thing. In one moment I noticed a custom defined value in the Makefile -DXPCOM_GLUE and changed it to -DXPCOM_GLUE_S (because of -lxpcomglue_s) and - it WORKED! Linked successfully.

    ReplyDelete