5 Replies - 983 Views - Last Post: 11 August 2016 - 05:17 PM Rate Topic: -----

#1 hateborne  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 22-September 10

Issue with Code::Blocks, SDL_ttf, and Linking

Posted 10 August 2016 - 07:13 PM

Hello ladies/gents/wizards,

I have run into a slightly..."fun" linking error that I cannot resolve. I have spent so long fighting it, I am likely missing the obvious solution standing in plain sight. I will include the errors, my linking info, and what I'm getting.

First, errors from CLI attempt:
[email protected]:~/Code/CPP_Tutorials/ZombieGame$ g++ -std=c++11 -I../../CPP_Tutorials -o ZG *.h *.cpp -lGL -lSDL2 -lSDL_ttf ../GameEngine101/bin/Debug/libGameEngine101.a 
../GameEngine101/bin/Debug/libGameEngine101.a(SpriteFont.o): In function `GameEngine101::SpriteFont::SpriteFont(char const*, int, char, char)':
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp:21: undefined reference to `TTF_WasInit'
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp:22: undefined reference to `TTF_Init'
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp:24: undefined reference to `TTF_OpenFont'
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp:30: undefined reference to `TTF_FontHeight'
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp:39: undefined reference to `TTF_GlyphMetrics'
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp:99: undefined reference to `TTF_RenderGlyph_Blended'
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp:159: undefined reference to `TTF_CloseFont'



Next, SpriteFont.h and SpriteFont.cpp:
/*
    This is a modified version of the SpriteFont class from the
    Seed Of Andromeda source code.
    Use it for any of your projects, commercial or otherwise,
    free of charge, but do not remove this disclaimer.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS
    ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
    EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
    RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
    ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
    OF THIS SOFTWARE.

    November 28 2014
    Original Author: Cristian Zaloj
    Modified By: Benjamin Arnold
*/

#ifndef SPRITEFONT_H
#define SPRITEFONT_H

#include <SDL/SDL_ttf.h>
#include <glm/glm.hpp>
#include <map>
#include <vector>

#include "Vertex.h"

namespace GameEngine101 {

    class GLTexture;
    class SpriteBatch;

    struct CharGlyph {
    public:
        char character;
        glm::vec4 uvRect;
        glm::vec2 size;
    };

#define FIRST_PRINTABLE_CHAR ((char)32)
#define LAST_PRINTABLE_CHAR ((char)126)

    /// For text justification
    enum class Justification {
        LEFT, MIDDLE, RIGHT
    };

    class SpriteFont {
    public:
        SpriteFont(const char* font, int size, char cs, char ce);
        SpriteFont(const char* font, int size) :
            SpriteFont(font, size, FIRST_PRINTABLE_CHAR, LAST_PRINTABLE_CHAR) {
        }
        /// Destroys the font resources
        void dispose();

        int getFontHeight() const {
            return _fontHeight;
        }

        /// Measures the dimensions of the text
        glm::vec2 measure(const char* s);

        /// Draws using a spritebatch
        void draw(SpriteBatch& batch, const char* s, glm::vec2 position, glm::vec2 scaling,
                  float depth, ColorRGBA8 tint, Justification just = Justification::LEFT);
    private:
        static std::vector<int>* createRows(glm::ivec4* rects, int rectsLength, int r, int padding, int& w);

        int _regStart, _regLength;
        CharGlyph* _glyphs;
        int _fontHeight;

        unsigned int _texID;
    };

}

#endif // SPRITEFONT_H


#include "SpriteFont.h"
#include "SpriteBatch.h"
#include <SDL2/SDL.h>

int closestPow2(int i) {
    i--;
    int pi = 1;
    while (i > 0) {
        i >>= 1;
        pi <<= 1;
    }
    return pi;
}

#define MAX_TEXTURE_RES 4096

namespace GameEngine101 {

