Bienvenue, Invité. Merci de vous connecter ou de vous inscrire. Avez-vous oublié d'activer ?

Voir les contributions

Cette section vous permet de consulter les contributions (messages, sujets et fichiers joints) d'un utilisateur. Vous ne pourrez voir que les contributions des zones auxquelles vous avez accès.


Sujets - Sapin

Pages: [1]
1
Général / Undefined reference avec la SFML 2
« le: Mai 09, 2013, 02:37:48 pm »
Bonjour,

J'écris ce message car çà fait plusieurs jours que je me débats avec la compilation d'un projet avec la SFML 2. Mon but est de créer une librairie utilisant sfml-window comme back end. J'utilise GLEW, OpenGL 3.2 et PThread à côté mais j'ai déja réglé les problèmes de linkage avec ces 3 derniers. Je pense que le mieux pour vous décrire tous çà est mon script CMake :

#####################
# Define the project

cmake_minimum_required(VERSION 2.8)
project(Alt-Engine)

set(Alt-Engine_VERSION_MAJOR 0)
set(Alt-Engine_VERSION_MINOR 0)
set(Alt-Engine_VERSION_PATCH 0)

######################
# Include directories

include_directories("include" "extlibs/include")

if(WIN32)
    include_directories("extlibs/windows/include")
endif()

#####################
# External libraries

find_package(OpenGL REQUIRED)

set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/mingw/lib/x86")

set(EXTRA_LIBS ${OPENGL_gl_LIBRARY})
set(EXTRA_LIBS ${EXTRA_LIBS} pthreadGC2)
set(EXTRA_LIBS ${EXTRA_LIBS} sfml-window sfml-system)

if(WIN32)
    if(COMPILER_GCC)
    endif()
endif()

#########
# Define

add_definitions(-DALT_DLL_EXPORTS -DGLEW_STATIC)

############
# Set files

file(GLOB_RECURSE ALT_SOURCE_FILES "src/*.cpp")
file(GLOB_RECURSE ALT_HEADER_FILES "include/*.hpp")
file(GLOB_RECURSE ALT_THIRD_C_SOURCE_FILES "extlibs/src/*.c")

####################
# Build the library

add_library(Alt-Engine SHARED ${ALT_SOURCE_FILES} ${ALT_HEADER_FILES} ${ALT_THIRD_C_SOURCE_FILES})
target_link_libraries(Alt-Engine ${EXTRA_LIBS})
 

Voici les erreurs que j'ai : (remarquez que j'ai des erreurs que avec sf::Window::setTitle et sf::Window::create alors que j'utilise d'autres méthodes de sf::Window)

14:01:54: Exécution des étapes pour le projet Alt-Engine...
14:01:54: Débute : "C:\MinGW\bin\mingw32-make.exe"
Linking CXX shared library libAlt-Engine.dll
CMakeFiles\Alt-Engine.dir/objects.a(SFMLVideoDevice.cpp.obj):SFMLVideoDevice.cpp:(.text+0x28e): undefined reference to `_imp___ZN2sf6Window8setTitleERKNS_6StringE'
Creating library file: libAlt-Engine.dll.a
CMakeFiles\Alt-Engine.dir/objects.a(SFMLVideoDevice.cpp.obj):SFMLVideoDevice.cpp:(.text+0x45a): undefined reference to `_imp___ZN2sf6Window6createENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
collect2: ld returned 1 exit status
mingw32-make[2]: *** [libAlt-Engine.dll] Error 1
mingw32-make[1]: *** [CMakeFiles/Alt-Engine.dir/all] Error 2
mingw32-make: *** [all] Error 2
14:01:55: Le processus "C:\MinGW\bin\mingw32-make.exe" s'est terminé avec le code 2.
Error while building/deploying project Alt-Engine (kit: Desktop Qt 5.0.1 MinGW 32bit)
Lors de l'exécution de l'étape "Make"
 

Pour résoudre les problèmes de compatibilité des compileurs, j'ai compilé la SFML avec le même que j'utilise pour ma lib. (il s'agit de MinGW 4.8 DW2; ne faites pas attention au "(kit: Desktop Qt 5.0.1 MinGW 32bit)" car ce n'est pas ce compilo qui est utilisé). Vous aurez peut-être remarqué que j'utilise QtCreator pour son intégration native de CMake en temps qu'IDE mais si j'utilise CMake en dehors de QtCreator et que je build avec Code::Blocks j'ai les mêmes erreurs...

