受保护的未解析的外部符号:“void __thiscall cocos2d :: Console :: loop(void)”

时间:2014-09-21 06:21:46

标签: c++ cocos2d-x cocos2d-x-3.0

我从官方网站下载SDK,并使用以下命令创建新项目:

cocos new foo -p com.foo.bar -l cpp -d .

因此,新项目foo已创建,我进入其目录。 我知道proj.win32有预装了visual studio的解决方案文件。但我希望从根项目目录的CMakeLists.txt重新生成它们。

所以我mkdir -p cmake-out/vs2012,输入目录,然后cmake -G "Visual Studio 11 2012" ../../。 一切都很好,解决方案文件是由cmake构建的,所以我在visual studio中重建了整个解决方案。 编译全部通过*,但最终链接过程因以下错误而失败:

4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '___WSAFDIsSet@8' referenced in function '"protected: void __thiscall cocos2d::Console::loop(void)" (?loop@Console@cocos2d@@IAEXXZ)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__accept@12' referenced in function '"protected: void __thiscall cocos2d::Console::addClient(void)" (?addClient@Console@cocos2d@@IAEXXZ)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__bind@12' referenced in function '"public: bool __thiscall cocos2d::Console::listenOnTCP(int)" (?listenOnTCP@Console@cocos2d@@QAE_NH@Z)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__closesocket@4' referenced in function '"protected: void __thiscall cocos2d::Console::commandExit(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?commandExit@Console@cocos2d@@IAEXHABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__ioctlsocket@12' referenced in function '"protected: void __thiscall cocos2d::Console::loop(void)" (?loop@Console@cocos2d@@IAEXXZ)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__listen@8' referenced in function '"public: bool __thiscall cocos2d::Console::listenOnTCP(int)" (?listenOnTCP@Console@cocos2d@@QAE_NH@Z)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__ntohs@4' referenced in function '"public: bool __thiscall cocos2d::Console::listenOnTCP(int)" (?listenOnTCP@Console@cocos2d@@QAE_NH@Z)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__recv@16' referenced in function '"protected: void __thiscall cocos2d::Console::commandUpload(int)" (?commandUpload@Console@cocos2d@@IAEXH@Z)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__select@20' referenced in function '"protected: void __thiscall cocos2d::Console::loop(void)" (?loop@Console@cocos2d@@IAEXXZ)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__send@16' referenced in function '"public: void __thiscall <lambda_18a69eabc233d9cfc5fb2fb65c07cfe6>::operator()(void)const " (??R<lambda_18a69eabc233d9cfc5fb2fb65c07cfe6>@@QBEXXZ)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__setsockopt@20' referenced in function '"public: bool __thiscall cocos2d::Console::listenOnTCP(int)" (?listenOnTCP@Console@cocos2d@@QAE_NH@Z)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__socket@12' referenced in function '"public: bool __thiscall cocos2d::Console::listenOnTCP(int)" (?listenOnTCP@Console@cocos2d@@QAE_NH@Z)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__WSAStartup@8' referenced in function '"public: bool __thiscall cocos2d::Console::listenOnTCP(int)" (?listenOnTCP@Console@cocos2d@@QAE_NH@Z)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__WSACleanup@0' referenced in function '"protected: void __thiscall cocos2d::Console::loop(void)" (?loop@Console@cocos2d@@IAEXXZ)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__getaddrinfo@16' referenced in function '"public: bool __thiscall cocos2d::Console::listenOnTCP(int)" (?listenOnTCP@Console@cocos2d@@QAE_NH@Z)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '__imp__freeaddrinfo@4' referenced in function '"public: bool __thiscall cocos2d::Console::listenOnTCP(int)" (?listenOnTCP@Console@cocos2d@@QAE_NH@Z)'
4>cocos2d.lib(CCConsole.obj) : error LNK2019: unresolved external symbol '_inet_ntop@16' referenced in function '"public: bool __thiscall cocos2d::Console::listenOnTCP(int)" (?listenOnTCP@Console@cocos2d@@QAE_NH@Z)'

原始解决方案没有错误,我知道。但是Visual Studio解决方案文件应该能够由cmake生成,CMakeLists.txt会出现什么问题?


*:实际上,包含目录设置是不正确的,所以我修补它们:

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/Classes
    ${COCOS2D_ROOT}
    ${COCOS2D_ROOT}/cocos
    ${COCOS2D_ROOT}/cocos/audio/include
    ${COCOS2D_ROOT}/cocos/2d
    ${COCOS2D_ROOT}/cocos/2d/renderer
    ${COCOS2D_ROOT}/cocos/2d/platform
    ${COCOS2D_ROOT}/cocos/2d/platform/desktop
    ${COCOS2D_ROOT}/cocos/2d/platform/win32
    ${COCOS2D_ROOT}/cocos/base

和他们一起:

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/Classes
    ${COCOS2D_ROOT}
    ${COCOS2D_ROOT}/cocos
    ${COCOS2D_ROOT}/cocos/audio/include
    ${COCOS2D_ROOT}/cocos/2d
    ${COCOS2D_ROOT}/cocos/renderer
    ${COCOS2D_ROOT}/cocos/platform
    ${COCOS2D_ROOT}/cocos/platform/desktop
    ${COCOS2D_ROOT}/cocos/platform/win32
    ${COCOS2D_ROOT}/cocos/base

是的,rendererplatform ...不在cocos/2d路径中。 这是我必须对消息来源做的唯一改变。

1 个答案:

答案 0 :(得分:0)

如果有人再次遇到这个问题。

这是因为cocos2d cmakelists.txt无法与windows platofrm上的ws2_32库链接。显然没有人使用cocos2d-x进行Windows开发或其他什么?无论如何。

要解决此问题,请在target_link_libraries中找到CMakeLists.txt部分,然后进行更改。

寻找:

target_link_libraries(${APP_NAME}
  spine
  cocostudio
  cocosbuilder
  extensions
  audio
  cocos2d
  )

并将其替换为:

if(WIN32 AND MSVC)
  target_link_libraries(${APP_NAME}
    spine
    cocostudio
    cocosbuilder
    extensions
    audio
    cocos2d
    box2d
    ws2_32
  )
else()
  target_link_libraries(${APP_NAME}
    spine
    cocostudio
    cocosbuilder
    extensions
    audio
    cocos2d
    box2d
  )
endif()

希望能解决这个特殊问题,并且整个过程会编译而不会遇到另一个问题。