Partage
  • Partager sur Facebook
  • Partager sur Twitter

undefined references errors

Compiler une lib en shared qui utilise SFML

    12 janvier 2021 à 0:05:39

    Salut! je voudrais essayer de compiler une lib en shared qui utilise SFML mais j'ai des messages d'erreurs :
    CMakeFiles\odfaeg-math.dir/objects.a(distribution.cpp.obj):distribution.cpp:(.text+0x15d): undefined reference to `_imp___ZN2sf7secondsEf'
    CMakeFiles\odfaeg-math.dir/objects.a(distribution.cpp.obj):distribution.cpp:(.text+0x350): undefined reference to `_imp___ZN2sf5ColorC1Ev'
    CMakeFiles\odfaeg-math.dir/objects.a(distribution.cpp.obj):distribution.cpp:(.text+0x917): undefined reference to `_imp___ZNK2sf4Time9asSecondsEv'
    C:/PROGRA~2/CODEBL~1/MinGW/bin/../lib/gcc/mingw32/5.1.0/../../../../mingw32/bin/ld.exe: CMakeFiles\odfaeg-math.dir/objects.a(distribution.cpp.obj): bad reloc address 0x4 in section `.text.startup'
    collect2.exe: error: ld returned 1 exit status
    src\odfaeg\Math\CMakeFiles\odfaeg-math.dir\build.make:246: recipe for target 'lib/odfaeg-math-1.dll' failed
    mingw32-make[2]: *** [lib/odfaeg-math-1.dll] Error 1
    CMakeFiles\Makefile2:263: recipe for target 'src/odfaeg/Math/CMakeFiles/odfaeg-math.dir/all' failed
    mingw32-make[1]: *** [src/odfaeg/Math/CMakeFiles/odfaeg-math.dir/all] Error 2
    Makefile:128: recipe for target 'all' failed
    mingw32-make: *** [all] Error 2
    J'ai des undefined references de sf::seconds, sf::Color et sf::Time :
    /////////////////////////////////////////////////////////////////////////////////
    //
    // Thor C++ Library
    // Copyright (c) 2011-2014 Jan Haller
    //
    // This software is provided 'as-is', without any express or implied
    // warranty. In no event will the authors be held liable for any damages
    // arising from the use of this software.
    //
    // Permission is granted to anyone to use this software for any purpose,
    // including commercial applications, and to alter it and redistribute it
    // freely, subject to the following restrictions:
    //
    // 1. The origin of this software must not be misrepresented; you must not
    // claim that you wrote the original software. If you use this software
    // in a product, an acknowledgment in the product documentation would be
    // appreciated but is not required.
    //
    // 2. Altered source versions must be plainly marked as such, and must not be
    // misrepresented as being the original software.
    //
    // 3. This notice may not be removed or altered from any source distribution.
    //
    /////////////////////////////////////////////////////////////////////////////////
    #include "../../../include/odfaeg/Math/distributions.h"
    #include <cassert>
    namespace odfaeg
    {
        namespace math {
            namespace Distributions
            {
                namespace
                {
                    template <typename T>
                    Distribution<T> uniformT(T min, T max)
                    {
                        assert(min <= max);
                        return [=] () -> T
                        {
                            return Math::random(min, max);
                        };
                    }
                }
                // ---------------------------------------------------------------------------------------------------------------------------
                Distribution<int> uniformi(int min, int max)
                {
                    return uniformT(min, max);
                }
                Distribution<unsigned int> uniformui(unsigned int min, unsigned int max)
                {
                    return uniformT(min, max);
                }
                Distribution<float> uniform(float min, float max)
                {
                    return uniformT(min, max);
                }
                Distribution<sf::Time> uniform(sf::Time min, sf::Time max)
                {
                    assert(min <= max);
                    const float floatMin = min.asSeconds();
                    const float floatMax = max.asSeconds();
                    return [=] () -> sf::Time
                    {
                        return sf::seconds(Math::random(floatMin, floatMax));
                    };
                }
                Distribution<sf::Vector3f> rect(sf::Vector3f center, sf::Vector3f halfSize)
                {
                    assert(halfSize.x >= 0.f && halfSize.y >= 0.f);
                    return [=] () -> sf::Vector3f
                    {
                        return sf::Vector3f(
                        Math::random(center.x - halfSize.x, center.x + halfSize.x),
                        Math::random(center.y - halfSize.y, center.y + halfSize.y),
                        Math::random(center.z - halfSize.z, center.z + halfSize.z));
                    };
                }
                Distribution<sf::Vector3f> circle(sf::Vector3f center, float radius)
                {
                    assert(radius >= 0.f);
                    return [=] () -> sf::Vector3f
                    {
                        //sf::Vector3f radiusVector = sf::Vector3f(radius * std::sqrt(Math::random(0.f, 1.f)), Math::random(0.f, 360.f), 0);
                        sf::Vector3f radiusVector = sf::Vector3f(Math::random(0, radius) * Math::cosinus(Math::random(0, Math::toRadians(360))), Math::random(0, radius) * Math::sinus(Math::random(0, Math::toRadians(360))), 0);
                        return center + radiusVector;
                    };
                }
                Distribution<sf::Vector3f> deflect(sf::Vector3f direction, float maxRotation)
                {
                    return [=] () -> sf::Vector3f
                    {
                        Vec3f v(direction.x, direction.y, direction.z);
                        graphic::TransformMatrix tm;
                        tm.setRotation(Vec3f(0, 0, 1), Math::random(0.f - maxRotation, 0.f + maxRotation));
                        Vec3f t = tm.transform(v);
                        return sf::Vector3f(t.x, t.y, t.z);
                    };
                }
                Distribution<sf::Color> color(Vec3f color1, Vec3f color2) {
                    return [=] () -> sf::Color {
                        sf::Color color;
                        color.r = Math::clamp(Math::random(color1.x, color2.x), 0, 255);
                        color.g = Math::clamp(Math::random(color1.y, color2.y), 0, 255);
                        color.b = Math::clamp(Math::random(color1.z, color2.z), 0, 255);
                        color.a = Math::clamp(Math::random(color1.w, color2.w), 0, 255);
                        return color;
                    };
                }
            }
        } // namespace Distributions
    } // namespace thor
    Je lie SFML dans le fichier CMake :
    # include the ODFAEG specific macros
    include(${PROJECT_SOURCE_DIR}/cmake/Macros.cmake)
    set(INCROOT ${PROJECT_SOURCE_DIR}/include/odfaeg/Math)
    set(SRCROOT ${PROJECT_SOURCE_DIR}/src/odfaeg/Math)
    set(SRC
    ${INCROOT}/transformMatrix.h
    ${SRCROOT}/transformMatrix.cpp
    ${INCROOT}/export.hpp
    ${INCROOT}/computer.h
    ${SRCROOT}/computer.cpp
    ${INCROOT}/maths.h
    ${SRCROOT}/maths.cpp
    ${INCROOT}/matrix2.h
    ${SRCROOT}/matrix2.cpp
    ${INCROOT}/matrix3.h
    ${SRCROOT}/matrix3.cpp
    ${INCROOT}/matrix4.h
    ${SRCROOT}/matrix4.cpp
    ${INCROOT}/vec2f.h
    ${SRCROOT}/vec2.cpp
    ${INCROOT}/vec4.h
    ${SRCROOT}/vec4.cpp
    ${INCROOT}/distributions.h
    ${INCROOT}/distribution.h
    ${SRCROOT}/distribution.cpp
    ${INCROOT}/ray.h
    ${SRCROOT}/ray.cpp
    ${INCROOT}/bigInt.hpp
    ${SRCROOT}/bigInt.cpp)
    include_directories(${CMAKE_INCLUDE_PATH})
    link_directories (${CMAKE_LIBRARY_PATH})
    find_package (SFML 2 REQUIRED)
    sfgl_add_library(odfaeg-math
    SOURCES ${SRC}
    DEPENDS odfaeg-core)
    target_link_libraries (odfaeg-math ${SFML_LIBRARIES})

    -
    Edité par OmbreNoire 12 janvier 2021 à 0:07:40

    • Partager sur Facebook
    • Partager sur Twitter
      12 janvier 2021 à 1:31:21

      Difficile à dire avec les infos que tu donnes, il faudrait voir si les libs sfml ont été effectivement linkées ou pas, et si tu as les bonnes définitions à la compilation (si sfml est static, SFML_STATIC doit avoir été propagé, sinon le mangling ne sera pas bon).

      Utilise les targets d'import de sfml plutôt que des variables old school, c'est beaucoup plus robuste. Es tu certain d'utiliser le fichier config CMake installé avec sfml?

      Le fait que ta librairie à toi soit partagée ou statique n'a aucune importance, si elle est statique le link est juste retardé à plus tard.

      Rien à voir mais pense à utiliser PRIVATE, PUBLIC, INTERFACE dans target_link_libraries, surtout lorsque cela concerne des librairies (pour les exécutables ça n'a pas trop d'importance)

      -
      Edité par SpaceIn 12 janvier 2021 à 1:42:25

      • Partager sur Facebook
      • Partager sur Twitter

      undefined references errors

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown