0
votes

Using std::tr1::function in x64 configuration, I get below linking error in VS2008SP1. The same code works correctly for Win32 configuration. Is this a bug in 64 bit compiler, or am I missing something?

#include <iostream>
#include <functional>

typedef std::tr1::function<void()> FnCallBack;

void test()
{
    std::cout << "Test";
}

int main(int argc, char* argv[])
{
    FnCallBack f = &test;

    f();

    return 0;
}

error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl std::tr1::Xfunc(void)" (_imp_?_Xfunc@tr1@std@@YAXXZ) referenced in function "public: void __cdecl std::tr1::_Function_impl0::operator()(void)const " (??R?$_Function_impl0@X@tr1@std@@QEBAXXZ)

1
verbatim copy of your code build fine in a fresh new VS2008 SP1 project, after having added the x64 platform in the solution. You have a configuration problem. - manuell
What I did was 1) created a new project 2) Added x64 configuration, copied settings from win32 3) In c++->preprocessor, changed WIN32 to WIN64. Is anything else required? - FaisalM
I have NEVER changed WIN32 to WIN64 in Preprocessor, and never had a problem (vc2008, vs2010, vs2012)... LOL. Anyway, just done it. Doesn't change anything, build fine. - manuell
Are you sure that your configuration is x64? I had my configuration compiled after adding x64 configuration, but printing sizeof(void*) still gave the value 4. Then I added the macro WIN64 and got the correct pointer size (8). - FaisalM
Yes. Not my first 64 bits project. AFAIK, the WIN32/WIN64 macros doesn't change anything. Never used it, and my pointers are 8 bytes. - manuell

1 Answers

0
votes

I met the same issue with you! and I checked my vs2008 version and project settings, looks all are OK. at Win32 configuration , there is no error but X64 I got the link error samed with you.

At last, I install vs2008 sp1 again (note: not re-install, just run vs2008 sp1 setup again). the link error disappeared.

I don't know why, but maybe you could try it to fix this issue.