Pour résumer je ne comprend rien à ce problème ... Merci d'avance


2
Général / Problème avec sfml-window et sfml-network
« le: Décembre 03, 2012, 07:30:30 pm »
Bonjour,

Ce dimanche j'ai continuai à coder un projet sfml qui compilait bien jusque là quand j'ai eu dans la soirée un problème avec l’exécutable dans un cas spécial, la seul différence entre les exécutions successives est qu'il lit dans un fichier s'il existe. Dans ce cas, le problème ne démarre pas, simplement. Plus tard dans la soirée, il ne voulait tout simplement pas démarrer quelque soit la situation. J'ai réussi à isoler l'erreur, la deuxième, en simplifiant mon code :

Ceci marche :
int main ()
{
    cout << "hello world !" << endl << flush;

    sf::Clock clock;

    while (clock.GetElapsedTime() <= 5)
    {
        cout << clock.GetElapsedTime() << endl << flush;
    }

    return 0;
}

Ceci ne marche pas :

int main ()
{
    cout << "hello world !" << endl << flush;

    sf::Window window (sf::VideoMode(800,600,32),"Jeu"); // <=====

    sf::Clock clock;

    while (clock.GetElapsedTime() <= 5)
    {
        cout << clock.GetElapsedTime() << endl << flush;
    }

    return 0;
}

Je sais que ce problème ressemble beaucoup à un autre sur le forum mais j'ai essayer de recompiler la sfml et de passer en norme c++ 98 mais rien n'y fait ... Ça  marche pas ...

Merci d'avance

3
Suggestions de nouvelles fonctionnalités / Amélioration des paquets
« le: Décembre 02, 2012, 11:07:51 am »
Bonjour,

Je me suis rendu compte que le potentiel de la classe sf::Packet est beaucoup plus important que ceux qu'on en fait, et pour cause, on pourrait l'utiliser pour envoyer/recevoir des données binaires sérialisées, ce que boost par exemple ne gère pas (rien que çà !), à travers les flux de la STL. Ça permettrait de stocké des données sérialisées dans le DD par exemple. De plus, il suffirait de rendre compatible sa classe avec sf::Packet pour la rendre compatible avec toutes les STL : gain de temps et de simplicité.

J'ai une proposition d'implémentation ( toute simple et surtout optimisable ) :

std::istream& operator >> (std::istream& stream, sf::Packet& packet)
{
    sf::Uint32 start = stream.tellg ();
    stream.seekg (0, std::ios::end);
    sf::Uint32 lenght = stream.tellg ();
    lenght -= start;
    stream.seekg (start, std::ios::beg);

    char** buffer = new char* [lenght];

    stream.read (*buffer,lenght);
    packet.Append (*buffer,lenght);

    return stream;
}

std::ostream& operator << (std::ostream& stream, sf::Packet& packet)
{
    stream.write (packet.GetData (), packet.GetDataSize ());

    return stream;
}

Remarqué la belle double réécriture de tampon ...
Sinon pour l'utiliser :

file << packet; // écriture
file >> packet; // lecture

Aussi je propose une autre amélioration des paquets, il serait bien de pouvoir utiliser l'opérateur & pour écrire ou lire dans les paquets. Le problème est que le compilateur ne sait pas dans quelle sens faire l'opération, c'est pour çà que je propose 2 classes qui ont comme seul caractéristique d’exister :

namespace sf
{

class InPacket : public Packet
{
public:
    InPacket () : Packet () {}
};

class OutPacket : public Packet
{
public:
    OutPacket () : Packet () {}
};

}

Il faut aussi gérer les données de base : (désolé pour le long fichier, je ne trouve de balise spoil/secret )

// *** *** *** IN *** *** ***

inline InPacket& operator& (InPacket& packet, bool e){
    packet >> e;
    return packet;
}

inline InPacket& operator& (InPacket& packet, Int8 e){
    packet >> e;
    return packet;
}

inline InPacket& operator& (InPacket& packet, Uint8 e){
    packet >> e;
    return packet;
}

inline InPacket& operator& (InPacket& packet, Int16 e){
    packet >> e;
    return packet;
}

inline InPacket& operator& (InPacket& packet, Uint16 e){
    packet >> e;
    return packet;
}

inline InPacket& operator& (InPacket& packet, Int32 e){
    packet >> e;
    return packet;
}

inline InPacket& operator& (InPacket& packet, Uint32 e){
    packet >> e;
    return packet;
}