    SpriteFont::SpriteFont(const char* font, int size, char cs, char ce) {
        // Initialize SDL_ttf
        if (!TTF_WasInit()) {
            TTF_Init();
        }
        TTF_Font* f = TTF_OpenFont(font, size);
        if (f == nullptr) {
            fprintf(stderr, "Failed to open TTF font %s\n", font);
            fflush(stderr);
            throw 281;
        }
        _fontHeight = TTF_FontHeight(f);
        _regStart = cs;
        _regLength = ce - cs + 1;
        int padding = size / 8;

        // First neasure all the regions
        glm::ivec4* glyphRects = new glm::ivec4[_regLength];
        int i = 0, advance;
        for (char c = cs; c <= ce; c++) {
            TTF_GlyphMetrics(f, c, &glyphRects[i].x, &glyphRects[i].z, &glyphRects[i].y, &glyphRects[i].w, &advance);
            glyphRects[i].z -= glyphRects[i].x;
            glyphRects[i].x = 0;
            glyphRects[i].w -= glyphRects[i].y;
            glyphRects[i].y = 0;
            i++;
        }

        // Find best partitioning of glyphs
        int rows = 1, w, h, bestWidth = 0, bestHeight = 0, area = MAX_TEXTURE_RES * MAX_TEXTURE_RES, bestRows = 0;
        std::vector<int>* bestPartition = nullptr;
        while (rows <= _regLength) {
            h = rows * (padding + _fontHeight) + padding;
            auto gr = createRows(glyphRects, _regLength, rows, padding, w);

            // Desire a power of 2 texture
            w = closestPow2(w);
            h = closestPow2(h);

            // A texture must be feasible
            if (w > MAX_TEXTURE_RES || h > MAX_TEXTURE_RES) {
                rows++;
                delete[] gr;
                continue;
            }

            // Check for minimal area
            if (area >= w * h) {
                if (bestPartition) delete[] bestPartition;
                bestPartition = gr;
                bestWidth = w;
                bestHeight = h;
                bestRows = rows;
                area = bestWidth * bestHeight;
                rows++;
            } else {
                delete[] gr;
                break;
            }
        }

        // Can a bitmap font be made?
        if (!bestPartition) {
            fprintf(stderr, "Failed to Map TTF font %s to texture. Try lowering resolution.\n", font);
            fflush(stderr);
            throw 282;
        }
        // Create the texture
        glGenTextures(1, &_texID);
        glBindTexture(GL_TEXTURE_2D, _texID);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bestWidth, bestHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);

        // Now draw all the glyphs
        SDL_Color fg = { 255, 255, 255, 255 };
        int ly = padding;
        for (int ri = 0; ri < bestRows; ri++) {
            int lx = padding;
            for (int ci = 0; ci < bestPartition[ri].size(); ci++) {
                int gi = bestPartition[ri][ci];

                SDL_Surface* glyphSurface = TTF_RenderGlyph_Blended(f, (char)(cs + gi), fg);

                // Pre-multiplication occurs here
                unsigned char* sp = (unsigned char*)glyphSurface->pixels;
                int cp = glyphSurface->w * glyphSurface->h * 4;
                for (int i = 0; i < cp; i += 4) {
                    float a = sp[i + 3] / 255.0f;
                    sp[i] *= a;
                    sp[i + 1] = sp[i];
                    sp[i + 2] = sp[i];
                }

                // Save glyph image and update coordinates
                glTexSubImage2D(GL_TEXTURE_2D, 0, lx, bestHeight - ly - 1 - glyphSurface->h, glyphSurface->w, glyphSurface->h, GL_BGRA, GL_UNSIGNED_BYTE, glyphSurface->pixels);
                glyphRects[gi].x = lx;
                glyphRects[gi].y = ly;
                glyphRects[gi].z = glyphSurface->w;
                glyphRects[gi].w = glyphSurface->h;

                SDL_FreeSurface(glyphSurface);
                glyphSurface = nullptr;

                lx += glyphRects[gi].z + padding;
            }
            ly += _fontHeight + padding;
        }

