Bienvenue, Invité. Merci de vous connecter ou de vous inscrire.
Avez-vous perdu votre e-mail d'activation ?

Auteur Sujet: undefined references errors.  (Lu 2058 fois)

0 Membres et 1 Invité sur ce sujet

nagimar

  • Newbie
  • *
  • Messages: 33
    • Voir le profil
undefined references errors.
« le: Janvier 12, 2021, 12:02:33 am »
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})
 
« Modifié: Janvier 12, 2021, 12:04:32 am par nagimar »

kareyrohr

  • Newbie
  • *
  • Messages: 1
    • Voir le profil
Re: undefined references errors.
« Réponse #1 le: Septembre 26, 2023, 05:24:49 am »
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&#39;
CMakeFiles\odfaeg-math.dir/objects.a(distribution.cpp.obj):distribution.cpp:(.text+0x350): undefined reference to `_imp___ZN2sf5ColorC1Ev&#39;
CMakeFiles\odfaeg-math.dir/objects.a(distribution.cpp.obj):distribution.cpp:(.text+0x917): undefined reference to `_imp___ZNK2sf4Time9asSecondsEv&#39;
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&#39;
collect2.exe: error: ld returned 1 exit status
src\odfaeg\Math\CMakeFiles\odfaeg-math.dir\build.make:246: recipe for target &#39;lib/odfaeg-math-1.dll&#39; failed
mingw32-make[2]: *** [lib/odfaeg-math-1.dll] Error 1
CMakeFiles\Makefile2:263: recipe for target &#39;src/odfaeg/Math/CMakeFiles/odfaeg-math.dir/all&#39; failed
mingw32-make[1]: *** [src/odfaeg/Math/CMakeFiles/odfaeg-math.dir/all] Error 2
Makefile:128: recipe for target &#39;all&#39; failed
mingw32-make: *** [all] Error 2
 

J'ai des undefined references de sf::seconds, sf::Color et sf::Time : slope game


/////////////////////////////////////////////////////////////////////////////////
//
// Thor C++ Library
// Copyright (c) 2011-2014 Jan Haller
//
// This software is provided &#39;as-is&#39;, 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})
 

Bonjour avez vous trouvé une solution à votre problème car nous rencontrons le même ? D'avance merci

 

anything