Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem Linking when using Threads  (Read 1478 times)

0 Members and 1 Guest are viewing this topic.

hatfarm

  • Newbie
  • *
  • Posts: 11
    • View Profile
Problem Linking when using Threads
« on: August 30, 2013, 02:28:22 am »
Hello all, I wasn't sure if I should put this here or in the System forum, but since this isn't a problem with the Thread class so much as linking, I decided it should go here.  The problem is that I'm trying to load resources from a separate thread, I've read a lot of the posts here and I think I have a working implementation, but I get a linking error when I try to build.  Here's the error:

ballswindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Thread::~Thread(void)" (__imp_??1Thread@sf@@QAE@XZ) referenced in function "public: __thiscall LoadState::~LoadState(void)" (??1LoadState@@QAE@XZ)
3>loadstate.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Thread::~Thread(void)" (__imp_??1Thread@sf@@QAE@XZ)
3>loadstate.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Thread::launch(void)" (__imp_?launch@Thread@sf@@QAEXXZ) referenced in function "public: virtual void __thiscall LoadState::init(void)" (?init@LoadState@@UAEXXZ)
3>loadstate.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Context::~Context(void)" (__imp_??1Context@sf@@QAE@XZ) referenced in function "private: void __thiscall LoadState::loadFunc(void)" (?loadFunc@LoadState@@AAEXXZ)
3>loadstate.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Context::Context(void)" (__imp_??0Context@sf@@QAE@XZ) referenced in function "private: void __thiscall LoadState::loadFunc(void)" (?loadFunc@LoadState@@AAEXXZ)
3>C:\Users\hatfarm\GitHome\balls-to-the-walls\bin\Debug\Balls to the Walls.exe : fatal error LNK1120: 4 unresolved externals
3>

I'm building this in VS 2010 and I'm using CMake to put together my solution.  It worked fine until I decided to add a separate thread, so it's got to be something with that.  I've been using sf::Clock for a while now, so it's not a problem with the System library.  Anyone have any ideas?  I'm building against SFML 2.1.  If you need code, let me know and I'll get it here.  Thanks!

EDIT:  Also, here's my cmake for SFML:

IF(WIN32)
        set(SFML_STATIC_LIBRARIES TRUE)
        find_package(SFML 2.1 COMPONENTS main graphics window system REQUIRED)
        #set(GLEW_LIBRARIES $ENV{SFML_ROOT}/extlibs/libs-msvc/x86/glew.lib)
        #set(FREETYPE_LIBRARY $ENV{SFML_ROOT}/extlibs/libs-msvc/x86/freetype.lib)
ENDIF()
« Last Edit: August 30, 2013, 02:39:34 am by hatfarm »

hatfarm

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Problem Linking when using Threads
« Reply #1 on: August 30, 2013, 02:32:57 am »
Here's the code, I thought it'd be best to just post it in case there's some way that's a problem.

LoadState::LoadState(BatE::MANAGER_PTR master_manager) : m_loadThread(&LoadState::loadFunc, this){
        m_sceneManager = master_manager;
}

void LoadState::init() {
        BatE::Camera *cam = m_sceneManager->createCamera("Ortho");
    cam->setProjection(glm::ortho(0.0f, float(m_windowWidth), float(m_windowHeight), 0.0f));
        m_sceneManager->addFontFromFile("LibSans44","LiberationSans-Bold.ttf", 44);
        m_sceneManager->addTextToFont("LibSans44", "Loading", "Loading...", 300, 300, true, glm::vec4(0.0, 1.0, 0.0, 1.0));
    m_sceneManager->addTextToFont("LibSans44", "Secs", "0", 300, 344, true, glm::vec4(1.0, 0.0, 0.0, 1.0));
        m_sceneManager->connectCameraToTextScene("LibSans44", "Ortho");
    m_ballsScene = m_sceneManager->add2dScene("Balls");
    m_loadingDone = false;
    m_loadThread.launch();
}

void LoadState::loadFunc(){
    sf::Context context;
    int ms = 100;
    m_ballsScene->addImageFromFile("BlackBall", "black.png");
    sf::sleep(sf::milliseconds(ms));
    m_ballsScene->addImageFromFile("BlackBall", "blue.png");
    sf::sleep(sf::milliseconds(ms));
    m_ballsScene->addImageFromFile("BlackBall", "green.png");
    sf::sleep(sf::milliseconds(ms));
    m_ballsScene->addImageFromFile("BlackBall", "light_blue.png");
    sf::sleep(sf::milliseconds(ms));
    m_ballsScene->addImageFromFile("BlackBall", "purple.png");
    sf::sleep(sf::milliseconds(ms));
    m_ballsScene->addImageFromFile("BlackBall", "red.png");
    sf::sleep(sf::milliseconds(ms));
    m_ballsScene->addImageFromFile("BlackBall", "white.png");
    sf::sleep(sf::milliseconds(ms));
    m_ballsScene->addImageFromFile("BlackBall", "yellow.png");
    sf::sleep(sf::milliseconds(ms));
    sf::Lock lock(m_doneMutex);
    m_loadingDone = true;
}
 

Thanks again for any help anyone can give.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Problem Linking when using Threads
« Reply #2 on: August 30, 2013, 07:57:21 am »
Quote
Also, here's my cmake for SFML
Can you show how you link these libraries to your target?
Laurent Gomila - SFML developer

hatfarm

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Problem Linking when using Threads
« Reply #3 on: August 30, 2013, 09:35:05 pm »
Gah, I feel like an idiot.  I accidentally commented out "ADD_DEFINITIONS( -DSFML_STATIC )".  I just happened to see it when I went to look for that information.  Now it works fine... oops.