        // Draw the unsupported glyph
        int rs = padding - 1;
        int* pureWhiteSquare = new int[rs * rs];
        memset(pureWhiteSquare, 0xffffffff, rs * rs * sizeof(int));
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rs, rs, GL_RGBA, GL_UNSIGNED_BYTE, pureWhiteSquare);
        delete[] pureWhiteSquare;
        pureWhiteSquare = nullptr;

        // Set some texture parameters
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

        // Create spriteBatch glyphs
        _glyphs = new CharGlyph[_regLength + 1];
        for (i = 0; i < _regLength; i++) {
            _glyphs[i].character = (char)(cs + i);
            _glyphs[i].size = glm::vec2(glyphRects[i].z, glyphRects[i].w);
            _glyphs[i].uvRect = glm::vec4(
                (float)glyphRects[i].x / (float)bestWidth,
                (float)glyphRects[i].y / (float)bestHeight,
                (float)glyphRects[i].z / (float)bestWidth,
                (float)glyphRects[i].w / (float)bestHeight
                );
        }
        _glyphs[_regLength].character = ' ';
        _glyphs[_regLength].size = _glyphs[0].size;
        _glyphs[_regLength].uvRect = glm::vec4(0, 0, (float)rs / (float)bestWidth, (float)rs / (float)bestHeight);

        glBindTexture(GL_TEXTURE_2D, 0);
        delete[] glyphRects;
        delete[] bestPartition;
        TTF_CloseFont(f);
    }
    void SpriteFont::dispose() {
        if (_texID != 0) {
            glDeleteTextures(1, &_texID);
            _texID = 0;
        }
        if (_glyphs) {
            delete[] _glyphs;
            _glyphs = nullptr;
        }
    }

    std::vector<int>* SpriteFont::createRows(glm::ivec4* rects, int rectsLength, int r, int padding, int& w) {
        // Blank initialize
        std::vector<int>* l = new std::vector<int>[r]();
        int* cw = new int[r]();
        for (int i = 0; i < r; i++) {
            cw[i] = padding;
        }

        // Loop through all glyphs
        for (int i = 0; i < rectsLength; i++) {
            // Find row for placement
            int ri = 0;
            for (int rii = 1; rii < r; rii++)
            if (cw[rii] < cw[ri]) ri = rii;

            // Add width to that row
            cw[ri] += rects[i].z + padding;

            // Add glyph to the row list
            l[ri].push_back(i);
        }

        // Find the max width
        w = 0;
        for (int i = 0; i < r; i++) {
            if (cw[i] > w) w = cw[i];
        }

        // clean up memory leak
        delete[] cw;

        // return vector
        return l;
    }

    glm::vec2 SpriteFont::measure(const char* s) {
        glm::vec2 size(0, _fontHeight);
        float cw = 0;
        for (int si = 0; s[si] != 0; si++) {
            char c = s[si];
            if (s[si] == '\n') {
                size.y += _fontHeight;
                if (size.x < cw)
                    size.x = cw;
                cw = 0;
            } else {
                // Check for correct glyph
                int gi = c - _regStart;
                if (gi < 0 || gi >= _regLength)
                    gi = _regLength;
                cw += _glyphs[gi].size.x;
            }
        }
        if (size.x < cw)
            size.x = cw;
        return size;
    }

    void SpriteFont::draw(SpriteBatch& batch, const char* s, glm::vec2 position, glm::vec2 scaling,
                          float depth, ColorRGBA8 tint, Justification just /* = Justification::LEFT */) {
        glm::vec2 tp = position;
        // Apply justification
        if (just == Justification::MIDDLE) {
            tp.x -= measure(s).x * scaling.x / 2;
        } else if (just == Justification::RIGHT) {
            tp.x -= measure(s).x * scaling.x;
        }
        for (int si = 0; s[si] != 0; si++) {
            char c = s[si];
            if (s[si] == '\n') {
                tp.y += _fontHeight * scaling.y;
                tp.x = position.x;
            } else {
                // Check for correct glyph
                int gi = c - _regStart;
                if (gi < 0 || gi >= _regLength)
                    gi = _regLength;
                glm::vec4 destRect(tp, _glyphs[gi].size * scaling);
                batch.draw(destRect, _glyphs[gi].uvRect, _texID, depth, tint);
                tp.x += _glyphs[gi].size.x * scaling.x;
            }
        }
    }

}



