vendredi 27 mai 2016

Unresolved external symbol using SDL2 with Boost.Test

I'm trying to implement a test module using a single header variant of Boost.Test for my SDL2 game. Using Visual Studio 2012, to make it work I had to make 2 projects inside a solution, one containing all the game stuff and the other with a single test file. To run the tests, I compiled the game project as a static library and linked the whole thing against the test project. It worked fine, until I wrote a new class (an A* algorithm solver for pathfinding) and decided to test it in the module. It started giving me a linker error when I instanced the AStar class in the test file (it compiled and worked fine in the game project). All my headers are wrapped in headerguards, just BTW.

Here's the error:

error LNK2019: unresolved external symbol _SDL_DestroyTexture referenced in function "public: void __thiscall Texture::free(void)" (?free@Texture@@QAEXXZ)

Here's how the test file from the test project looks like:

Tests.cpp:

#include <boost/test/included/unit_test.hpp>
#include <boost/test/parameterized_test.hpp>
using namespace boost::unit_test;
#include "AStar.h"

void pathfinding_test(){//std::pair<fPoint,fPoint> start_end){
    FieldMap f(5,10);
    fPoint a,b;
    a.x = 5; a.y = 5;
    b.x = 100; b.y = 100;

    AStar astar(f,a,b);
}

test_suite* init_unit_test_suite(int argc, char* argv[])
{
    framework::master_test_suite().add(BOOST_TEST_CASE( &pathfinding_test ));
    return 0;
}

And here's the AStar header and it's nested includes:

#ifndef ASTAR_H
#define ASTAR_H
#include "FieldMap.h"
#include <algorithm>

class AStar{

    struct AStar_Node
    {
        fPoint pos;
        bool inOL, inCL;
        bool traversable;
        float F,G,H;
        AStar_Node* parent;
        std::vector<AStar_Node*> neighbors;

        AStar_Node();
        ~AStar_Node();
        AStar_Node(fPoint position);
    };

public:
    AStar(FieldMap &map, fPoint start, fPoint end);
    ~AStar();
    void findPath();
    static std::pair<int,int> pos2index(fPoint pos){
        std::pair<int,int> ind;
        ind.first = pos.x / tile_size;
        ind.second = pos.y / tile_size;

        if(ind.first * tile_size > pos.x && ind.first != 0)
            ++ind.first;
        if(ind.second * tile_size > pos.y && ind.second != 0)
            ++ind.second;

        if(ind.first < 0 || ind.second < 0)
            throw "Trying to get index for a point out of map bounds!";

        return ind; 
    }


private:    
    unsigned w,h;
    AStar_Node** map_graph;
    AStar_Node* start_node;
    AStar_Node* end_node;

    void fillNodes(FieldMap &map);  
    void countFGH(AStar_Node* n);
    float countG(AStar_Node* n);
    AStar_Node* findMinF(std::vector<AStar_Node*> &OL); 
};
#endif

Relation

I also tried testing a case that only used the FieldMap and it worked, so the problem has to be somewhere inside AStar.h.

Texture.h is the header where I include all the SDL headers and this is the function the error refers to:

void Texture::free()
{
    if( texture != NULL ){
        SDL_DestroyTexture( texture );
        texture = NULL;
        width = 0;
        height = 0;
    }
}

Any idea where it's coming from? If I comment out the AStar part of the test or the SDL_DestroyTexture() from Texture.h, it compiles.

Aucun commentaire:

Enregistrer un commentaire