views:

1815

answers:

3

I am building an application as a library, but to make sure I can get the output that I'd like, I switched it over to produce an exe. As soon as I did, I got several errors about unresolved external symbols.

At first I thought that I didn't have a path set to the 3rd party library that I was referencing, so I added the folder to my path variable and even added it to my include, references, and source files, just to make sure I had all the paths.

I still get the error:

error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl xercesc_2_8::XMLPlatformUtils::Initialize(char const * const,char const * const,class xercesc_2_8::PanicHandler * const,class xercesc_2_8::MemoryManager * const,bool)" (__imp_?Initialize@XMLPlatformUtils@xercesc_2_8@@SAXQBD0QAVPanicHandler@2@QAVMemoryManager@2@_N@Z) referenced in function "void __cdecl xsd::cxx::xml::initialize(void)" (?initialize@xml@cxx@xsd@@YAXXZ)

The reason that I'm asking it here is because in Visual Studio, when I built it as a library, I didn't get these errors, but as a dll and exe, I do.

Anybody have any thoughts?

+2  A: 

You also need to specify that you wish to link against that library in particular. The link paths merely tell the linker where the data you need to find is, not what to look for. You will also need to specify that you are linking against the library in question (xerces?).

Unfortunately, I don't know how to specify this in MSVC, but it's probably somewhere under 'Linker Options'.

coppro
+1  A: 

Building a library, the linker doesn't need to resolve imported symbols. That happens only when it starts linking object files and libraries together.

That's why you only started seeing the error when building an executable.

Indeed, in VC2008 (and 2005, if I remember well), use the project properties -> Linker -> Input -> Additional dependencies. The libraries you need are to be separated by spaces (odd, hey?)

Good Luck!

xtofl
A: 

As @coppro said, you need to specify that you want to link with that library. When you build an EXE or DLL, a linker is run, and it needs to find all the functions you are using, but to build a library, the librarian is run, and it doesn't have to resolve all function references (but when you use that lib in an EXE, you'll have to, again).

So go to the project's options, Linker Options, Input, and list the library that defines the missing function (xerces.lib?) under Additional Library Paths. You might need to add its location under Additional Library Paths.

Lev