lundi 2 mars 2015

resolving an undefined reference to `__imp__ in a library


I am currently in the process of porting a Visual Studio solution to mingw gcc. I am running into a linker error which is confusing me. In simplified term there are basically two projects called "xml" and "SharedFunctions" . The xml project (a static library) is referencing a header file which is present in the next project (SharedFunctions) Now when I attempt to build SharedFunctions project a dll project . I get linker errrors. I am not sure why I am getting that. I did look at this thread however I still cant figure out why I might be getting this.



Project Name : xml

FileName : MessageRepository.h

#pragma once

class MessageRepository
{
public:
...
...
...
...
virtual const std::wstring &LookUp(int tag, const std::wstring &key) const;
};


The implementation is:



FileName : MessageRepository.cpp

#include "MessageRepository.h"
#include "RamClearOption.h" //This is confusing (this file is in a project that has not been compiled yet.
const std::wstring& MessageRepository::LookUp(const std::wstring &key) const
{

bool internationalSetting = RamClearOption::GetInstance().SomeMethod();
...
...
return key;
}
...
...


Output is a static library called libxml.a



Project : SharedFunctions


Now the project that I am trying to build has RamClearOption.h and RamClearOption.cpp . The project is suppose to create a dynamic link library .dll. This is the output I get when I attempt to build the project



..\xml/libxml.a(MessageRepository.o):MessageRepository.cpp:(.text+0xfd4): undefined reference to `__imp__ZN14RamClearOption11GetInstanceEv'
..\xml/libxml.a(MessageRepository.o):MessageRepository.cpp:(.text+0xfed): undefined reference to `__imp__ZN14RamClearOption3GetERKSs'
..\xml/libxml.a(MessageRepository.o):MessageRepository.cpp:(.text+0x230c): undefined reference to `__imp__ZN14RamClearOption11GetInstanceEv'
..\xml/libxml.a(MessageRepository.o):MessageRepository.cpp:(.text+0x2325): undefined reference to `__imp__ZN14RamClearOption3GetERKSs'


I am including the _MAKE_SHARED_FUNCTIONS_DLL_ preprocessore when I attempt to build this project.


This is what the RamClearOption file looks like



#pragma once

#ifdef _MAKE_SHARED_FUNCTIONS_DLL_
# define DLL_DECLSPEC __declspec(dllexport)
#else
# define DLL_DECLSPEC __declspec(dllimport)
#endif

...
....

typedef struct
{
...
...
};

class DLL_DECLSPEC RamClearOption
{
...
static RamClearOption& GetInstance();
};


Any suggestions / tips on fixing this issue would be appreciated. Thanks




Aucun commentaire:

Enregistrer un commentaire