Finally, linking bits:
http://i.imgur.com/Ydx7rTh.png
http://i.imgur.com/4GX5Mhl.png

I have installed libsdl-ttf2.0-dev (which installed the libs and freetype). I am working through some of the tutorials/refreshers found here by Ben Arnold of Seed of Andromeda (and recently, ArenaNet).

Any pointers would be greatly appreciated! I can supply missing info as soon as possible as I am effectively stuck until I resolve this. I have attached Code::Blocks' build log in it's entirety for better information.


-Hate


EDIT: Running Ubuntu 16.04 x64, Code::Blocks 16.01, video drivers from nVidia (361.42), and whatever the latest version of SDL comes from the ubuntu repos.

This post has been edited by hateborne: 10 August 2016 - 07:15 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Issue with Code::Blocks, SDL_ttf, and Linking

#2 andrewsw  Icon User is online

  • say what now
  • member icon

Reputation: 6409
  • View blog
  • Posts: 25,903
  • Joined: 12-December 12

Re: Issue with Code::Blocks, SDL_ttf, and Linking

Posted 10 August 2016 - 11:39 PM

Question moved out of Discussion Lounge, you are seeking help with your code, not starting a discussion topic.
Was This Post Helpful? 1
  • +
  • -

#3 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 1392
  • View blog
  • Posts: 4,405
  • Joined: 20-March 10

Re: Issue with Code::Blocks, SDL_ttf, and Linking

Posted 11 August 2016 - 12:15 AM

If you are linking from code::blocks
Then you would goto build options
In the linker section for the project
Set the libraries you would like to link to

And press build.

You're problem seems to be it's not finding SDL_ttf
So I would check that too

I would also include SDL.h before Spritefont.h

If you're linking from the command line
Then the advice would be different you would specify the libs with -l

Regards

snoopy.
Was This Post Helpful? 1
  • +
  • -

#4 hateborne  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 22-September 10

Re: Issue with Code::Blocks, SDL_ttf, and Linking

Posted 11 August 2016 - 04:24 AM

andrewsw, sorry for posting in the wrong section! :o/>



snoopy11,

Re-reading my original post...it's kind of a mess and I apologize for that. I tried CLI when Code::Blocks failed miserably. I am at a loss of how to get it to link or act as if it is included. The SDL_ttf.h is in /usr/include/SDL, which would allow me to use #include <SDL/SDL_ttf.h> (as well as the SDL2 includes). I moved SDL.h before SpriteFont.h in SpriteFont.cpp's includes (as you suggested), but it had no effect. I've included a full build log below again and the pictures of the linker options. I have added back the link to the library directly, but it is still unable to build.

The only thing missing from the Linker Settings is that ZombieGame's Debug build target looks for GameEngine101's Debug built library, while ZombieGame Release build target looks at GameEngine101's Release built library.


Linker Settings:
http://i.imgur.com/Tt20M4Z.png
http://i.imgur.com/SCUPxGa.png


