Archived

This topic is now archived and is closed to further replies.

Coconut

Static Library import/export and LNK2001

Recommended Posts

Coconut    122
Hey, I tried to put all my game engine code into a static library, and it compiles fine now with my actual application using the project as a dependency. The actual .lib is included in linking, and I have a header file that #include''s all of the headers in the library code so that all functions/class'' are included, etc... all compiles fine. Now, when I go to link, I get several LNK2001 errors that I shouldn''t be getting. They''re: Linking... breakout_main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CGDLLIterator::MoveToNext(void)" (?MoveToNext@CGDLLIterator@@QAE_NXZ) breakout_main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CGDLLIterator::InsertData(void *,unsigned long)" (?InsertData@CGDLLIterator@@QAE_NPAXK@Z) breakout_main.obj : error LNK2001: unresolved external symbol "public: class CGDLLIterator * __thiscall CGDLinkedList::GetIterator(void)" (?GetIterator@CGDLinkedList@@QAEPAVCGDLLIterator@@XZ) breakout_main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CGDLinkedList::Create(void)" (?Create@CGDLinkedList@@QAE_NXZ) breakout_main.obj : error LNK2001: unresolved external symbol "public: __thiscall CGDLinkedList::CGDLinkedList(void)" (??0CGDLinkedList@@QAE@XZ) breakout_main.obj : error LNK2001: unresolved external symbol "bool __cdecl InitGraphicsLibrary(struct HWND__ *,int,int,int,struct _GUID *,struct tagLOGFONTA *,int)" (?InitGraphicsLibrary@@YA_NPAUHWND__@@HHHPAU_GUID@@PAUtagLOGFONTA@@H@Z) breakout_main.obj : error LNK2001: unresolved external symbol "public: __thiscall CGDLinkedList::~CGDLinkedList(void)" (??1CGDLinkedList@@QAE@XZ) breakout_main.obj : error LNK2001: unresolved external symbol "public: void * __thiscall CGDLLIterator::GetData(void)" (?GetData@CGDLLIterator@@QAEPAXXZ) breakout_main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CGDLLIterator::MoveToFirst(void)" (?MoveToFirst@CGDLLIterator@@QAE_NXZ) arrow game library.lib(GKeyboard.obj) : error LNK2001: unresolved external symbol "public: virtual bool __thiscall CGKeyboard::Destroy(void)" (?Destroy@CGKeyboard@@UAE_NXZ) Debug/BreakOut.exe : fatal error LNK1120: 10 unresolved externals Error executing link.exe. BreakOut.exe - 11 error(s), 0 warning(s) Do I need to include a .def file declaring the exports, and if so how? What can I do? I tried prototyping the classes in the actual application file, as well as in the library include file. Thanks! -Brent Robinson

Share this post


Link to post
Share on other sites
LessBread    1415
quote:
Original post by Coconut
Do I need to include a .def file declaring the exports, and if so how? What can I do?


Consult the manual. Consult MSDN. Also check out the __declspec(dllexport) modifier.

Share this post


Link to post
Share on other sites
Coconut    122
My version of MSVC++ didn''t come with a manual (besides MSDN), so I tried their website. MSDN has never been able to help much with LNK2001, but I still tried it before posting here because I don''t want to bother you great GDNet people with questions I could have answered myself. Thanks tho. About the __declspec(dllexport), do I need that for static library''s? I thought that was just for dll''s, but I''ll try it. Thanks for the help!

-Brent Robinson

Share this post


Link to post
Share on other sites
LessBread    1415
Sorry man, I know what you mean about MSDN - and I didn''t spot the word "static" - I saw "lib" and I figured you were trying to link in with a dll. __declspec(export) should obviate the need for a .def file (unless you want to undecorate the function names).

Most of the results of a google search on LNK2001 pertain to incorrect subsystem settings. However, this compaq link might be helpful (even though it concerns Fortran it provides some depth and it references C/C++ quite extensively) Q1012 - List of Linker Errors LNK2001 through LNK2014

Share this post


Link to post
Share on other sites
aftermath    100
in the source code for the library, dont forget to have this statement in one header:

// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the NAN_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// NAN_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef NAN_EXPORTS
#define NAN_API __declspec(dllexport)
#else
#define NAN_API __declspec(dllimport)
#endif

and include that header everywhare you are declaring/defining a function.
evey function shuld be declared with NAN_API

void NAN_API foo(int bar)
{
}

(NAN_API can be changed)

[ my engine ][ my game ][ my email ]
SPAM

Share this post


Link to post
Share on other sites
Coconut    122
About the declspec(), do they need to be in the class declaration or the class prototype, or both? cause I added them to the prototypes and they''re still getting errors. Also, if I add th em to the class, I don''t need to add them to the individual class members right?

About the template question: No, none of the interfaces are template classes. Just standard C++ inheritance classes wrapping the DX interfaces in some cases.

-Brent Robinson

Share this post


Link to post
Share on other sites
Coconut    122
Hey guys! I managed to fix it. Seems more likely that Visual Studio had another mystery problem, cause the only error I could detect is a difference in a parameter type in the prototype. The other 9 errors seemed to be undeserved completely, cause they went away completely after I stopped using __declspec again like I was before...hrmmm. Oh well, that''s quality work for you. Thanks for all your help guys!

-Brent Robinson

Share this post


Link to post
Share on other sites