I'm trying to build Firefox extension with some C/C++ code and <a
href="http://www.nlnetlabs.nl/projects/ldns">ldns</a> library. I have
got already working solution on Linux and Mac OS X (all binary code
compiled by g++), but I can't get it working on Windows.
Compiling of extension and ldns (by mingw's gcc) is successful, but
when I try to link it together, I get following error:
c++ -Wall -Os -o dnssecValidator.dll dnssecValidator.cpp
dnssecValidatorModule.cpp -include "xpcom-config.h" -I C:\dev
\xulrunner-sdk\sdk\include -DXP_WIN -shared -Ildns -Lwin32 -L C:\dev
\xulrunner-sdk\sdk\lib -L C:\dev\xulrunner-sdk\sdk\bin -lxpcomglue_s -
lxpcom -lnspr4 -lldns
C:\DOCUME~1\zbynek\LOCALS~1\Temp\ccOnVuVY.o:dnssecValidator.cpp:(.text
+0x7c): undefined reference to `NS_TableDrivenQI(void*, QITableEntry
const*, nsID const&, void**)@16'
C:\DOCUME~1\zbynek\LOCALS~1\Temp\ccGiUeI4.o:dnssecValidatorModule.cpp:
(.text+0x15): undefined reference to `NS_NewGenericModule2
(nsModuleInfo const*, nsIModule**)'
collect2: ld returned 1 exit status
mingw32-make: *** [build] Error 1
I use <a href="http://releases.mozilla.org/pub/mozilla.org/xulrunner/
releases/1.9.1.3/sdk/xulrunner-1.9.1.3.en-US.win32.sdk.zip">xulrunner
1.9.1.3</a> which is compiled by MS Visual Studio. So is it possible
to link msvc's library by mingw's linker?
I also tried to compile xulrunner by mingw's g++ (according to
https://developer.mozilla.org/En/Cross_Compile_Mozilla_for_Mingw32),
but in this case I receive while compiling:
Building deps for /home/zmichl/sandbox/mozilla-1.9.1/js/src/jsapi.cpp
i686-mingw32-g++ -mno-cygwin -o jsapi.o -c -DFEATURE_NANOJIT -
DJS_TRACER -DOSTYPE=\"WINNT\" -DOSARCH=WINNT -DEXPORT_JS_API -
DJS_USE_SAFE_ARENA -I/home/zmichl/sandbox/mozilla-1.9.1/js/src -I. -
I./../../dist/include -I./../../dist/include/js -I/home/zmichl/
sandbox/mozilla-mingw/dist/include/nspr -I/sdk/include -I/home/zmichl/
sandbox/mozilla-1.9.1/js/src -I/usr/include -fno-rtti -fno-
exceptions -Wall -Wpointer-arith -Woverloaded-virtual -Wsynth -Wno-
ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-invalid-
offsetof -Wno-long-long -pedantic -fno-strict-aliasing -mms-bitfields -
pipe -DDEBUG -D_DEBUG -DDEBUG_zmichl -DTRACING -g -I/usr/include -
DCROSS_COMPILE=1 -DWINVER=0x501 -D_WIN32_WINNT=0x501 -
D_WIN32_IE=0x0500 -DHAVE_SNPRINTF=1 -D_WINDOWS=1 -D_WIN32=1 -DWIN32=1 -
DXP_WIN=1 -DXP_WIN32=1 -DHW_THREADS=1 -DSTDC_HEADERS=1 -DNEW_H=\<new\>
-DWIN32_LEAN_AND_MEAN=1 -DNO_X11=1 -D_X86_=1 -DD_INO=d_ino -
DAVMPLUS_IA32=1 -DAVMPLUS_WIN32=1 -DSTDC_HEADERS=1 -DHAVE_ST_BLKSIZE=1
-DHAVE_SIGINFO_T=1 -DJS_HAVE_STDINT_H=1 -DJS_BYTES_PER_WORD=4 -
DJS_BITS_PER_WORD_LOG2=5 -DJS_ALIGN_OF_POINTER=4 -
DJS_BYTES_PER_DOUBLE=8 -DHAVE_INT16_T=1 -DHAVE_INT32_T=1 -
DHAVE_INT64_T=1 -DHAVE_UINT=1 -DHAVE_UNAME_US_DOMAINNAME_FIELD=1 -
DHAVE_CPP_2BYTE_WCHAR_T=1 -DHAVE_DIRENT_H=1 -DHAVE_GETOPT_H=1 -
DHAVE_SYS_BITYPES_H=1 -DHAVE_MEMORY_H=1 -DHAVE_UNISTD_H=1 -
DHAVE_GNU_LIBC_VERSION_H=1 -DHAVE_NL_TYPES_H=1 -DHAVE_MALLOC_H=1 -
DHAVE_X11_XKBLIB_H=1 -DHAVE_SYS_STATVFS_H=1 -DHAVE_SYS_STATFS_H=1 -
DHAVE_SYS_VFS_H=1 -DHAVE_SYS_MOUNT_H=1 -DNEW_H=\<new\> -
DHAVE_SYS_CDEFS_H=1 -DHAVE_LIBM=1 -DHAVE_STRERROR=1 -DHAVE_MEMMOVE=1 -
DHAVE_RINT=1 -DHAVE_GETPAGESIZE=1 -DHAVE_CPP_EXPLICIT=1 -
DHAVE_CPP_TYPENAME=1 -DHAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX=1 -
DHAVE_CPP_PARTIAL_SPECIALIZATION=1 -DHAVE_CPP_ACCESS_CHANGING_USING=1 -
DHAVE_CPP_AMBIGUITY_RESOLVING_USING=1 -DHAVE_CPP_NAMESPACE_STD=1 -
DHAVE_CPP_UNAMBIGUOUS_STD_NOTEQUAL=1 -DHAVE_CPP_NEW_CASTS=1 -
DNEED_CPP_UNUSED_IMPLEMENTATIONS=1 -DHAVE_I18N_LC_MESSAGES=1 -
DHAVE___CXA_DEMANGLE=1 -DMOZ_DEMANGLE_SYMBOLS=1 -
DHAVE__UNWIND_BACKTRACE=1 -DHAVE_TM_ZONE_TM_GMTOFF=1 -
DCPP_THROW_NEW=throw\(\) -DMOZ_DLL_SUFFIX=\".dll\" -DJS_THREADSAFE=1 -
DMOZ_REFLOW_PERF=1 -DMOZ_REFLOW_PERF_DSP=1 -D_MOZILLA_CONFIG_H_ -
DMOZILLA_CLIENT /home/zmichl/sandbox/mozilla-1.9.1/js/src/jsapi.cpp
In file included from /home/zmichl/sandbox/mozilla-1.9.1/js/src/
jsbuiltins.h:45,
from /home/zmichl/sandbox/mozilla-1.9.1/js/src/
jsapi.cpp:59:
/home/zmichl/sandbox/mozilla-1.9.1/js/src/nanojit/nanojit.h:139:48:
warning: anonymous variadic macros were introduced in C99
/home/zmichl/sandbox/mozilla-1.9.1/js/src/nanojit/nanojit.h:145:47:
warning: anonymous variadic macros were introduced in C99
/home/zmichl/sandbox/mozilla-1.9.1/js/src/nanojit/nanojit.h:147:30:
warning: anonymous variadic macros were introduced in C99
/home/zmichl/sandbox/mozilla-1.9.1/js/src/nanojit/nanojit.h:193:23:
warning: anonymous variadic macros were introduced in C99
In file included from /home/zmichl/sandbox/mozilla-1.9.1/js/src/
nanojit/nanojit.h:245,
from /home/zmichl/sandbox/mozilla-1.9.1/js/src/
jsbuiltins.h:45,
from /home/zmichl/sandbox/mozilla-1.9.1/js/src/
jsapi.cpp:59:
/home/zmichl/sandbox/mozilla-1.9.1/js/src/nanojit/Native.h:106:22:
warning: anonymous variadic macros were introduced in C99
In file included from /home/zmichl/sandbox/mozilla-1.9.1/js/src/
jsutil.h:114,
from /home/zmichl/sandbox/mozilla-1.9.1/js/src/
jsapi.cpp:51:
/usr/include/stdio.h:432: error: expected initializer before 'throw'
/usr/include/stdio.h:488: error: expected initializer before 'throw'
make[4]: *** [jsapi.o] Error 1
make[4]: Leaving directory `/home/zmichl/sandbox/mozilla-mingw/js/src'
make[3]: *** [libs_tier_js] Error 2
make[3]: Leaving directory `/home/zmichl/sandbox/mozilla-mingw'
make[2]: *** [tier_js] Error 2
make[2]: Leaving directory `/home/zmichl/sandbox/mozilla-mingw'
make[1]: *** [default] Error 2
make[1]: Leaving directory `/home/zmichl/sandbox/mozilla-mingw'
make: *** [build] Error 2
So my question is: How can I link msvc's libraries (from xulrunner) by
mingw's linker? Or if it is impossible, how can I compile xulrunner by
mingw's g++ (to get both ldns and xulrunner compiled by the same
compiler)?
Or any other hints how to get extension working on Windows? :)
Thanks a lot
Zbynek
I'd guess the easy solution would be to
a) Compile and link the ldns.dll with MSVC (provided that the source is
easily portable). Then you get a .def/.lib you may link against. You may
even decide to statically link it, so that you avoid some runtime/dll-hell.
b) Use the ldns.dll produces by gcc and generate an MSVC compatible
library from it:
http://support.microsoft.com/?scid=kb%3Ben-us%3B131313&x=8&y=17
c) Create the .def yourself and generate an import library from it.
I don't think there is a feasible way to link g++ and msvc cl output
together as both use their own incompatible version of C++ name
mangling. But I could be wrong, of course.
Cheers
Nils
Ok. I have compiled ldns with mingw's gcc and it produced static
library libldns.a. I need to statically link this library with my
extension's library to create one .dll. I have tried to add libldns.a
to the linker's additional dependencies in MSVC. Compilation and
linking of the extension with libldns seems to be fine, but the final
size of .dll is very small. When I load it to FF and try to call some
ldns's function, browser completely crashes. So it seems that ldns is
not linked well. Is any special procedure how to statically link
mingw's gcc .a library with MSVC extension's .dll library? Or how can
I tell to MSVC's compiler/linker which library I would like to link
statically and which dynamically (something like -Bstatic and -
Bdynamic gnu ld's options)?
Thanks
Zb.
Another question. Can I use cygwin instead of mingw for compiling some
parts of the FF extension and then link it by MSVC into .dll? I know
that cygwin1.dll will need to be present in the system in this case.
Thanks
Zb.
Sounds like you're working on something similar to what I'm doing.
I've built ldns using cygwin, but ran into the same problems you
mentioned earlier - specifically 'NS_TableDrivenQI' symbol not found
when linking to the XPCOM libs. What did you finally do to get past
that one? One of the solutions mentioned by Nils?
I'm starting to think that the best, but probably most painful,
solution is to port ldns to VC.
Thanks,
Eddie