Errors from CB Build Log:
||=== Build: Debug in GameEngine101 (compiler: GNU GCC Compiler) ===|
||=== Build: Debug in ZombieGame (compiler: GNU GCC Compiler) ===|
/home/hate/Code/CPP_Tutorials/ZombieGame/Agent.cpp||In member function ‘bool Agent::collideWithLevel(const std::vector<std::__cxx11::basic_string<char> >&)’:|
/home/hate/Code/CPP_Tutorials/ZombieGame/Agent.cpp|49|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/Bullet.cpp||In member function ‘bool Bullet::collideWithWorld(const std::vector<std::__cxx11::basic_string<char> >&)’:|
/home/hate/Code/CPP_Tutorials/ZombieGame/Bullet.cpp|64|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/Bullet.cpp|65|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/Level.cpp||In constructor ‘Level::Level(const string&)’:|
/home/hate/Code/CPP_Tutorials/ZombieGame/Level.cpp|42|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/Level.cpp|43|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.h||In constructor ‘MainGame::MainGame()’:|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.h|104|warning: ‘MainGame::_gameState’ will be initialized after [-Wreorder]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.h|92|warning:   ‘float MainGame::_fps’ [-Wreorder]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|20|warning:   when initialized here [-Wreorder]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp||In destructor ‘MainGame::~MainGame()’:|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|33|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|37|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|40|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp||In member function ‘void MainGame::initLevel()’:|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|105|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp||In member function ‘void MainGame::updateAgents(float)’:|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|182|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|190|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|198|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|200|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|204|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|223|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|225|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp||In member function ‘void MainGame::updateBullets(float)’:|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|235|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|248|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|251|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|278|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp||In member function ‘void MainGame::drawGame()’:|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|378|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|383|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/MainGame.cpp|388|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/home/hate/Code/CPP_Tutorials/ZombieGame/Zombie.cpp||In member function ‘Human* Zombie::getNearestHuman(std::vector<Human*>&)’:|
/home/hate/Code/CPP_Tutorials/ZombieGame/Zombie.cpp|44|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
../GameEngine101/bin/Debug/libGameEngine101.a(SpriteFont.o)||In function `GameEngine101::SpriteFont::SpriteFont(char const*, int, char, char)':|
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp|21|undefined reference to `TTF_WasInit'|
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp|22|undefined reference to `TTF_Init'|
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp|24|undefined reference to `TTF_OpenFont'|
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp|30|undefined reference to `TTF_FontHeight'|
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp|39|undefined reference to `TTF_GlyphMetrics'|
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp|99|undefined reference to `TTF_RenderGlyph_Blended'|
/home/hate/Code/CPP_Tutorials/GameEngine101/SpriteFont.cpp|159|undefined reference to `TTF_CloseFont'|
||error: ld returned 1 exit status|
||=== Build failed: 8 error(s), 27 warning(s) (0 minute(s), 10 second(s)) ===|





-Hate
Was This Post Helpful? 0
  • +
  • -

#5 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 1392
  • View blog
  • Posts: 4,405
  • Joined: 20-March 10

Re: Issue with Code::Blocks, SDL_ttf, and Linking

Posted 11 August 2016 - 04:55 AM

Is your ttf library not called
libSDL2_ttf.a ?

If not that might be the problem

If it is you need to link with

-lSDL2_ttf.a

Regards

Snoopy
Was This Post Helpful? 1
  • +
  • -

#6 hateborne  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 22-September 10

Re: Issue with Code::Blocks, SDL_ttf, and Linking

Posted 11 August 2016 - 05:17 PM

snoopy11,

The issue was I didn't have all of the packages installed and SDL_TTF is incredibly picky about the load order (CodeBlocks seems to load things in an 'off' order from ~5h scouring the internet). The fix is effectively what I found in a posting on StackOverflow by Epic Yeti.

Installing Correct Packages: apt-get install libsdl2-ttf-dev libsdl2-ttf-2.0-0
After installing these, I could correctly use #include <SDL2/SDL_ttf.h>.

Next, load my static library before any of the SDL libraries. Dumped all of the pictures into an Imgur library for easy reference.

Thank you again for all of your assistance!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1