pawajoro Temat założony przez niniejszego użytkownika |
[SFML] Problem z klasą » 2012-10-06 22:43:51 Witam, Napisałem własną "bibliotekę" do obsługi quizów. Napisałem również program, który uruchomi tą funkcję(game.cpp). Kod wygląda tak: #ifndef QUIZ_HPP #define QUIZ_HPP #include <SFML/Graphics.hpp> using namespace sf; using namespace std; struct command { string name; Color color; int points; };
struct que1 { string question; string answer; string opt1; string opt2; string opt3; };
struct que { string question; string answer; };
class Quiz { private: RenderWindow window; Image back; Sprite background; command * comm1; command * comm2; command * comm3; command * comm4; public: Quiz( command * comm1i, command * comm2i, command * comm3i, command * comm4i ); }; #endif
#include "quiz.hpp"
Quiz::Quiz( command * comm1i, command * comm2i, command * comm3i, command * comm4i ) : comm1( comm1i ) , comm2( comm2i ) , comm3( comm3i ) , comm4( comm4i ) , window( RenderWindow( sf::VideoMode( 800, 600, 32 ), "Quiz", Style::Fullscreen ) ) { Image img; img.LoadFromFile( "C:\\Quiz\\image\\abstract-waves-on-a-blue-background.jpg" ); back.Copy( img, 0, 0, IntRect( 0, 0, 800, 600 ) ); background.SetImage( back ); window.Draw( background ); window.Display(); }
#include "quiz.hpp"
int main() { command * comm1; command * comm2; command * comm3; command * comm4; Quiz game( comm1, comm2, comm3, comm4 ); return 0; }
I kompilator "wyrzuca" przy kompilacji liba wyrzuca takie błędy:
-------------- Build: Debug in Quiz ---------------
Compiling: ..\quiz.cpp C:\Quiz\quiz.hpp: In constructor 'Quiz::Quiz(command*, command*, command*, command*)': C:\Quiz\quiz.hpp:37: warning: 'Quiz::comm4' will be initialized after C:\Quiz\quiz.hpp:31: warning: 'sf::RenderWindow Quiz::window' C:\Quiz\quiz.cpp:3: warning: when initialized here In file included from d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Window.hpp:37, from d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Graphics.hpp:32, from C:\Quiz\quiz.hpp:3, from C:\Quiz\quiz.cpp:1: d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/System/NonCopyable.hpp: In copy constructor 'sf::Window::Window(const sf::Window&)': d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/System/NonCopyable.hpp:57: error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Window/Window.hpp:56: error: within this context In file included from d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Window.hpp:35, from d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Graphics.hpp:32, from C:\Quiz\quiz.hpp:3, from C:\Quiz\quiz.cpp:1: d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/System/NonCopyable.hpp: In copy constructor 'sf::Input::Input(const sf::Input&)': d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/System/NonCopyable.hpp:57: error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Window/Input.hpp:45: error: within this context In file included from d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Window.hpp:37, from d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Graphics.hpp:32, from C:\Quiz\quiz.hpp:3, from C:\Quiz\quiz.cpp:1: d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Window/Window.hpp: In copy constructor 'sf::Window::Window(const sf::Window&)': d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Window/Window.hpp:56: note: synthesized method 'sf::Input::Input(const sf::Input&)' first required here In file included from d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Graphics.hpp:38, from C:\Quiz\quiz.hpp:3, from C:\Quiz\quiz.cpp:1: d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Graphics/RenderWindow.hpp: In copy constructor 'sf::RenderWindow::RenderWindow(const sf::RenderWindow&)': d:\p\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/SFML/Graphics/RenderWindow.hpp:46: note: synthesized method 'sf::Window::Window(const sf::Window&)' first required here C:\Quiz\quiz.cpp: In constructor 'Quiz::Quiz(command*, command*, command*, command*)': C:\Quiz\quiz.cpp:8: note: synthesized method 'sf::RenderWindow::RenderWindow(const sf::RenderWindow&)' first required here Process terminated with status 1 (0 minutes, 1 seconds) 4 errors, 3 warnings
Co robić? |
|
cyklopek11 |
» 2012-10-06 22:48:31 sprawdziłbym to: error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private |
|
pawajoro Temat założony przez niniejszego użytkownika |
» 2012-10-07 11:23:32 OK, powyższy problem rozwiązany. Ale jest następny: quiz.hpp i quiz.cpp dodałem do projektu "quiz.cbp" Próba kompilacji kończy się wyrzuceniem komunikatu: "You must select a host application to "run" a library..." Ja zrozumiałem, że należy kompilować program, który wywołuje bibliotekę. Więc kompiluję game.cpp. ten krzyczy o błędach: Compiling: ..\game.cpp Linking console executable: ..\game.exe d:/p/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../../mingw32/bin/ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line. This should work unless it involves constant data structures referencing symbols from auto-imported DLLs. C:\Quiz\Quiz\libQuiz.a(quiz.o): In function `Quiz': C:/Quiz/quiz.cpp:8: undefined reference to `sf::RenderWindow::RenderWindow()' C:/Quiz/quiz.cpp:8: undefined reference to `sf::Image::Image()' C:/Quiz/quiz.cpp:8: undefined reference to `sf::Sprite::Sprite()' C:/Quiz/quiz.cpp:10: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)' C:/Quiz/quiz.cpp:10: undefined reference to `sf::Window::Create(sf::VideoMode, std::string const&, unsigned long, sf::WindowSettings const&)' C:/Quiz/quiz.cpp:11: undefined reference to `sf::Image::Image()' C:/Quiz/quiz.cpp:12: undefined reference to `sf::Image::LoadFromFile(std::string const&)' C:/Quiz/quiz.cpp:13: undefined reference to `sf::Image::Copy(sf::Image const&, unsigned int, unsigned int, sf::Rect<int> const&, bool)' C:/Quiz/quiz.cpp:14: undefined reference to `sf::Sprite::SetImage(sf::Image const&)' C:/Quiz/quiz.cpp:15: undefined reference to `sf::RenderTarget::Draw(sf::Drawable const&)' C:/Quiz/quiz.cpp:16: undefined reference to `sf::Window::Display()' C:/Quiz/quiz.cpp:8: undefined reference to `sf::RenderWindow::RenderWindow()' C:/Quiz/quiz.cpp:8: undefined reference to `sf::Image::Image()' C:/Quiz/quiz.cpp:8: undefined reference to `sf::Sprite::Sprite()' C:/Quiz/quiz.cpp:10: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)' C:/Quiz/quiz.cpp:10: undefined reference to `sf::Window::Create(sf::VideoMode, std::string const&, unsigned long, sf::WindowSettings const&)' C:/Quiz/quiz.cpp:11: undefined reference to `sf::Image::Image()' C:/Quiz/quiz.cpp:12: undefined reference to `sf::Image::LoadFromFile(std::string const&)' C:/Quiz/quiz.cpp:13: undefined reference to `sf::Image::Copy(sf::Image const&, unsigned int, unsigned int, sf::Rect<int> const&, bool)' C:/Quiz/quiz.cpp:14: undefined reference to `sf::Sprite::SetImage(sf::Image const&)' C:/Quiz/quiz.cpp:15: undefined reference to `sf::RenderTarget::Draw(sf::Drawable const&)' C:/Quiz/quiz.cpp:16: undefined reference to `sf::Window::Display()' collect2: ld returned 1 exit status Info: resolving vtable for sf::Sprite by linking to __imp___ZTVN2sf6SpriteE (auto-import) Process terminated with status 1 (0 minutes, 1 seconds) 22 errors, 1 warnings
A pliki *.a dołączyłem i do opcji kompilatora i do projektu. Do projektu dołączyłem: libsfml-graphics.a libsfml-system.a libsfml-window.a
DLL dałem do folderu z programem. Co robić? |
|
hincu |
» 2012-10-07 13:19:15 po pierwsze przejdz na sfml 2.0 bo jest cholernie bardziej wydajny od sfml 1.6 po drugie jak linkujesz liby to usun .a dopisz w linkerze tylko lsfml-system itp itd |
|
« 1 » |