inline InPacket& operator& (InPacket& packet, float e){
    packet >> e;
    return packet;
}

inline InPacket& operator& (InPacket& packet, double e){
    packet >> e;
    return packet;
}

inline InPacket& operator& (InPacket& packet, char* e){
    packet >> e;
    return packet;
}

inline InPacket& operator& (InPacket& packet, std::string& e){
    packet >> e;
    return packet;
}

inline InPacket& operator& (InPacket& packet, wchar_t* e){
    packet >> e;
    return packet;
}

inline InPacket& operator& (InPacket& packet, std::wstring& e){
    packet >> e;
    return packet;
}

// *** *** *** OUT *** *** ***

inline OutPacket& operator& (OutPacket& packet, bool e){
    packet << e;
    return packet;
}

inline OutPacket& operator& (OutPacket& packet, Int8 e){
    packet << e;
    return packet;
}

inline OutPacket& operator& (OutPacket& packet, Uint8 e){
    packet << e;
    return packet;
}

inline OutPacket& operator& (OutPacket& packet, Int16 e){
    packet << e;
    return packet;
}

inline OutPacket& operator& (OutPacket& packet, Uint16 e){
    packet << e;
    return packet;
}



inline OutPacket& operator& (OutPacket& packet, Int32 e){
    packet << e;
    return packet;
}

inline OutPacket& operator& (OutPacket& packet, Uint32 e){
    packet << e;
    return packet;
}

inline OutPacket& operator& (OutPacket& packet, float e){
    packet << e;
    return packet;
}

inline OutPacket& operator& (OutPacket& packet, double e){
    packet << e;
    return packet;
}

inline OutPacket& operator& (OutPacket& packet, char* e){
    packet << e;
    return packet;
}

inline OutPacket& operator& (OutPacket& packet, std::string& e){
    packet << e;
    return packet;
}

inline OutPacket& operator& (OutPacket& packet, wchar_t* e){
    packet << e;
    return packet;
}

inline OutPacket& operator& (OutPacket& packet, std::wstring& e){
    packet << e;
    return packet;
}


Pour l'utiliser :


struct Data
{
    sf::Uint32 number;
    sf::Uint32 anOtherNumber;
    sf::Uint32 anImportantOne;
}



template <class Packet>
Packet& operator& (Packet& packet, Data& data)
{
    sf::Uint32 version = 2;


    packet & version;


    switch (version)
    {
    case 2:
        packet & anImportantOne;
    case 1:
        packet & data.anOtherNumber
    case 0:
        packet & data.number;
        break;
    default:
        break;
    }


    return packet;
}


 


Voilà tout  :D  !

4
Bonjour, je viens récemment (il y a deux heures) d'installer sfml sur mon nouvelle ordinateur (un 64bit enfin !) mais je tombe sur des flopées d'erreur depuis mon EDI préféré (QtCreator). Je me met à penser qu'il est bête car je vois pas où est l'erreur, il y en a aucune sur mon ordinateur 32 bit, donc je tente la compilation en ligne de commande :

g++ *.cpp -o Program -L"/usr/local/lib/" -lsfml-system -lsfml-window -lsfml-graphics

A défaut d'être élégante cette méthode est censée marcher ... Voici le retour  :

/usr/local/lib//libsfml-window.so: undefined reference to `sf::Unicode::UTF8Offsets'
/usr/local/lib//libsfml-window.so: undefined reference to `sf::Clock::Reset()'
/usr/local/lib//libsfml-window.so: undefined reference to `sf::Unicode::UTF8TrailingBytes'
/usr/local/lib//libsfml-window.so: undefined reference to `sf::Clock::GetElapsedTime() const'
/usr/local/lib//libsfml-window.so: undefined reference to `sf::Sleep(float)'
/usr/local/lib//libsfml-graphics.so: undefined reference to `sf::Unicode::Text::Text(unsigned int const*)'
/usr/local/lib//libsfml-window.so: undefined reference to `sf::Clock::Clock()'
/usr/local/lib//libsfml-graphics.so: undefined reference to `sf::Unicode::Text::operator std::basic_string<unsigned int, std::char_traits<unsigned int>, std::allocator<unsigned int> > const&() const'
/usr/local/lib//libsfml-graphics.so: undefined reference to `sf::Unicode::Text::Text()'
collect2: ld a retourné 1 code d'état d'exécution

Des undefined references au niveau des .so ?! Help !!!

Merci d'avance

Pages: [1]
anything