Reputation: 500
I'm trying to compile a c++ source code file from the DXC competition.
The instructions are:
To compile any of the C++ examples (or a DA written in C++) under Windows, MS Visual C++ 8.0 (2005) is required. Make sure to add %DXC_HOME%\Lib and %DXC_HOME%\Include to your library and header search paths respectively, and add dxcApi.lib to your list of libraries (or dxcApid.lib if compiling in debug mode).
I added Lib and the Include libraries to the library and search paths and it imported them. What I didn't understand is the meaning of the second step: "add dxcApi.lib to your list of libraries" - what does it mean?
Without this step I'm getting linker errors, such as:
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: _thiscall Dxc::CandidateSet::~CandidateSet(void)" (_imp_??1CandidateSet@Dxc@@QAE@XZ) referenced in function "public: void __thiscall ExampleDA::sendDiagnosis(void)" (?sendDiagnosis@ExampleDA@@QAEXXZ) D:\Dropbox\Work\Visual Studio 2010\Projects\DXC11\DXC11\ExampleDA.obj DXC11
I'm stuck with this problem for quite some time now and I'm desperate for help! Thanks a lot
Upvotes: 0
Views: 354
Reputation: 131789
The task says to add that particular .lib to the list of libraries that get linked to your code. Without saying that this library should be linked, the implementation for the functions defined in its headers is not available to the linker and you get that unresolved external symbol.
In VS, you can add something to the linked libraries list either through a #pragma comment
or in the project settings:
// at the top of main.cpp, preferrably
#pragma comment(lib, "the_lib_name.lib") // .lib optional
You can have different libraries for debug and release with simply surrounding the #pragma comment
in an #if
block:
#ifdef NDEBUG // release
#pragma comment(lib, "the_lib_name.lib")
#else // debug
#pragma comment(lib, "the_lib_named.lib") // most debug libraries end with a 'd'
#endif
And for the project settings you can do so with
[Project] -> <Project Name> Properties (or Alt-F7) -> Configuration Properties
-> Linker -> Input -> Additional Dependencies
Just add the_lib_name.lib
at the front (followed by either a space or a semi-colon ;
). Make sure you add the correct library for the active project configuration (debug / release).
Upvotes: 2
Reputation: 258568
You need to add the specific lib
file to the libraries list, so that the linker can search it for the symbols you're missing.
Upvotes: 2